-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuilder.d
executable file
·115 lines (97 loc) · 4.16 KB
/
builder.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env rdmd
import std.conv, std.file, std.path, std.process, std.range, std.stdio;
auto digger = "dub run digger -- ";
auto dlangOrgFolder = "dlang.org";
int execute(string command, string[string] env = null)
{
stderr.writefln("\033[1;33m---> Executing: %s\033[00m", command);
auto pipes = pipeShell(command, Redirect.stdin, env);
return pipes.pid.wait;
}
void executeOrFail(string command, string[string] env = null)
{
import core.stdc.stdlib;
execute(command, env) == 0 || exit(1);
}
void console(S...)(S args)
{
stdout.write("\033[1;32m");
stdout.write(args);
stdout.writeln("\033[00m");
}
string tagVersion(int minor)
{
return text("v2.", minor < 100 ? "0" : "", minor, minor >= 65 ? ".0" : "");
}
void main(string[] args)
{
if (args.length < 2)
{
console("\033[1;33mbuilder.d: missing git tag argument");
console("\033[1;33musage: ./builder.d tags...");
return;
}
auto outFolder = "archives";
outFolder.mkdirRecurse;
console("Building digger...");
executeOrFail("dub fetch digger");
auto cwd = getcwd();
auto tags = args[1 .. $];
foreach (tag; tags)
{
auto diggerWorkRepo = cwd.buildPath("work", "repo");
auto dlangOrgFolder = diggerWorkRepo.buildPath("dlang.org");
auto installerFolder = diggerWorkRepo.buildPath("installer");
auto web = dlangOrgFolder.buildPath("web");
// cleanup
if (diggerWorkRepo.exists)
{
auto removeWorkTree = (string p) => p.exists && p.remove;
auto diggerModulePath = diggerWorkRepo.buildPath(".git", "modules");
removeWorkTree(diggerModulePath.buildPath("dmd", "ae-sys-d-worktree.json"));
removeWorkTree(diggerModulePath.buildPath("druntime", "ae-sys-d-worktree.json"));
removeWorkTree(diggerModulePath.buildPath("phobos", "ae-sys-d-worktree.json"));
removeWorkTree(diggerModulePath.buildPath("dlang.org", "ae-sys-d-worktree.json"));
removeWorkTree(diggerModulePath.buildPath("installer", "ae-sys-d-worktree.json"));
removeWorkTree(diggerModulePath.buildPath("tools", "ae-sys-d-worktree.json"));
}
// checkout
console("Checking out: ", tag);
executeOrFail(digger ~ "checkout --with=website " ~ tag);
executeOrFail("git -C " ~ diggerWorkRepo ~ " submodule update --init installer");
executeOrFail("git -C " ~ installerFolder ~ " checkout " ~ tag);
// build
console("Building: ", tag);
auto env = [
"NODATETIME": "nodatetime.ddoc"
];
auto folders = " DMD_DIR=" ~ diggerWorkRepo.buildPath("dmd");
if (tag.split(".")[1].to!int >= 101)
folders ~= " DRUNTIME_DIR=" ~ diggerWorkRepo.buildPath("dmd/druntime");
else
folders ~= " DRUNTIME_DIR=" ~ diggerWorkRepo.buildPath("druntime");
folders ~= " PHOBOS_DIR=" ~ diggerWorkRepo.buildPath("phobos");
folders ~= " INSTALLER_DIR=" ~ diggerWorkRepo.buildPath("installer");
folders ~= " TOOLS_DIR=" ~ diggerWorkRepo.buildPath("tools");
folders ~= " LATEST=" ~ tag[1..$];
auto nextTag = tagVersion(tag.split(".")[1].to!int + 1);
if (execute("git -C " ~ diggerWorkRepo ~ " show-ref --tags " ~ nextTag) == 0)
folders ~= " CHANGELOG_VERSION_MASTER=" ~ tag ~ ".." ~ nextTag;
auto patch = (string c) => c.exists && executeOrFail("patch -p1 -i " ~ c ~ " -d " ~ diggerWorkRepo);
patch(cwd.buildPath("patches", tag ~ ".diff"));
auto make = (string c) => executeOrFail("make -f posix.mak " ~ c ~ " -C " ~ dlangOrgFolder ~ folders, env);
make("all");
make("kindle");
auto removeFromWeb = (string d) => d.exists && d.rmdirRecurse;
removeFromWeb(web.buildPath("phobos-prerelease"));
removeFromWeb(web.buildPath("library-prerelease"));
// save
console("Storing: ", tag);
auto target = outFolder.buildPath(tag);
if (target.exists)
target.rmdirRecurse;
web.rename(target);
dlangOrgFolder.buildPath(".generated", "docs-latest.json").rename(target.buildPath("docs.json"));
}
console(tags);
}