-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
build_all.d
402 lines (339 loc) · 13.1 KB
/
build_all.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/++
Prerequisites:
-------------------------
A working dmd installation to compile this script (also requires libcurl).
Install Vagrant (https://learnchef.opscode.com/screencasts/install-vagrant/)
Install VirtualBox (https://learnchef.opscode.com/screencasts/install-virtual-box/)
+/
import std.conv, std.exception, std.file, std.path, std.process, std.stdio, std.string, std.range;
import common;
version (Posix) {} else { static assert(0, "This must be run on a Posix machine."); }
// Open Source OS boxes are from http://www.vagrantbox.es/
// Note: The pull request to add the FreeBSD-8.4 boxes to vagrantbox.es is still pending, https://github.com/garethr/vagrantboxes-heroku/pull/246.
/// Name: create_dmd_release-freebsd-64
/// VagrantBox.es: FreeBSD 8.4 i386 (minimal, No Guest Additions, UFS)
enum freebsd_32 = Box(OS.freebsd, Model._32, "http://dlang.dawg.eu/vagrant/FreeBSD-8.4-i386.box",
"sudo pkg_add -r curl git gmake;");
// Note: pull request for vagrantbox.es pending
/// Name: create_dmd_release-freebsd-64
/// VagrantBox.es: FreeBSD 8.4 amd64 (minimal, No Guest Additions, UFS)
enum freebsd_64 = Box(OS.freebsd, Model._64, "http://dlang.dawg.eu/vagrant/FreeBSD-8.4-amd64.box",
"sudo pkg_add -r curl git gmake;");
/// Name: create_dmd_release-linux
/// VagrantBox.es: Puppetlabs Debian 6.0.7 x86_64, VBox 4.2.10, No Puppet or Chef
enum linux_both = Box(OS.linux, Model._both, "http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box",
"sudo apt-get -y update; sudo apt-get -y install git g++-multilib;");
/// OSes that require licenses must be setup manually
/// Name: create_dmd_release-osx
/// Setup: Preparing OSX-10.8 box, https://gist.github.com/MartinNowak/8156507
enum osx_both = Box(OS.osx, Model._both, null,
null);
/// Name: create_dmd_release-windows
/// Setup: Preparing Win7x64 box, https://gist.github.com/MartinNowak/8270666
enum windows_both = Box(OS.windows, Model._both, null,
null);
enum boxes = [windows_both, osx_both, freebsd_32, freebsd_64, linux_both];
enum OS { freebsd, linux, osx, windows, }
enum Model { _both = 0, _32 = 32, _64 = 64 }
struct Box
{
void up()
{
_tmpdir = mkdtemp();
std.file.write(buildPath(_tmpdir, "Vagrantfile"), vagrantFile);
// bring up the virtual box (downloads missing images)
run("cd "~_tmpdir~" && vagrant up");
_isUp = true;
// save the ssh config file
run("cd "~_tmpdir~" && vagrant ssh-config > ssh.cfg");
provision();
}
void destroy()
{
try
{
if (_isUp) run("cd "~_tmpdir~" && vagrant destroy -f");
if (_tmpdir.length) rmdirRecurse(_tmpdir);
}
finally
{
_isUp = false;
_tmpdir = null;
}
}
void halt()
{
try
if (_isUp) run("cd "~_tmpdir~" && vagrant halt");
finally
_isUp = false;
}
ProcessPipes shell(Redirect redirect = Redirect.stdin)
in { assert(redirect & Redirect.stdin); }
body
{
ProcessPipes sh;
if (_os == OS.windows)
{
sh = pipeProcess(["ssh", "-F", sshcfg, "default", "powershell", "-Command", "-"], redirect);
}
else
{
sh = pipeProcess(["ssh", "-F", sshcfg, "default", "bash"], redirect);
// enable verbose echo and stop on error
sh.exec("set -e -v");
}
return sh;
}
void scp(string src, string tgt)
{
run("scp -rq -F "~sshcfg~" "~src~" "~tgt);
}
private:
@property string vagrantFile()
{
auto res =
`
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "create_dmd_release-`~platform~`"
config.vm.box_url = "`~_url~`"
# disable shared folders, because the guest additions are missing
config.vm.synced_folder ".", "/vagrant", :disabled => true
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "4096"]
vb.customize ["modifyvm", :id, "--cpus", "4"]
vb.customize ["modifyvm", :id, "--accelerate3d", "off"]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--usb", "off"]
end
`;
if (_os == OS.windows)
res ~=
`
config.vm.guest = :windows
# Port forward WinRM and RDP
config.vm.network :forwarded_port, guest: 3389, host: 3389
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
`;
res ~=
`
end
`;
return res.outdent();
}
void provision()
{
auto sh = shell();
// install prerequisites
sh.exec(_setup);
// wait for completion
sh.close();
}
@property string platform() { return _model == Model._both ? osS : osS ~ "-" ~ modelS; }
@property string osS() { return to!string(_os); }
@property string modelS() { return _model == Model._both ? "" : to!string(cast(uint)_model); }
@property string sshcfg() { return buildPath(_tmpdir, "ssh.cfg"); }
OS _os;
Model _model;
string _url; /// optional url of the image
string _setup; /// initial provisioning script
string _tmpdir;
bool _isUp;
}
string runCapture(string cmd)
{
writeln("\033[36m", cmd, "\033[0m");
auto result = executeShell(cmd);
enforce(result.status == 0);
return result.output.strip;
}
void run(string cmd)
{
writeln("\033[36m", cmd, "\033[0m");
enforce(wait(spawnShell(cmd)) == 0);
}
void exec(ProcessPipes pipes, string cmd)
{
writeln("\033[33m", cmd, "\033[0m");
pipes.stdin.writeln(cmd);
}
void close(ProcessPipes pipes)
{
pipes.stdin.close();
// TODO: capture stderr and attach it to enforce
enforce(wait(pipes.pid) == 0);
}
//------------------------------------------------------------------------------
auto addPrefix(R)(R rng, string prefix)
{
return rng.map!(a => prefix ~ a)();
}
//------------------------------------------------------------------------------
// Copy additional release binaries from the previous release
void prepareExtraBins(string workDir)
{
auto winBins = [
"windbg.hlp", "ddemangle.exe", "lib.exe", "link.exe", "make.exe",
"replace.exe", "shell.exe", "windbg.exe", "dm.dll", "eecxxx86.dll",
"emx86.dll", "mspdb41.dll", "shcv.dll", "tlloc.dll", "libcurl.dll",
].addPrefix("bin/");
auto winBins64 = ["libcurl.dll"].addPrefix("bin64/");
auto winLibs = [
"advapi32.lib", "COMCTL32.LIB", "comdlg32.lib", "CTL3D32.LIB",
"gdi32.lib", "kernel32.lib", "ODBC32.LIB", "ole32.lib", "OLEAUT32.LIB",
"rpcrt4.lib", "shell32.lib", "snn.lib", "user32.lib", "uuid.lib",
"winmm.lib", "winspool.lib", "WS2_32.LIB", "wsock32.lib", "curl.lib",
].addPrefix("lib/");
auto winLibs64 = ["curl.lib"].addPrefix("lib64/");
auto winFiles = chain(winBins, winBins64, winLibs, winLibs64).array();
auto extraBins = [
"windows" : winFiles,
"linux" : ["bin32/dumpobj", "bin64/dumpobj", "bin32/obj2asm", "bin64/obj2asm"],
"freebsd" : ["bin32/dumpobj", "bin32/obj2asm", "bin32/shell"],
"osx" : ["bin/dumpobj", "bin/obj2asm", "bin/shell"],
];
foreach (os, files; extraBins)
copyFiles(files.addPrefix("dmd2/"~os~"/").array(),
workDir~"/old-dmd", workDir~"/"~os~"/extraBins");
}
//------------------------------------------------------------------------------
// builds a dmd.VERSION.OS.MODEL.zip on the vanilla VirtualBox image
void runBuild(Box box, string gitTag, bool combine)
{
auto sh = box.shell();
string rdmd;
final switch (box._os)
{
case OS.freebsd:
rdmd = "old-dmd/dmd2/freebsd/bin"~box.modelS~"/rdmd"~
" --compiler=old-dmd/dmd2/freebsd/bin"~box.modelS~"/dmd";
break;
case OS.linux:
rdmd = "old-dmd/dmd2/linux/bin64/rdmd"~
" --compiler=old-dmd/dmd2/linux/bin64/dmd";
break;
case OS.windows:
// update DMC's snn.lib and link.exe
sh.exec(`copy old-dmd\dmd2\windows\bin\link.exe C:\dm\bin\link.exe`);
sh.exec(`copy old-dmd\dmd2\windows\lib\snn.lib C:\dm\lib\snn.lib`);
// copy libcurl needed for create_dmd_release and dlang.org
sh.exec(`copy old-dmd\dmd2\windows\bin\libcurl.dll .`);
sh.exec(`copy old-dmd\dmd2\windows\bin\libcurl.dll clones\dlang.org`);
sh.exec(`copy old-dmd\dmd2\windows\lib\curl.lib clones\dlang.org`);
rdmd = `old-dmd\dmd2\windows\bin\rdmd.exe`~
` --compiler=old-dmd\dmd2\windows\bin\dmd.exe`;
break;
case OS.osx:
rdmd = "old-dmd/dmd2/osx/bin/rdmd"
" --compiler=old-dmd/dmd2/osx/bin/dmd";
break;
}
auto cmd = rdmd~" create_dmd_release -v --extras=extraBins --archive --use-clone=clones";
if (box._model != Model._both)
cmd ~= " --only-" ~ box.modelS;
cmd ~= " " ~ gitTag;
sh.exec(cmd);
if (combine)
sh.exec(rdmd~" create_dmd_release -v --extras=extraBins --combine --use-clone=clones "~gitTag);
sh.close();
// copy out created zip files
box.scp("default:dmd."~gitTag~"."~box.platform~".zip", ".");
if (combine)
box.scp("default:dmd."~gitTag~".zip", ".");
// Build package installers
immutable ver = gitTag.chompPrefix("v");
final switch (box._os)
{
case OS.freebsd:
break;
case OS.linux:
// TBD
break;
case OS.windows:
{
sh = box.shell();
sh.stdin.writeln(`cd clones\installer\windows`);
sh.stdin.writeln(`&'C:\Program Files (x86)\NSIS\makensis'`~
` '/DEmbedD2Dir=C:\Users\vagrant\dmd.`~gitTag~`.windows\dmd2'`~
` '/DVersion2=`~ver~`' d2-installer.nsi`);
sh.stdin.writeln(`copy dmd-`~ver~`.exe C:\Users\vagrant\dmd-`~ver~`.exe`);
sh.close();
box.scp("default:dmd-"~ver~".exe", ".");
}
break;
case OS.osx:
// TBD
break;
}
}
void cloneSources(string gitTag, string tgtDir)
{
auto prefix = "https://github.com/D-Programming-Language/";
auto fmt = "git clone --depth 1 -b "~gitTag~" "~prefix~"%1$s.git "~tgtDir~"/%1$s";
foreach (proj; allProjects)
run(fmt.format(proj));
import std.file;
write(tgtDir~"/dmd/VERSION", gitTag.chompPrefix("v"));
}
int main(string[] args)
{
if (args.length != 2)
{
stderr.writeln("Expected <git-branch-or-tag> as only argument, e.g. v2.064.2.");
return 1;
}
auto gitTag = args[1];
auto workDir = mkdtemp();
scope (success) if (workDir.exists) rmdirRecurse(workDir);
// Cache huge downloads
enum cacheDir = "cached_downloads";
// Determine previous dmd release from gitTag
immutable oldVer = runCapture("git describe --abbrev=0 " ~ gitTag ~ "^");
immutable oldDMD = "dmd." ~ oldVer.chompPrefix("v") ~ ".zip";
enum optlink = "optlink.zip";
enum libC = "snn.lib";
enum libCurl = "libcurl-7.34.0-WinSSL-zlib-x86-x64.zip";
fetchFile("http://ftp.digitalmars.com/"~oldDMD, cacheDir~"/"~oldDMD);
fetchFile("http://ftp.digitalmars.com/"~optlink, cacheDir~"/"~optlink);
fetchFile("http://ftp.digitalmars.com/"~libC, cacheDir~"/"~libC);
fetchFile("http://downloads.dlang.org/other/"~libCurl, cacheDir~"/"~libCurl);
// Get previous dmd release
extractZip(cacheDir~"/"~oldDMD, workDir~"/old-dmd");
// Get latest optlink
remove(workDir~"/old-dmd/dmd2/windows/bin/link.exe");
extractZip(cacheDir~"/"~optlink, workDir~"/old-dmd/dmd2/windows/bin");
// Get latest libC (snn.lib)
remove(workDir~"/old-dmd/dmd2/windows/lib/snn.lib");
copyFile(cacheDir~"/"~libC, workDir~"/old-dmd/dmd2/windows/lib/"~libC);
// Get libcurl for windows
extractZip(cacheDir~"/"~libCurl, workDir~"/old-dmd");
cloneSources(gitTag, workDir~"/clones");
prepareExtraBins(workDir);
foreach (i, box; boxes)
{
immutable combine = i == boxes.length - 1;
// skip a box if we already have its zip files
if (("dmd."~gitTag~"."~box.platform~".zip").exists &&
(!combine || ("dmd."~gitTag~".zip").exists))
{
writeln("\033[31m", "Skipping already build platform '"~box.platform~"'.", "\033[0m");
continue;
}
box.up();
scope (success) box.destroy();
scope (failure) box.halt();
auto toCopy = ["old-dmd", "clones", box.osS~"/extraBins"].addPrefix(workDir~"/").join(" ");
box.scp(toCopy, "default:");
// copy create_dmd_release.d and dependencies
box.scp("create_dmd_release.d common.d", "default:");
// copy all zips into the last box to combine them
if (combine)
{
toCopy = boxes[0 .. $ - 1].map!(b => "dmd."~gitTag~"."~b.platform~".zip").join(" ");
box.scp(toCopy, "default:");
}
runBuild(box, gitTag, combine);
}
return 0;
}