forked from HaxeFoundation/haxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunCi.hx
1325 lines (1163 loc) · 39.8 KB
/
RunCi.hx
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using StringTools;
import yaml.*;
import sys.*;
import sys.io.*;
import haxe.*;
import haxe.io.*;
private typedef TravisConfig = {
before_install: Array<String>,
script: Array<String>
}
/**
List of "TEST" defined in the "matrix" section of ".travis.yml".
*/
@:enum abstract TEST(String) from String {
var Macro = "macro";
var Neko = "neko";
var Js = "js";
var Lua = "lua";
var Php = "php";
var Cpp = "cpp";
var Flash9 = "flash9";
var As3 = "as3";
var Java = "java";
var Cs = "cs";
var Python = "python";
var Hl = "hl";
var ThirdParty = "third-party";
}
enum Ci {
TravisCI;
AppVeyor;
}
/**
Will be run by CI services, currently TravisCI and AppVeyor.
TravisCI:
Setting file: ".travis.yml".
Build result: https://travis-ci.org/HaxeFoundation/haxe
AppVeyor:
Setting file: "appveyor.yml".
Build result: https://ci.appveyor.com/project/HaxeFoundation/haxe
*/
class RunCi {
static function successMsg(msg:String):Void {
Sys.println('\x1b[32m' + msg + '\x1b[0m');
}
static function failMsg(msg:String):Void {
Sys.println('\x1b[31m' + msg + '\x1b[0m');
}
static function infoMsg(msg:String):Void {
Sys.println('\x1b[36m' + msg + '\x1b[0m');
}
/**
Run a command using `Sys.command()`.
If the command exits with non-zero code, exit the whole script with the same code.
If `useRetry` is `true`, the command will be re-run if it exits with non-zero code (3 trials).
It is useful for running network-dependent commands.
*/
static function runCommand(cmd:String, ?args:Array<String>, useRetry:Bool = false):Void {
var trials = useRetry ? 3 : 1;
var exitCode:Int = 1;
var cmdStr = cmd + (args == null ? '' : ' $args');
while (trials-->0) {
Sys.println('Command: $cmdStr');
var t = Timer.stamp();
exitCode = Sys.command(cmd, args);
var dt = Math.round(Timer.stamp() - t);
if (exitCode == 0)
successMsg('Command exited with $exitCode in ${dt}s: $cmdStr');
else
failMsg('Command exited with $exitCode in ${dt}s: $cmdStr');
if (exitCode == 0) {
return;
} else if (trials > 0) {
Sys.println('Command will be re-run...');
}
}
Sys.exit(exitCode);
}
static function isAptPackageInstalled(aptPackage:String):Bool {
return commandSucceed("dpkg-query", ["-W", "-f='${Status}'", aptPackage]);
}
static function requireAptPackages(packages:Array<String>):Void {
var notYetInstalled = [for (p in packages) if (!isAptPackageInstalled(p)) p];
if (notYetInstalled.length > 0)
runCommand("sudo", ["apt-get", "install", "-y"].concat(notYetInstalled), true);
}
static function haxelibInstallGit(account:String, repository:String, ?branch:String, ?srcPath:String, useRetry:Bool = false, ?altName:String):Void {
var name:String = (altName == null) ? repository : altName;
try {
getHaxelibPath(name);
infoMsg('$name has already been installed.');
} catch (e:Dynamic) {
var args:Array<String> = ["git", name, 'https://github.com/$account/$repository'];
if (branch != null) {
args.push(branch);
}
if (srcPath != null) {
args.push(srcPath);
}
runCommand("haxelib", args, useRetry);
}
}
static function haxelibInstall(library:String):Void {
try {
getHaxelibPath(library);
infoMsg('$library has already been installed.');
} catch (e:Dynamic) {
runCommand("haxelib", ["install", library]);
}
}
static function haxelibRun(args:Array<String>, useRetry:Bool = false):Void {
runCommand("haxelib", ["run"].concat(args), useRetry);
}
static function getHaxelibPath(libName:String) {
var proc = new Process("haxelib", ["path", libName]);
var result;
var code = proc.exitCode();
do {
result = proc.stdout.readLine();
if (!result.startsWith("-L")) {
break;
}
} while(true);
proc.close();
if (code != 0) {
throw 'Failed to get haxelib path ($result)';
}
return result;
}
static function changeDirectory(path:String) {
Sys.println('Changing directory to $path');
Sys.setCwd(path);
}
static function setupFlashPlayerDebugger():Void {
var mmcfgPath = switch (systemName) {
case "Linux":
Sys.getEnv("HOME") + "/mm.cfg";
case "Mac":
"/Library/Application Support/Macromedia/mm.cfg";
case _:
throw "unsupported system";
}
switch (systemName) {
case "Linux":
Sys.putEnv("DISPLAY", ":99.0");
runCommand("sh", ["-e", "/etc/init.d/xvfb", "start"]);
Sys.putEnv("AUDIODEV", "null");
requireAptPackages([
"libcurl3:i386", "libglib2.0-0:i386", "libx11-6:i386", "libxext6:i386",
"libxt6:i386", "libxcursor1:i386", "libnss3:i386", "libgtk2.0-0:i386"
]);
runCommand("wget", ["-nv", "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz"], true);
runCommand("tar", ["-xf", "flashplayer_11_sa_debug.i386.tar.gz", "-C", Sys.getEnv("HOME")]);
File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
runCommand(Sys.getEnv("HOME") + "/flashplayerdebugger", ["-v"]);
case "Mac":
runCommand("brew", ["cask", "install", "flash-player-debugger"]);
var dir = Path.directory(mmcfgPath);
runCommand("sudo", ["mkdir", "-p", dir]);
runCommand("sudo", ["chmod", "a+w", dir]);
File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
}
}
/**
Run a Flash swf file.
Return whether the test is successful or not.
It detemines the test result by reading the flashlog.txt, looking for "SUCCESS: true".
*/
static function runFlash(swf:String):Bool {
swf = FileSystem.fullPath(swf);
Sys.println('going to run $swf');
switch (systemName) {
case "Linux":
new Process(Sys.getEnv("HOME") + "/flashplayerdebugger", [swf]);
case "Mac":
Sys.command("open", ["-a", Sys.getEnv("HOME") + "/Applications/Flash Player Debugger.app", swf]);
}
//wait a little until flashlog.txt is created
var flashlogPath = switch (systemName) {
case "Linux":
Sys.getEnv("HOME") + "/.macromedia/Flash_Player/Logs/flashlog.txt";
case "Mac":
Sys.getEnv("HOME") + "/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
case _:
throw "unsupported system";
}
for (t in 0...5) {
runCommand("sleep", ["2"]);
if (FileSystem.exists(flashlogPath))
break;
}
if (!FileSystem.exists(flashlogPath)) {
failMsg('$flashlogPath not found.');
return false;
}
//read flashlog.txt continously
var traceProcess = new Process("tail", ["-f", flashlogPath]);
var line = "";
while (true) {
try {
line = traceProcess.stdout.readLine();
Sys.println(line);
if (line.indexOf("SUCCESS: ") >= 0) {
return line.indexOf("SUCCESS: true") >= 0;
}
} catch (e:haxe.io.Eof) {
break;
}
}
return false;
}
static function runCs(exe:String, ?args:Array<String>):Void {
if (args == null) args = [];
exe = FileSystem.fullPath(exe);
switch (systemName) {
case "Linux", "Mac":
runCommand("mono", [exe].concat(args));
case "Windows":
runCommand(exe, args);
switch (ci) {
case AppVeyor:
// https://github.com/HaxeFoundation/haxe/issues/4873
// runCommand("mono", [exe].concat(args));
case _:
//pass
}
}
}
static function runCpp(bin:String, ?args:Array<String>):Void {
if (args == null) args = [];
bin = FileSystem.fullPath(bin);
runCommand(bin, args);
}
static function parseCommand(cmd:String) {
var args = [];
var offset = 0;
var cur = new StringBuf();
var inString = false;
while(true) {
switch(cmd.fastCodeAt(offset++)) {
case '"'.code:
inString = !inString;
case ' '.code if (!inString):
if (cur.length > 0) {
args.push(cur.toString());
cur = new StringBuf();
}
case '\\'.code:
cur.addChar(cmd.fastCodeAt(offset++));
case "$".code:
switch (cmd.fastCodeAt(offset)) {
case '('.code:
++offset;
var env = new StringBuf();
while(true) {
switch(cmd.fastCodeAt(offset++)) {
case ')'.code:
break;
case c:
env.addChar(c);
}
}
cur.add(Sys.getEnv(env.toString()));
case _:
cur.addChar("$".code);
}
case c:
cur.addChar(c);
}
if (offset == cmd.length) {
break;
}
}
if (cur.length > 0) {
args.push(cur.toString());
}
return args;
}
//static function parseTravisFile(path:String, ignoreBeforeInstall = false) {
//var yaml:TravisConfig = yaml.Yaml.read(path, Parser.options().useObjects());
//if (!ignoreBeforeInstall) {
//for (code in yaml.before_install) {
//var args = parseCommand(code);
//var cmd = args.shift();
//runCommand(cmd, args);
//}
//}
//for (code in yaml.script) {
//var args = parseCommand(code);
//var cmd = args.shift();
//runCommand(cmd, args);
//}
//}
static function commandSucceed(cmd:String, args:Array<String>):Bool {
return try {
var p = new Process(cmd, args);
var succeed = p.exitCode() == 0;
p.close();
succeed;
} catch(e:Dynamic) false;
}
static function commandResult(cmd:String, args:Array<String>):{
stdout:String,
stderr:String,
exitCode:Int
} {
var p = new Process(cmd, args);
var out = {
stdout: p.stdout.readAll().toString(),
stderr: p.stderr.readAll().toString(),
exitCode: p.exitCode()
}
p.close();
return out;
}
static function addToPATH(path:String):Void {
switch (systemName) {
case "Windows":
Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + path);
case "Mac", "Linux":
Sys.putEnv("PATH", Sys.getEnv("PATH") + ":" + path);
}
}
static function getPhpDependencies() {
switch (systemName) {
case "Linux":
if (commandSucceed("php", ["-v"])) {
infoMsg('php has already been installed.');
} else {
requireAptPackages(["php5-cli", "php5-mysql", "php5-sqlite"]);
}
case "Mac":
//pass
case "Windows":
if (commandSucceed("php", ["-v"])) {
infoMsg('php has already been installed.');
} else {
runCommand("cinst", ["php", "-version", "5.6.3", "-y"], true);
addToPATH("C:\\tools\\php");
}
}
runCommand("php", ["-v"]);
}
static var gotCppDependencies = false;
static function getCppDependencies() {
if (gotCppDependencies) return;
//hxcpp dependencies
switch (systemName) {
case "Linux":
requireAptPackages(["gcc-multilib", "g++-multilib"]);
case "Mac":
//pass
}
//install and build hxcpp
try {
getHaxelibPath("hxcpp");
infoMsg('hxcpp has already been installed.');
} catch(e:Dynamic) {
haxelibInstallGit("HaxeFoundation", "hxcpp", true);
var oldDir = Sys.getCwd();
changeDirectory(getHaxelibPath("hxcpp") + "tools/hxcpp/");
runCommand("haxe", ["compile.hxml"]);
changeDirectory(oldDir);
}
gotCppDependencies = true;
}
static function getJavaDependencies() {
haxelibInstallGit("HaxeFoundation", "hxjava", true);
runCommand("javac", ["-version"]);
}
static function getJSDependencies() {
switch (systemName) {
case "Linux":
if (commandSucceed("node", ["-v"])) {
infoMsg('node has already been installed.');
} else {
requireAptPackages(["nodejs"]);
}
case "Mac":
//pass
}
runCommand("node", ["-v"]);
}
static function getLuaDependencies(jit = false, lua_version = "lua5.2", luarocks_version = "2.3.0") {
switch (systemName){
case "Linux": requireAptPackages(["libpcre3-dev"]);
case "Mac": runCommand("brew", ["install", "pcre"]);
}
var home_dir = Sys.getEnv("HOME");
// the lua paths created by the setup script.
addToPATH('$home_dir/.lua');
addToPATH('$home_dir/.local/bin');
// we need to cd back into the build directory to do some work
var build_dir = Sys.getEnv("TRAVIS_BUILD_DIR");
changeDirectory(build_dir);
// luarocks needs to be in the path
addToPATH('$build_dir/install/luarocks/bin');
if (jit) Sys.putEnv("LUAJIT","yes");
Sys.putEnv("LUAROCKS", luarocks_version);
Sys.putEnv("LUA", lua_version);
// use the helper scripts in .travis. TODO: Refactor as pure haxe?
runCommand("sh", ['${build_dir}/.travis/setenv_lua.sh']);
if (jit){
runCommand("luajit", ["-v"]);
} else {
runCommand("lua", ["-v"]);
}
runCommand("pip", ["install", "--user", "cpp-coveralls"]);
runCommand("luarocks", ["install", "lrexlib-pcre", "2.7.2-1", "--server=https://luarocks.org/dev"]);
runCommand("luarocks", ["install", "luautf8", "--server=https://luarocks.org/dev"]);
// we did user land installs of luarocks and lua. We need to point lua
// to the luarocks install using the luarocks path and env variables
var lua_path = commandResult("luarocks", ["path", "--lr-path"]).stdout.trim();
Sys.putEnv("LUA_PATH", lua_path);
trace(lua_path + " is the value for lua_path");
// step two of the variable setting
var lua_cpath = commandResult("luarocks", ["path", "--lr-cpath"]).stdout.trim();
Sys.putEnv("LUA_CPATH", lua_cpath);
trace(lua_cpath + " is the value for lua_cpath");
// change back to the unit dir for the rest of the tests
changeDirectory(unitDir);
}
static function getCsDependencies() {
switch (systemName) {
case "Linux":
if (commandSucceed("mono", ["--version"]))
infoMsg('mono has already been installed.');
else
requireAptPackages(["mono-devel", "mono-mcs"]);
runCommand("mono", ["--version"]);
case "Mac":
if (commandSucceed("mono", ["--version"]))
infoMsg('mono has already been installed.');
else
runCommand("brew", ["install", "mono"], true);
runCommand("mono", ["--version"]);
case "Windows":
switch (ci) {
case AppVeyor:
addToPATH("C:\\Program Files (x86)\\Mono\\bin");
runCommand("mono", ["--version"]);
case _:
//pass
}
}
haxelibInstallGit("HaxeFoundation", "hxcs", true);
}
static var gotOpenFLDependencies = false;
static function getOpenFLDependencies() {
if (gotOpenFLDependencies) return;
getCppDependencies();
haxelibInstallGit("HaxeFoundation", "format");
haxelibInstallGit("haxenme", "nme");
haxelibInstallGit("haxenme", "nme-dev");
haxelibInstallGit("openfl", "svg");
haxelibInstallGit("openfl", "lime");
haxelibInstallGit("openfl", "lime-tools");
haxelibInstallGit("openfl", "openfl-native");
haxelibInstallGit("openfl", "openfl-html5");
haxelibInstallGit("openfl", "openfl");
switch (systemName) {
case "Linux":
haxelibRun(["openfl", "rebuild", "linux"]);
case "Mac":
haxelibRun(["openfl", "rebuild", "mac"]);
}
haxelibRun(["openfl", "rebuild", "tools"]);
gotOpenFLDependencies = true;
}
/**
Install python and return the names of the installed pythons.
*/
static function getPythonDependencies():Array<String> {
switch (systemName) {
case "Linux":
if (commandSucceed("python3", ["-V"]))
infoMsg('python3 has already been installed.');
else
requireAptPackages(["python3"]);
runCommand("python3", ["-V"]);
var pypy = "pypy3";
if (commandSucceed(pypy, ["-V"])) {
infoMsg('pypy3 has already been installed.');
} else {
var pypyVersion = "pypy3-2.4.0-linux64";
runCommand("wget", ['https://bitbucket.org/pypy/pypy/downloads/${pypyVersion}.tar.bz2'], true);
runCommand("tar", ["-xf", '${pypyVersion}.tar.bz2']);
pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
}
runCommand(pypy, ["-V"]);
return ["python3", pypy];
case "Mac":
if (commandSucceed("python3", ["-V"]))
infoMsg('python3 has already been installed.');
else
runCommand("brew", ["install", "python3"], true);
runCommand("python3", ["-V"]);
if (commandSucceed("pypy3", ["-V"]))
infoMsg('pypy3 has already been installed.');
else
runCommand("brew", ["install", "pypy3"], true);
runCommand("pypy3", ["-V"]);
return ["python3", "pypy3"];
case "Windows":
if (commandSucceed("python3", ["-V"]))
infoMsg('python3 has already been installed.');
else
throw "please install python 3.x and make it available as python3 in PATH";
runCommand("python3", ["-V"]);
return ["python3"];
}
return [];
}
static var ci(default, never):Null<Ci> =
if (Sys.getEnv("TRAVIS") == "true")
TravisCI;
else if (Sys.getEnv("APPVEYOR") == "True")
AppVeyor;
else
null;
static var systemName(default, never) = Sys.systemName();
static var cwd(default, never) = Sys.getCwd();
static var repoDir(default, never) = FileSystem.fullPath("..") + "/";
static var unitDir(default, never) = cwd + "unit/";
static var sysDir(default, never) = cwd + "sys/";
static var optDir(default, never) = cwd + "optimization/";
static var miscDir(default, never) = cwd + "misc/";
static var displayDir(default, never) = cwd + "display/";
static var gitInfo(get, null):{repo:String, branch:String, commit:String, timestamp:Float, date:String};
static function get_gitInfo() return if (gitInfo != null) gitInfo else gitInfo = {
repo: switch (ci) {
case TravisCI:
Sys.getEnv("TRAVIS_REPO_SLUG");
case AppVeyor:
Sys.getEnv("APPVEYOR_PROJECT_SLUG");
case _:
commandResult("git", ["config", "--get", "remote.origin.url"]).stdout.trim();
},
branch: switch (ci) {
case TravisCI:
Sys.getEnv("TRAVIS_BRANCH");
case AppVeyor:
Sys.getEnv("APPVEYOR_REPO_BRANCH");
case _:
commandResult("git", ["rev-parse", "--abbrev-ref", "HEAD"]).stdout.trim();
},
commit: commandResult("git", ["rev-parse", "HEAD"]).stdout.trim(),
timestamp: Std.parseFloat(commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout),
date: {
var gitTime = commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout;
var tzd = {
var z = Date.fromTime(0);
z.getHours() * 60 * 60 * 1000 + z.getMinutes() * 60 * 1000;
}
// make time in the UTC time zone
var time = Date.fromTime(Std.parseFloat(gitTime) * 1000 - tzd);
DateTools.format(time, "%FT%TZ");
}
}
static var haxeVer(default, never) = {
var haxe_ver = haxe.macro.Compiler.getDefine("haxe_ver");
switch (haxe_ver.split(".")) {
case [major]:
major;
case [major, minor] if (minor.length == 1):
'${major}.${minor}';
case [major, minor] if (minor.length > 1):
var minor = minor.charAt(0);
var patch = Std.parseInt(minor.substr(1));
'${major}.${minor}.${patch}';
case _:
throw haxe_ver;
}
}
static var haxeVerFull(default, never) = {
var ver = haxeVer.split(".");
while (ver.length < 3) {
ver.push("0");
}
ver.join(".");
}
static function deploy():Void {
if (
Sys.getEnv("DEPLOY") != null
) {
changeDirectory(repoDir);
// generate doc
runCommand("make", ["-s", "install_dox"]);
runCommand("make", ["-s", "package_doc"]);
// deployBintray();
deployApiDoc();
deployPPA();
}
}
static function deployBintray():Void {
if (
Sys.getEnv("BINTRAY") != null &&
Sys.getEnv("BINTRAY_USERNAME") != null &&
Sys.getEnv("BINTRAY_API_KEY") != null
) {
// generate bintray config
var tpl = new Template(File.getContent("extra/bintray.tpl.json"));
var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
var json = tpl.execute({
packageSubject: {
var sub = Sys.getEnv("BINTRAY_SUBJECT");
sub != null ? sub : Sys.getEnv("BINTRAY_USERNAME");
},
os: systemName.toLowerCase(),
versionName: '${haxeVer}+${compatDate}.${gitInfo.commit.substr(0,7)}',
versionDesc: "Automated CI build.",
gitRepo: gitInfo.repo,
gitBranch: gitInfo.branch,
gitCommit: gitInfo.commit,
gitDate: gitInfo.date,
});
var path = "extra/bintray.json";
File.saveContent("extra/bintray.json", json);
infoMsg("saved " + FileSystem.absolutePath(path) + " with content:");
Sys.println(json);
}
}
/**
Deploy doc to api.haxe.org.
*/
static function deployApiDoc():Void {
if (
gitInfo.branch == "development" &&
Sys.getEnv("DEPLOY") != null &&
Sys.getEnv("deploy_key_decrypt") != null
) {
// setup deploy_key
runCommand("openssl aes-256-cbc -k \"$deploy_key_decrypt\" -in extra/deploy_key.enc -out extra/deploy_key -d");
runCommand("chmod 600 extra/deploy_key");
runCommand("ssh-add extra/deploy_key");
runCommand("make", ["-s", "deploy_doc"]);
}
}
/**
Deploy source package to ppa:haxe/snapshots.
*/
static function deployPPA():Void {
if (
gitInfo.branch == "development" &&
Sys.getEnv("DEPLOY") != null &&
Sys.getEnv("haxeci_decrypt") != null
) {
// setup haxeci_ssh
runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_ssh.enc -out extra/haxeci_ssh -d");
runCommand("chmod 600 extra/haxeci_ssh");
runCommand("ssh-add extra/haxeci_ssh");
// setup haxeci_sec.gpg
runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_sec.gpg.enc -out extra/haxeci_sec.gpg -d");
runCommand("gpg --allow-secret-key-import --import extra/haxeci_sec.gpg");
runCommand("sudo apt-get install devscripts git-buildpackage ubuntu-dev-tools dh-make -y");
var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
var SNAPSHOT_VERSION = '${haxeVerFull}+1SNAPSHOT${compatDate}+${gitInfo.commit.substr(0,7)}';
runCommand('cp out/haxe*_src.tar.gz "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz"');
changeDirectory("..");
runCommand("git clone https://github.com/HaxeFoundation/haxe-debian.git");
changeDirectory("haxe-debian");
runCommand("git checkout upstream");
runCommand("git checkout next");
runCommand('gbp import-orig "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz" -u "${SNAPSHOT_VERSION}" --debian-branch=next');
runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
runCommand("debuild -S -sa");
runCommand("backportpackage -d xenial --upload ${PPA} --yes ../haxe_*.dsc");
runCommand("backportpackage -d wily --upload ${PPA} --yes ../haxe_*.dsc");
runCommand("backportpackage -d vivid --upload ${PPA} --yes ../haxe_*.dsc");
runCommand("backportpackage -d trusty --upload ${PPA} --yes ../haxe_*.dsc");
runCommand("git checkout debian/changelog");
runCommand("git config --global user.name \"${DEBFULLNAME}\"");
runCommand("git config --global user.email \"${DEBEMAIL}\"");
runCommand("git merge -X ours --no-edit origin/backport-precise");
runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
runCommand("debuild -S -sa");
runCommand("backportpackage -d precise --upload ${PPA} --yes ../haxe_*.dsc");
}
}
static function saveOutput():Void {
if (Sys.getEnv("HAXECI_GH_TOKEN") == null) {
infoMsg("Missing HAXECI_GH_TOKEN. Will not save output.");
return;
}
changeDirectory(repoDir);
var haxe_output = Path.join([repoDir, "haxe-output"]);
var gitInfo = gitInfo;
var TEST = Sys.getEnv("TEST");
var TRAVIS_OS_NAME = Sys.getEnv("TRAVIS_OS_NAME");
var haxe_output_branch = '${gitInfo.branch}_travisci_${TRAVIS_OS_NAME}_${TEST}';
var haxe_output_repo = "github.com/HaxeFoundation/haxe-output.git";
function haxeCommitTime(sha:String):Float {
var cwd = Sys.getCwd();
Sys.setCwd(repoDir);
var time = Std.parseFloat(commandResult("git", ["show", "-s", "--pretty=%ct", sha]).stdout);
Sys.setCwd(cwd);
return time;
}
function save():Void {
// prepare haxe-output repo
runCommand("git", ["clone", 'https://${Sys.getEnv("HAXECI_GH_TOKEN")}@${haxe_output_repo}', haxe_output]);
changeDirectory(haxe_output);
runCommand("git", ["config", "user.email", "haxe-ci@onthewings.net"]);
runCommand("git", ["config", "user.name", "Haxe CI Bot"]);
// check to see whether the haxe repo branch has been created in haxe-output
var firstOutputBranch = switch (Sys.command("git", ["ls-remote", "--exit-code", "origin", haxe_output_branch])) {
case 0: false;
case 2: true;
case exitcode: throw "unknown exit code: " + exitcode;
}
// switch to the branch
if (firstOutputBranch) {
runCommand("git", ["checkout", "-B", haxe_output_branch]);
} else {
runCommand("git", ["checkout", "-B", haxe_output_branch, "--track", "origin/" + haxe_output_branch]);
}
// check to see whether this will be the first push of this haxe repo commit
var firstOutputCommit = firstOutputBranch || {
var lastLog = commandResult("git", ["show", "-s", "--pretty=format:%B", "HEAD"]).stdout;
var commitRe = ~/[a-f0-9]{40}/;
if (!commitRe.match(lastLog)) {
infoMsg("No commit sha found in log: " + lastLog);
true;
} else {
var lastCommit = commitRe.matched(0);
// check to see whether this commit is newer than the last pushed one
// in case e.g. the current build is a rebuild of an old commit
if (haxeCommitTime(lastCommit) > gitInfo.timestamp) {
throw "There exists output with a later commit in the haxe-output repo.";
}
lastCommit != gitInfo.commit;
}
};
// Remove all the old output first.
// It is because there may be files no longer emitted by the current build.
if (firstOutputCommit) {
runCommand("rm", ["-rf", "tests"]);
}
// get the outputs by listing the files/folders ignored by git
changeDirectory(cwd);
var stdout = {
var proc = new Process("git", ["status", "--ignored", "--porcelain", cwd]);
var out = proc.stdout.readAll().toString();
proc.close();
out;
};
var outputs = stdout.split("\n")
.filter(function(s) return s.startsWith("!! "))
.map(function(s) return s.substr("!! ".length));
// copy all the outputs to haxe-output
FileSystem.createDirectory(haxe_output);
for (item in outputs) {
var orig = Path.join([repoDir, item]);
var dest = Path.join([haxe_output, item]);
if (FileSystem.isDirectory(orig)) {
FileSystem.createDirectory(dest);
} else {
FileSystem.createDirectory(Path.directory(dest));
}
runCommand("cp", ["-rf", orig, dest]);
}
changeDirectory(haxe_output);
runCommand("git", ["add", "--all", haxe_output]);
var commitMsg = [
'-m', '${Sys.getEnv("TRAVIS_JOB_NUMBER")} ${TEST} https://github.com/HaxeFoundation/haxe/commit/${gitInfo.commit}',
'-m', 'https://travis-ci.org/HaxeFoundation/haxe/jobs/${Sys.getEnv("TRAVIS_JOB_ID")}',
];
runCommand("git", ["commit", "-q", "--allow-empty"].concat(commitMsg));
}
// try save() for 5 times because the push may fail when the another build push at the same time
var pushError = false;
for (i in 0...5) {
try {
save();
} catch (e:Dynamic) {
infoMsg(e);
pushError = false;
break;
}
var pushResult = commandResult("git", ["push", "origin", haxe_output_branch]);
if (pushResult.exitCode == 0) {
successMsg("push to haxe-output succeed");
pushError = false;
break;
} else {
failMsg("push to haxe-output failed");
failMsg(pushResult.stderr);
pushError = true;
runCommand("rm", ["-rf", haxe_output]);
Sys.sleep(Std.random(10));
}
}
if (pushError) {
Sys.exit(1);
}
}
static function main():Void {
Sys.putEnv("OCAMLRUNPARAM", "b");
var tests:Array<TEST> = switch (Sys.getEnv("TEST")) {
case null:
[Macro];
case env:
[for (v in env.split(",")) v.trim().toLowerCase()];
}
Sys.println('Going to test: $tests');
for (test in tests) {
infoMsg('Now test $test');
changeDirectory(unitDir);
var args = switch (ci) {
case TravisCI:
["-D","travis"];
case AppVeyor:
["-D","appveyor"];
case _:
[];
}
switch (test) {
case Macro:
runCommand("haxe", ["compile-macro.hxml"].concat(args));
changeDirectory(displayDir);
runCommand("haxe", ["build.hxml"]);
changeDirectory(miscDir);
getCsDependencies();
getPythonDependencies();
runCommand("haxe", ["compile.hxml"]);
changeDirectory(sysDir);
runCommand("haxe", ["compile-macro.hxml"]);
runCommand("haxe", ["compile-each.hxml", "--run", "Main"]);
//BYTECODE
switch (ci) {
case null:
//pass
case TravisCI:
changeDirectory(repoDir);
runCommand("make", ["BYTECODE=1", "-s"]);
// runCommand("sudo", ["make", "install", "-s"]);
changeDirectory(unitDir);
runCommand("haxe", ["compile-macro.hxml"]);
case AppVeyor:
// save time...
// changeDirectory(repoDir);
// runCommand(Sys.getEnv("CYG_ROOT") + "/bin/bash", ["-lc", 'cd \"$$OLDPWD\" && make -s -f Makefile.win BYTECODE=1']);
// changeDirectory(unitDir);
// runCommand("haxe", ["compile-macro.hxml"]);
}
case Neko:
runCommand("haxe", ["compile-neko.hxml", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
runCommand("neko", ["bin/unit.n"]);
changeDirectory(sysDir);
runCommand("haxe", ["compile-neko.hxml"]);
runCommand("neko", ["bin/neko/sys.n"]);
case Php:
getPhpDependencies();
runCommand("haxe", ["compile-php.hxml"].concat(args));
runCommand("php", ["bin/php/index.php"]);
changeDirectory(sysDir);
runCommand("haxe", ["compile-php.hxml"]);
runCommand("php", ["bin/php/Main/index.php"]);
case Python:
var pys = getPythonDependencies();
runCommand("haxe", ["compile-python.hxml"].concat(args));
for (py in pys) {
runCommand(py, ["bin/unit.py"]);
}
changeDirectory(sysDir);
runCommand("haxe", ["compile-python.hxml"]);
for (py in pys) {
runCommand(py, ["bin/python/sys.py"]);
}
changeDirectory(miscDir + "pythonImport");
runCommand("haxe", ["compile.hxml"]);
for (py in pys) {
runCommand(py, ["test.py"]);
}
case Lua:
getLuaDependencies();
runCommand("haxe", ["compile-lua.hxml"].concat(args));
runCommand("lua", ["bin/unit.lua"]);
case Cpp:
getCppDependencies();
runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M32"].concat(args));
runCpp("bin/cpp/Test-debug", []);
switch (ci) {
case AppVeyor:
//save time...
case _:
runCommand("rm", ["-rf", "cpp"]);
runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"].concat(args));
runCpp("bin/cpp/Test-debug", []);
}
changeDirectory(sysDir);