RunCi.hx 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. using StringTools;
  2. import yaml.*;
  3. import sys.*;
  4. import sys.io.*;
  5. import haxe.*;
  6. import haxe.io.*;
  7. private typedef TravisConfig = {
  8. before_install: Array<String>,
  9. script: Array<String>
  10. }
  11. /**
  12. List of "TEST" defined in the "matrix" section of ".travis.yml".
  13. */
  14. @:enum abstract TEST(String) from String {
  15. var Macro = "macro";
  16. var Neko = "neko";
  17. var Js = "js";
  18. var Lua = "lua";
  19. var Php = "php";
  20. var Cpp = "cpp";
  21. var Flash9 = "flash9";
  22. var As3 = "as3";
  23. var Java = "java";
  24. var Cs = "cs";
  25. var Python = "python";
  26. var Hl = "hl";
  27. var ThirdParty = "third-party";
  28. }
  29. enum Ci {
  30. TravisCI;
  31. AppVeyor;
  32. }
  33. enum Failure {
  34. Fail;
  35. }
  36. /**
  37. Will be run by CI services, currently TravisCI and AppVeyor.
  38. TravisCI:
  39. Setting file: ".travis.yml".
  40. Build result: https://travis-ci.org/HaxeFoundation/haxe
  41. AppVeyor:
  42. Setting file: "appveyor.yml".
  43. Build result: https://ci.appveyor.com/project/HaxeFoundation/haxe
  44. */
  45. class RunCi {
  46. static function successMsg(msg:String):Void {
  47. Sys.println('\x1b[32m' + msg + '\x1b[0m');
  48. }
  49. static function failMsg(msg:String):Void {
  50. Sys.println('\x1b[31m' + msg + '\x1b[0m');
  51. }
  52. static function infoMsg(msg:String):Void {
  53. Sys.println('\x1b[36m' + msg + '\x1b[0m');
  54. }
  55. static function fail():Void {
  56. success = false;
  57. throw Fail;
  58. }
  59. /**
  60. Run a command using `Sys.command()`.
  61. If the command exits with non-zero code, exit the whole script with the same code.
  62. If `useRetry` is `true`, the command will be re-run if it exits with non-zero code (3 trials).
  63. It is useful for running network-dependent commands.
  64. */
  65. static function runCommand(cmd:String, ?args:Array<String>, useRetry:Bool = false):Void {
  66. var trials = useRetry ? 3 : 1;
  67. var exitCode:Int = 1;
  68. var cmdStr = cmd + (args == null ? '' : ' $args');
  69. while (trials-->0) {
  70. Sys.println('Command: $cmdStr');
  71. var t = Timer.stamp();
  72. exitCode = Sys.command(cmd, args);
  73. var dt = Math.round(Timer.stamp() - t);
  74. if (exitCode == 0)
  75. successMsg('Command exited with $exitCode in ${dt}s: $cmdStr');
  76. else
  77. failMsg('Command exited with $exitCode in ${dt}s: $cmdStr');
  78. if (exitCode == 0) {
  79. return;
  80. } else if (trials > 0) {
  81. Sys.println('Command will be re-run...');
  82. }
  83. }
  84. fail();
  85. }
  86. static function isAptPackageInstalled(aptPackage:String):Bool {
  87. return commandSucceed("dpkg-query", ["-W", "-f='${Status}'", aptPackage]);
  88. }
  89. static function requireAptPackages(packages:Array<String>):Void {
  90. var notYetInstalled = [for (p in packages) if (!isAptPackageInstalled(p)) p];
  91. if (notYetInstalled.length > 0)
  92. runCommand("sudo", ["apt-get", "install", "-y"].concat(notYetInstalled), true);
  93. }
  94. static function haxelibInstallGit(account:String, repository:String, ?branch:String, ?srcPath:String, useRetry:Bool = false, ?altName:String):Void {
  95. var name:String = (altName == null) ? repository : altName;
  96. try {
  97. getHaxelibPath(name);
  98. infoMsg('$name has already been installed.');
  99. } catch (e:Dynamic) {
  100. var args:Array<String> = ["git", name, 'https://github.com/$account/$repository'];
  101. if (branch != null) {
  102. args.push(branch);
  103. }
  104. if (srcPath != null) {
  105. args.push(srcPath);
  106. }
  107. runCommand("haxelib", args, useRetry);
  108. }
  109. }
  110. static function haxelibInstall(library:String):Void {
  111. try {
  112. getHaxelibPath(library);
  113. infoMsg('$library has already been installed.');
  114. } catch (e:Dynamic) {
  115. runCommand("haxelib", ["install", library]);
  116. }
  117. }
  118. static function haxelibRun(args:Array<String>, useRetry:Bool = false):Void {
  119. runCommand("haxelib", ["run"].concat(args), useRetry);
  120. }
  121. static function getHaxelibPath(libName:String) {
  122. var proc = new Process("haxelib", ["path", libName]);
  123. var result;
  124. var code = proc.exitCode();
  125. do {
  126. result = proc.stdout.readLine();
  127. if (!result.startsWith("-L")) {
  128. break;
  129. }
  130. } while(true);
  131. proc.close();
  132. if (code != 0) {
  133. throw 'Failed to get haxelib path ($result)';
  134. }
  135. return result;
  136. }
  137. static function changeDirectory(path:String) {
  138. Sys.println('Changing directory to $path');
  139. Sys.setCwd(path);
  140. }
  141. static function setupFlashPlayerDebugger():Void {
  142. var mmcfgPath = switch (systemName) {
  143. case "Linux":
  144. Sys.getEnv("HOME") + "/mm.cfg";
  145. case "Mac":
  146. "/Library/Application Support/Macromedia/mm.cfg";
  147. case _:
  148. throw "unsupported system";
  149. }
  150. switch (systemName) {
  151. case "Linux":
  152. requireAptPackages([
  153. "libcurl3:i386", "libglib2.0-0:i386", "libx11-6:i386", "libxext6:i386",
  154. "libxt6:i386", "libxcursor1:i386", "libnss3:i386", "libgtk2.0-0:i386"
  155. ]);
  156. runCommand("wget", ["-nv", "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz"], true);
  157. runCommand("tar", ["-xf", "flashplayer_11_sa_debug.i386.tar.gz", "-C", Sys.getEnv("HOME")]);
  158. File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
  159. runCommand(Sys.getEnv("HOME") + "/flashplayerdebugger", ["-v"]);
  160. case "Mac":
  161. runCommand("brew", ["cask", "install", "flash-player-debugger"]);
  162. var dir = Path.directory(mmcfgPath);
  163. runCommand("sudo", ["mkdir", "-p", dir]);
  164. runCommand("sudo", ["chmod", "a+w", dir]);
  165. File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
  166. }
  167. }
  168. /**
  169. Run a Flash swf file.
  170. Return whether the test is successful or not.
  171. It detemines the test result by reading the flashlog.txt, looking for "SUCCESS: true".
  172. */
  173. static function runFlash(swf:String):Bool {
  174. swf = FileSystem.fullPath(swf);
  175. Sys.println('going to run $swf');
  176. switch (systemName) {
  177. case "Linux":
  178. new Process(Sys.getEnv("HOME") + "/flashplayerdebugger", [swf]);
  179. case "Mac":
  180. Sys.command("open", ["-a", Sys.getEnv("HOME") + "/Applications/Flash Player Debugger.app", swf]);
  181. }
  182. //wait a little until flashlog.txt is created
  183. var flashlogPath = switch (systemName) {
  184. case "Linux":
  185. Sys.getEnv("HOME") + "/.macromedia/Flash_Player/Logs/flashlog.txt";
  186. case "Mac":
  187. Sys.getEnv("HOME") + "/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
  188. case _:
  189. throw "unsupported system";
  190. }
  191. for (t in 0...5) {
  192. runCommand("sleep", ["2"]);
  193. if (FileSystem.exists(flashlogPath))
  194. break;
  195. }
  196. if (!FileSystem.exists(flashlogPath)) {
  197. failMsg('$flashlogPath not found.');
  198. return false;
  199. }
  200. //read flashlog.txt continously
  201. var traceProcess = new Process("tail", ["-f", flashlogPath]);
  202. var line = "";
  203. while (true) {
  204. try {
  205. line = traceProcess.stdout.readLine();
  206. Sys.println(line);
  207. if (line.indexOf("SUCCESS: ") >= 0) {
  208. return line.indexOf("SUCCESS: true") >= 0;
  209. }
  210. } catch (e:haxe.io.Eof) {
  211. break;
  212. }
  213. }
  214. return false;
  215. }
  216. static function runCs(exe:String, ?args:Array<String>):Void {
  217. if (args == null) args = [];
  218. exe = FileSystem.fullPath(exe);
  219. switch (systemName) {
  220. case "Linux", "Mac":
  221. runCommand("mono", [exe].concat(args));
  222. case "Windows":
  223. runCommand(exe, args);
  224. switch (ci) {
  225. case AppVeyor:
  226. // https://github.com/HaxeFoundation/haxe/issues/4873
  227. // runCommand("mono", [exe].concat(args));
  228. case _:
  229. //pass
  230. }
  231. }
  232. }
  233. static function runCpp(bin:String, ?args:Array<String>):Void {
  234. if (args == null) args = [];
  235. bin = FileSystem.fullPath(bin);
  236. runCommand(bin, args);
  237. }
  238. static function parseCommand(cmd:String) {
  239. var args = [];
  240. var offset = 0;
  241. var cur = new StringBuf();
  242. var inString = false;
  243. while(true) {
  244. switch(cmd.fastCodeAt(offset++)) {
  245. case '"'.code:
  246. inString = !inString;
  247. case ' '.code if (!inString):
  248. if (cur.length > 0) {
  249. args.push(cur.toString());
  250. cur = new StringBuf();
  251. }
  252. case '\\'.code:
  253. cur.addChar(cmd.fastCodeAt(offset++));
  254. case "$".code:
  255. switch (cmd.fastCodeAt(offset)) {
  256. case '('.code:
  257. ++offset;
  258. var env = new StringBuf();
  259. while(true) {
  260. switch(cmd.fastCodeAt(offset++)) {
  261. case ')'.code:
  262. break;
  263. case c:
  264. env.addChar(c);
  265. }
  266. }
  267. cur.add(Sys.getEnv(env.toString()));
  268. case _:
  269. cur.addChar("$".code);
  270. }
  271. case c:
  272. cur.addChar(c);
  273. }
  274. if (offset == cmd.length) {
  275. break;
  276. }
  277. }
  278. if (cur.length > 0) {
  279. args.push(cur.toString());
  280. }
  281. return args;
  282. }
  283. //static function parseTravisFile(path:String, ignoreBeforeInstall = false) {
  284. //var yaml:TravisConfig = yaml.Yaml.read(path, Parser.options().useObjects());
  285. //if (!ignoreBeforeInstall) {
  286. //for (code in yaml.before_install) {
  287. //var args = parseCommand(code);
  288. //var cmd = args.shift();
  289. //runCommand(cmd, args);
  290. //}
  291. //}
  292. //for (code in yaml.script) {
  293. //var args = parseCommand(code);
  294. //var cmd = args.shift();
  295. //runCommand(cmd, args);
  296. //}
  297. //}
  298. static function commandSucceed(cmd:String, args:Array<String>):Bool {
  299. return try {
  300. var p = new Process(cmd, args);
  301. var succeed = p.exitCode() == 0;
  302. p.close();
  303. succeed;
  304. } catch(e:Dynamic) false;
  305. }
  306. static function commandResult(cmd:String, args:Array<String>):{
  307. stdout:String,
  308. stderr:String,
  309. exitCode:Int
  310. } {
  311. var p = new Process(cmd, args);
  312. var out = {
  313. stdout: p.stdout.readAll().toString(),
  314. stderr: p.stderr.readAll().toString(),
  315. exitCode: p.exitCode()
  316. }
  317. p.close();
  318. return out;
  319. }
  320. static function addToPATH(path:String):Void {
  321. switch (systemName) {
  322. case "Windows":
  323. Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + path);
  324. case "Mac", "Linux":
  325. Sys.putEnv("PATH", Sys.getEnv("PATH") + ":" + path);
  326. }
  327. }
  328. static function getPhpDependencies() {
  329. switch (systemName) {
  330. case "Linux":
  331. if (commandSucceed("php", ["-v"])) {
  332. infoMsg('php has already been installed.');
  333. } else {
  334. requireAptPackages(["php5-cli", "php5-mysql", "php5-sqlite"]);
  335. }
  336. case "Mac":
  337. //pass
  338. case "Windows":
  339. if (commandSucceed("php", ["-v"])) {
  340. infoMsg('php has already been installed.');
  341. } else {
  342. runCommand("cinst", ["php", "-version", "5.6.3", "-y"], true);
  343. addToPATH("C:\\tools\\php");
  344. }
  345. }
  346. runCommand("php", ["-v"]);
  347. }
  348. static var gotCppDependencies = false;
  349. static function getCppDependencies() {
  350. if (gotCppDependencies) return;
  351. //hxcpp dependencies
  352. switch (systemName) {
  353. case "Linux":
  354. requireAptPackages(["gcc-multilib", "g++-multilib"]);
  355. case "Mac":
  356. //pass
  357. }
  358. //install and build hxcpp
  359. try {
  360. getHaxelibPath("hxcpp");
  361. infoMsg('hxcpp has already been installed.');
  362. } catch(e:Dynamic) {
  363. haxelibInstallGit("HaxeFoundation", "hxcpp", true);
  364. var oldDir = Sys.getCwd();
  365. changeDirectory(getHaxelibPath("hxcpp") + "tools/hxcpp/");
  366. runCommand("haxe", ["compile.hxml"]);
  367. changeDirectory(oldDir);
  368. }
  369. gotCppDependencies = true;
  370. }
  371. static function getJavaDependencies() {
  372. haxelibInstallGit("HaxeFoundation", "hxjava", true);
  373. runCommand("javac", ["-version"]);
  374. }
  375. static function getJSDependencies() {
  376. switch (systemName) {
  377. case "Linux":
  378. if (commandSucceed("node", ["-v"])) {
  379. infoMsg('node has already been installed.');
  380. } else {
  381. requireAptPackages(["nodejs"]);
  382. }
  383. case "Mac":
  384. //pass
  385. }
  386. runCommand("node", ["-v"]);
  387. }
  388. static function getLuaDependencies(jit = false, lua_version = "lua5.2", luarocks_version = "2.3.0") {
  389. switch (systemName){
  390. case "Linux": requireAptPackages(["libpcre3-dev"]);
  391. case "Mac": runCommand("brew", ["install", "pcre"]);
  392. }
  393. var home_dir = Sys.getEnv("HOME");
  394. // the lua paths created by the setup script.
  395. addToPATH('$home_dir/.lua');
  396. addToPATH('$home_dir/.local/bin');
  397. // we need to cd back into the build directory to do some work
  398. var build_dir = Sys.getEnv("TRAVIS_BUILD_DIR");
  399. changeDirectory(build_dir);
  400. // luarocks needs to be in the path
  401. addToPATH('$build_dir/install/luarocks/bin');
  402. if (jit) Sys.putEnv("LUAJIT","yes");
  403. Sys.putEnv("LUAROCKS", luarocks_version);
  404. Sys.putEnv("LUA", lua_version);
  405. // use the helper scripts in .travis. TODO: Refactor as pure haxe?
  406. runCommand("sh", ['${build_dir}/.travis/setenv_lua.sh']);
  407. if (jit){
  408. runCommand("luajit", ["-v"]);
  409. } else {
  410. runCommand("lua", ["-v"]);
  411. }
  412. runCommand("pip", ["install", "--user", "cpp-coveralls"]);
  413. runCommand("luarocks", ["install", "lrexlib-pcre", "2.7.2-1", "--server=https://luarocks.org/dev"]);
  414. runCommand("luarocks", ["install", "luautf8", "--server=https://luarocks.org/dev"]);
  415. // we did user land installs of luarocks and lua. We need to point lua
  416. // to the luarocks install using the luarocks path and env variables
  417. var lua_path = commandResult("luarocks", ["path", "--lr-path"]).stdout.trim();
  418. Sys.putEnv("LUA_PATH", lua_path);
  419. trace(lua_path + " is the value for lua_path");
  420. // step two of the variable setting
  421. var lua_cpath = commandResult("luarocks", ["path", "--lr-cpath"]).stdout.trim();
  422. Sys.putEnv("LUA_CPATH", lua_cpath);
  423. trace(lua_cpath + " is the value for lua_cpath");
  424. // change back to the unit dir for the rest of the tests
  425. changeDirectory(unitDir);
  426. }
  427. static function getCsDependencies() {
  428. switch (systemName) {
  429. case "Linux":
  430. if (commandSucceed("mono", ["--version"]))
  431. infoMsg('mono has already been installed.');
  432. else
  433. requireAptPackages(["mono-devel", "mono-mcs"]);
  434. runCommand("mono", ["--version"]);
  435. case "Mac":
  436. if (commandSucceed("mono", ["--version"]))
  437. infoMsg('mono has already been installed.');
  438. else
  439. runCommand("brew", ["install", "mono"], true);
  440. runCommand("mono", ["--version"]);
  441. case "Windows":
  442. switch (ci) {
  443. case AppVeyor:
  444. addToPATH("C:\\Program Files (x86)\\Mono\\bin");
  445. runCommand("mono", ["--version"]);
  446. case _:
  447. //pass
  448. }
  449. }
  450. haxelibInstallGit("HaxeFoundation", "hxcs", true);
  451. }
  452. static var gotOpenFLDependencies = false;
  453. static function getOpenFLDependencies() {
  454. if (gotOpenFLDependencies) return;
  455. getCppDependencies();
  456. haxelibInstallGit("HaxeFoundation", "format");
  457. haxelibInstallGit("haxenme", "nme");
  458. haxelibInstallGit("haxenme", "nme-dev");
  459. haxelibInstallGit("openfl", "svg");
  460. haxelibInstallGit("openfl", "lime");
  461. haxelibInstallGit("openfl", "lime-tools");
  462. haxelibInstallGit("openfl", "openfl-native");
  463. haxelibInstallGit("openfl", "openfl-html5");
  464. haxelibInstallGit("openfl", "openfl");
  465. switch (systemName) {
  466. case "Linux":
  467. haxelibRun(["openfl", "rebuild", "linux"]);
  468. case "Mac":
  469. haxelibRun(["openfl", "rebuild", "mac"]);
  470. }
  471. haxelibRun(["openfl", "rebuild", "tools"]);
  472. gotOpenFLDependencies = true;
  473. }
  474. /**
  475. Install python and return the names of the installed pythons.
  476. */
  477. static function getPythonDependencies():Array<String> {
  478. switch (systemName) {
  479. case "Linux":
  480. if (commandSucceed("python3", ["-V"]))
  481. infoMsg('python3 has already been installed.');
  482. else
  483. requireAptPackages(["python3"]);
  484. runCommand("python3", ["-V"]);
  485. var pypy = "pypy3";
  486. if (commandSucceed(pypy, ["-V"])) {
  487. infoMsg('pypy3 has already been installed.');
  488. } else {
  489. var pypyVersion = "pypy3-2.4.0-linux64";
  490. runCommand("wget", ['https://bitbucket.org/pypy/pypy/downloads/${pypyVersion}.tar.bz2'], true);
  491. runCommand("tar", ["-xf", '${pypyVersion}.tar.bz2']);
  492. pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
  493. }
  494. runCommand(pypy, ["-V"]);
  495. return ["python3", pypy];
  496. case "Mac":
  497. if (commandSucceed("python3", ["-V"]))
  498. infoMsg('python3 has already been installed.');
  499. else
  500. runCommand("brew", ["install", "python3"], true);
  501. runCommand("python3", ["-V"]);
  502. if (commandSucceed("pypy3", ["-V"]))
  503. infoMsg('pypy3 has already been installed.');
  504. else
  505. runCommand("brew", ["install", "pypy3"], true);
  506. runCommand("pypy3", ["-V"]);
  507. return ["python3", "pypy3"];
  508. case "Windows":
  509. if (commandSucceed("python3", ["-V"]))
  510. infoMsg('python3 has already been installed.');
  511. else
  512. throw "please install python 3.x and make it available as python3 in PATH";
  513. runCommand("python3", ["-V"]);
  514. return ["python3"];
  515. }
  516. return [];
  517. }
  518. static var ci(default, never):Null<Ci> =
  519. if (Sys.getEnv("TRAVIS") == "true")
  520. TravisCI;
  521. else if (Sys.getEnv("APPVEYOR") == "True")
  522. AppVeyor;
  523. else
  524. null;
  525. static var systemName(default, never) = Sys.systemName();
  526. static var cwd(default, never) = Sys.getCwd();
  527. static var repoDir(default, never) = FileSystem.fullPath("..") + "/";
  528. static var unitDir(default, never) = cwd + "unit/";
  529. static var sysDir(default, never) = cwd + "sys/";
  530. static var optDir(default, never) = cwd + "optimization/";
  531. static var miscDir(default, never) = cwd + "misc/";
  532. static var displayDir(default, never) = cwd + "display/";
  533. static var gitInfo(get, null):{repo:String, branch:String, commit:String, timestamp:Float, date:String};
  534. static var success(default, null) = true;
  535. static function get_gitInfo() return if (gitInfo != null) gitInfo else gitInfo = {
  536. repo: switch (ci) {
  537. case TravisCI:
  538. Sys.getEnv("TRAVIS_REPO_SLUG");
  539. case AppVeyor:
  540. Sys.getEnv("APPVEYOR_PROJECT_SLUG");
  541. case _:
  542. commandResult("git", ["config", "--get", "remote.origin.url"]).stdout.trim();
  543. },
  544. branch: switch (ci) {
  545. case TravisCI:
  546. Sys.getEnv("TRAVIS_BRANCH");
  547. case AppVeyor:
  548. Sys.getEnv("APPVEYOR_REPO_BRANCH");
  549. case _:
  550. commandResult("git", ["rev-parse", "--abbrev-ref", "HEAD"]).stdout.trim();
  551. },
  552. commit: commandResult("git", ["rev-parse", "HEAD"]).stdout.trim(),
  553. timestamp: Std.parseFloat(commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout),
  554. date: {
  555. var gitTime = commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout;
  556. var tzd = {
  557. var z = Date.fromTime(0);
  558. z.getHours() * 60 * 60 * 1000 + z.getMinutes() * 60 * 1000;
  559. }
  560. // make time in the UTC time zone
  561. var time = Date.fromTime(Std.parseFloat(gitTime) * 1000 - tzd);
  562. DateTools.format(time, "%FT%TZ");
  563. }
  564. }
  565. static var haxeVer(default, never) = {
  566. var haxe_ver = haxe.macro.Compiler.getDefine("haxe_ver");
  567. switch (haxe_ver.split(".")) {
  568. case [major]:
  569. major;
  570. case [major, minor] if (minor.length == 1):
  571. '${major}.${minor}';
  572. case [major, minor] if (minor.length > 1):
  573. var minor = minor.charAt(0);
  574. var patch = Std.parseInt(minor.substr(1));
  575. '${major}.${minor}.${patch}';
  576. case _:
  577. throw haxe_ver;
  578. }
  579. }
  580. static var haxeVerFull(default, never) = {
  581. var ver = haxeVer.split(".");
  582. while (ver.length < 3) {
  583. ver.push("0");
  584. }
  585. ver.join(".");
  586. }
  587. static function deploy():Void {
  588. if (
  589. Sys.getEnv("DEPLOY") != null
  590. ) {
  591. changeDirectory(repoDir);
  592. // generate doc
  593. runCommand("make", ["-s", "install_dox"]);
  594. runCommand("make", ["-s", "package_doc"]);
  595. // deployBintray();
  596. deployApiDoc();
  597. deployPPA();
  598. }
  599. }
  600. static function deployBintray():Void {
  601. if (
  602. Sys.getEnv("BINTRAY") != null &&
  603. Sys.getEnv("BINTRAY_USERNAME") != null &&
  604. Sys.getEnv("BINTRAY_API_KEY") != null
  605. ) {
  606. // generate bintray config
  607. var tpl = new Template(File.getContent("extra/bintray.tpl.json"));
  608. var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
  609. var json = tpl.execute({
  610. packageSubject: {
  611. var sub = Sys.getEnv("BINTRAY_SUBJECT");
  612. sub != null ? sub : Sys.getEnv("BINTRAY_USERNAME");
  613. },
  614. os: systemName.toLowerCase(),
  615. versionName: '${haxeVer}+${compatDate}.${gitInfo.commit.substr(0,7)}',
  616. versionDesc: "Automated CI build.",
  617. gitRepo: gitInfo.repo,
  618. gitBranch: gitInfo.branch,
  619. gitCommit: gitInfo.commit,
  620. gitDate: gitInfo.date,
  621. });
  622. var path = "extra/bintray.json";
  623. File.saveContent("extra/bintray.json", json);
  624. infoMsg("saved " + FileSystem.absolutePath(path) + " with content:");
  625. Sys.println(json);
  626. }
  627. }
  628. /**
  629. Deploy doc to api.haxe.org.
  630. */
  631. static function deployApiDoc():Void {
  632. if (
  633. gitInfo.branch == "development" &&
  634. Sys.getEnv("DEPLOY") != null &&
  635. Sys.getEnv("deploy_key_decrypt") != null
  636. ) {
  637. // setup deploy_key
  638. runCommand("openssl aes-256-cbc -k \"$deploy_key_decrypt\" -in extra/deploy_key.enc -out extra/deploy_key -d");
  639. runCommand("chmod 600 extra/deploy_key");
  640. runCommand("ssh-add extra/deploy_key");
  641. runCommand("make", ["-s", "deploy_doc"]);
  642. }
  643. }
  644. /**
  645. Deploy source package to ppa:haxe/snapshots.
  646. */
  647. static function deployPPA():Void {
  648. if (
  649. gitInfo.branch == "development" &&
  650. Sys.getEnv("DEPLOY") != null &&
  651. Sys.getEnv("haxeci_decrypt") != null
  652. ) {
  653. // setup haxeci_ssh
  654. runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_ssh.enc -out extra/haxeci_ssh -d");
  655. runCommand("chmod 600 extra/haxeci_ssh");
  656. runCommand("ssh-add extra/haxeci_ssh");
  657. // setup haxeci_sec.gpg
  658. runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_sec.gpg.enc -out extra/haxeci_sec.gpg -d");
  659. runCommand("gpg --allow-secret-key-import --import extra/haxeci_sec.gpg");
  660. runCommand("sudo apt-get install devscripts git-buildpackage ubuntu-dev-tools dh-make -y");
  661. var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
  662. var SNAPSHOT_VERSION = '${haxeVerFull}+1SNAPSHOT${compatDate}+${gitInfo.commit.substr(0,7)}';
  663. runCommand('cp out/haxe*_src.tar.gz "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz"');
  664. changeDirectory("..");
  665. runCommand("git clone https://github.com/HaxeFoundation/haxe-debian.git");
  666. changeDirectory("haxe-debian");
  667. runCommand("git checkout upstream");
  668. runCommand("git checkout next");
  669. runCommand('gbp import-orig "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz" -u "${SNAPSHOT_VERSION}" --debian-branch=next');
  670. runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
  671. runCommand("debuild -S -sa");
  672. runCommand("backportpackage -d xenial --upload ${PPA} --yes ../haxe_*.dsc");
  673. runCommand("backportpackage -d wily --upload ${PPA} --yes ../haxe_*.dsc");
  674. runCommand("backportpackage -d vivid --upload ${PPA} --yes ../haxe_*.dsc");
  675. runCommand("backportpackage -d trusty --upload ${PPA} --yes ../haxe_*.dsc");
  676. runCommand("git checkout debian/changelog");
  677. runCommand("git config --global user.name \"${DEBFULLNAME}\"");
  678. runCommand("git config --global user.email \"${DEBEMAIL}\"");
  679. runCommand("git merge -X ours --no-edit origin/backport-precise");
  680. runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
  681. runCommand("debuild -S -sa");
  682. runCommand("backportpackage -d precise --upload ${PPA} --yes ../haxe_*.dsc");
  683. }
  684. }
  685. static function saveOutput():Void {
  686. if (Sys.getEnv("HAXECI_GH_TOKEN") == null) {
  687. infoMsg("Missing HAXECI_GH_TOKEN. Will not save output.");
  688. return;
  689. }
  690. changeDirectory(repoDir);
  691. var haxe_output = Path.join([repoDir, "haxe-output"]);
  692. var gitInfo = gitInfo;
  693. var TEST = Sys.getEnv("TEST");
  694. var TRAVIS_OS_NAME = Sys.getEnv("TRAVIS_OS_NAME");
  695. var haxe_output_branch = '${gitInfo.branch}_travisci_${TRAVIS_OS_NAME}_${TEST}';
  696. var haxe_output_repo = "github.com/HaxeFoundation/haxe-output.git";
  697. function haxeCommitTime(sha:String):Float {
  698. var cwd = Sys.getCwd();
  699. Sys.setCwd(repoDir);
  700. var time = Std.parseFloat(commandResult("git", ["show", "-s", "--pretty=%ct", sha]).stdout);
  701. Sys.setCwd(cwd);
  702. return time;
  703. }
  704. function save():Void {
  705. // prepare haxe-output repo
  706. runCommand("git", ["clone", 'https://${Sys.getEnv("HAXECI_GH_TOKEN")}@${haxe_output_repo}', haxe_output]);
  707. changeDirectory(haxe_output);
  708. runCommand("git", ["config", "user.email", "[email protected]"]);
  709. runCommand("git", ["config", "user.name", "Haxe CI Bot"]);
  710. // check to see whether the haxe repo branch has been created in haxe-output
  711. var firstOutputBranch = switch (Sys.command("git", ["ls-remote", "--exit-code", "origin", haxe_output_branch])) {
  712. case 0: false;
  713. case 2: true;
  714. case exitcode: throw "unknown exit code: " + exitcode;
  715. }
  716. // switch to the branch
  717. if (firstOutputBranch) {
  718. runCommand("git", ["checkout", "-B", haxe_output_branch]);
  719. } else {
  720. runCommand("git", ["checkout", "-B", haxe_output_branch, "--track", "origin/" + haxe_output_branch]);
  721. }
  722. // check to see whether this will be the first push of this haxe repo commit
  723. var firstOutputCommit = firstOutputBranch || {
  724. var lastLog = commandResult("git", ["show", "-s", "--pretty=format:%B", "HEAD"]).stdout;
  725. var commitRe = ~/[a-f0-9]{40}/;
  726. if (!commitRe.match(lastLog)) {
  727. infoMsg("No commit sha found in log: " + lastLog);
  728. true;
  729. } else {
  730. var lastCommit = commitRe.matched(0);
  731. // check to see whether this commit is newer than the last pushed one
  732. // in case e.g. the current build is a rebuild of an old commit
  733. if (haxeCommitTime(lastCommit) > gitInfo.timestamp) {
  734. throw "There exists output with a later commit in the haxe-output repo.";
  735. }
  736. lastCommit != gitInfo.commit;
  737. }
  738. };
  739. // Remove all the old output first.
  740. // It is because there may be files no longer emitted by the current build.
  741. if (firstOutputCommit) {
  742. runCommand("rm", ["-rf", "tests"]);
  743. }
  744. // get the outputs by listing the files/folders ignored by git
  745. changeDirectory(cwd);
  746. var stdout = {
  747. var proc = new Process("git", ["status", "--ignored", "--porcelain", cwd]);
  748. var out = proc.stdout.readAll().toString();
  749. proc.close();
  750. out;
  751. };
  752. var outputs = stdout.split("\n")
  753. .filter(function(s) return s.startsWith("!! "))
  754. .map(function(s) return s.substr("!! ".length));
  755. // copy all the outputs to haxe-output
  756. FileSystem.createDirectory(haxe_output);
  757. for (item in outputs) {
  758. var orig = Path.join([repoDir, item]);
  759. var dest = Path.join([haxe_output, item]);
  760. if (FileSystem.isDirectory(orig)) {
  761. FileSystem.createDirectory(dest);
  762. } else {
  763. FileSystem.createDirectory(Path.directory(dest));
  764. }
  765. runCommand("cp", ["-rf", orig, dest]);
  766. }
  767. changeDirectory(haxe_output);
  768. runCommand("git", ["add", "--all", haxe_output]);
  769. var commitMsg = [
  770. '-m', '${Sys.getEnv("TRAVIS_JOB_NUMBER")} ${TEST} https://github.com/HaxeFoundation/haxe/commit/${gitInfo.commit}',
  771. '-m', 'https://travis-ci.org/HaxeFoundation/haxe/jobs/${Sys.getEnv("TRAVIS_JOB_ID")}',
  772. ];
  773. runCommand("git", ["commit", "-q", "--allow-empty"].concat(commitMsg));
  774. }
  775. // try save() for 5 times because the push may fail when the another build push at the same time
  776. var pushError = false;
  777. for (i in 0...5) {
  778. try {
  779. save();
  780. } catch (e:Dynamic) {
  781. infoMsg(e);
  782. pushError = false;
  783. break;
  784. }
  785. var pushResult = commandResult("git", ["push", "origin", haxe_output_branch]);
  786. if (pushResult.exitCode == 0) {
  787. successMsg("push to haxe-output succeeded");
  788. pushError = false;
  789. break;
  790. } else {
  791. failMsg("push to haxe-output failed");
  792. failMsg(pushResult.stderr);
  793. pushError = true;
  794. runCommand("rm", ["-rf", haxe_output]);
  795. Sys.sleep(Std.random(10));
  796. }
  797. }
  798. if (pushError) {
  799. fail();
  800. }
  801. }
  802. static function main():Void {
  803. Sys.putEnv("OCAMLRUNPARAM", "b");
  804. var tests:Array<TEST> = switch (Sys.getEnv("TEST")) {
  805. case null:
  806. [Macro];
  807. case env:
  808. [for (v in env.split(",")) v.trim().toLowerCase()];
  809. }
  810. Sys.println('Going to test: $tests');
  811. for (test in tests) {
  812. switch (ci) {
  813. case TravisCI:
  814. Sys.println('travis_fold:start:test-${test}');
  815. case _:
  816. //pass
  817. }
  818. infoMsg('test $test');
  819. var success = true;
  820. try {
  821. changeDirectory(unitDir);
  822. var args = switch (ci) {
  823. case TravisCI:
  824. ["-D","travis"];
  825. case AppVeyor:
  826. ["-D","appveyor"];
  827. case _:
  828. [];
  829. }
  830. switch (test) {
  831. case Macro:
  832. runCommand("haxe", ["compile-macro.hxml"].concat(args));
  833. changeDirectory(displayDir);
  834. runCommand("haxe", ["build.hxml"]);
  835. changeDirectory(miscDir);
  836. getCsDependencies();
  837. getPythonDependencies();
  838. runCommand("haxe", ["compile.hxml"]);
  839. changeDirectory(sysDir);
  840. runCommand("haxe", ["compile-macro.hxml"]);
  841. runCommand("haxe", ["compile-each.hxml", "--run", "Main"]);
  842. case Neko:
  843. runCommand("haxe", ["compile-neko.hxml", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
  844. runCommand("neko", ["bin/unit.n"]);
  845. changeDirectory(sysDir);
  846. runCommand("haxe", ["compile-neko.hxml"]);
  847. runCommand("neko", ["bin/neko/sys.n"]);
  848. case Php:
  849. getPhpDependencies();
  850. runCommand("haxe", ["compile-php.hxml"].concat(args));
  851. runCommand("php", ["bin/php/index.php"]);
  852. changeDirectory(sysDir);
  853. runCommand("haxe", ["compile-php.hxml"]);
  854. runCommand("php", ["bin/php/Main/index.php"]);
  855. case Python:
  856. var pys = getPythonDependencies();
  857. runCommand("haxe", ["compile-python.hxml"].concat(args));
  858. for (py in pys) {
  859. runCommand(py, ["bin/unit.py"]);
  860. }
  861. changeDirectory(sysDir);
  862. runCommand("haxe", ["compile-python.hxml"]);
  863. for (py in pys) {
  864. runCommand(py, ["bin/python/sys.py"]);
  865. }
  866. changeDirectory(miscDir + "pythonImport");
  867. runCommand("haxe", ["compile.hxml"]);
  868. for (py in pys) {
  869. runCommand(py, ["test.py"]);
  870. }
  871. case Lua:
  872. getLuaDependencies();
  873. runCommand("haxe", ["compile-lua.hxml"].concat(args));
  874. runCommand("lua", ["bin/unit.lua"]);
  875. case Cpp:
  876. getCppDependencies();
  877. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M32"].concat(args));
  878. runCpp("bin/cpp/Test-debug", []);
  879. switch (ci) {
  880. case AppVeyor:
  881. //save time...
  882. case _:
  883. runCommand("rm", ["-rf", "cpp"]);
  884. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"].concat(args));
  885. runCpp("bin/cpp/Test-debug", []);
  886. }
  887. changeDirectory(sysDir);
  888. runCommand("haxe", ["compile-cpp.hxml"]);
  889. runCpp("bin/cpp/Main-debug", []);
  890. if (Sys.systemName() == "Mac")
  891. {
  892. changeDirectory(miscDir + "cppObjc");
  893. runCommand("haxe", ["build.hxml"]);
  894. runCpp("bin/TestObjc-debug");
  895. }
  896. case Js:
  897. getJSDependencies();
  898. var jsOutputs = [
  899. for (es3 in [[], ["-D", "js-es=3"]])
  900. for (unflatten in [[], ["-D", "js-unflatten"]])
  901. for (classic in [[], ["-D", "js-classic"]])
  902. {
  903. var extras = args.concat(es3).concat(unflatten).concat(classic);
  904. runCommand("haxe", ["compile-js.hxml"].concat(extras));
  905. var output = if (extras.length > 0) {
  906. "bin/js/" + extras.join("") + "/unit.js";
  907. } else {
  908. "bin/js/default/unit.js";
  909. }
  910. var outputDir = Path.directory(output);
  911. if (!FileSystem.exists(outputDir)) {
  912. FileSystem.createDirectory(outputDir);
  913. }
  914. FileSystem.rename("bin/unit.js", output);
  915. FileSystem.rename("bin/unit.js.map", output + ".map");
  916. runCommand("node", ["-e", "var unit = require('./" + output + "').unit; unit.Test.main(); process.exit(unit.Test.success ? 0 : 1);"]);
  917. output;
  918. }
  919. ];
  920. var env = Sys.environment();
  921. if (
  922. env.exists("SAUCE") &&
  923. env.exists("SAUCE_USERNAME") &&
  924. env.exists("SAUCE_ACCESS_KEY")
  925. ) {
  926. // sauce-connect should have been started
  927. // var scVersion = "sc-4.3-linux";
  928. // runCommand("wget", ['https://saucelabs.com/downloads/${scVersion}.tar.gz'], true);
  929. // runCommand("tar", ["-xf", '${scVersion}.tar.gz']);
  930. // //start sauce-connect
  931. // var scReadyFile = "sauce-connect-ready-" + Std.random(100);
  932. // var sc = new Process('${scVersion}/bin/sc', [
  933. // "-i", Sys.getEnv("TRAVIS_JOB_NUMBER"),
  934. // "-f", scReadyFile
  935. // ]);
  936. // while(!FileSystem.exists(scReadyFile)) {
  937. // Sys.sleep(0.5);
  938. // }
  939. runCommand("npm", ["install", "wd", "q"], true);
  940. haxelibInstall("hxnodejs");
  941. runCommand("haxe", ["compile-saucelabs-runner.hxml"]);
  942. var server = new Process("nekotools", ["server"]);
  943. runCommand("node", ["bin/RunSauceLabs.js"].concat([for (js in jsOutputs) "unit-js.html?js=" + js.urlEncode()]));
  944. server.close();
  945. // sc.close();
  946. }
  947. infoMsg("Test optimization:");
  948. changeDirectory(optDir);
  949. runCommand("haxe", ["run.hxml"]);
  950. case Java:
  951. getJavaDependencies();
  952. runCommand("haxe", ["compile-java.hxml"].concat(args));
  953. runCommand("java", ["-jar", "bin/java/Test-Debug.jar"]);
  954. runCommand("haxe", ["compile-java.hxml","-dce","no"].concat(args));
  955. runCommand("java", ["-jar", "bin/java/Test-Debug.jar"]);
  956. changeDirectory(sysDir);
  957. runCommand("haxe", ["compile-java.hxml"]);
  958. runCommand("java", ["-jar", "bin/java/Main-Debug.jar"]);
  959. infoMsg("Testing java-lib extras");
  960. changeDirectory('$unitDir/bin');
  961. runCommand("git", ["clone", "https://github.com/waneck/java-lib-tests.git", "--depth", "1"], true);
  962. for (dir in FileSystem.readDirectory('java-lib-tests'))
  963. {
  964. var path = 'java-lib-tests/$dir';
  965. if (FileSystem.isDirectory(path)) for (file in FileSystem.readDirectory(path))
  966. {
  967. if (file.endsWith('.hxml'))
  968. {
  969. runCommand("haxe", ["--cwd",'java-lib-tests/$dir',file]);
  970. }
  971. }
  972. }
  973. case Cs:
  974. getCsDependencies();
  975. var compl = switch [ci, systemName] {
  976. case [TravisCI, "Linux"]:
  977. "-travis";
  978. case _:
  979. "";
  980. };
  981. runCommand("haxe", ['compile-cs$compl.hxml']);
  982. runCs("bin/cs/bin/Test-Debug.exe");
  983. runCommand("haxe", ['compile-cs$compl.hxml','-D','fast_cast']);
  984. runCs("bin/cs/bin/Test-Debug.exe");
  985. runCommand("haxe", ['compile-cs$compl.hxml','-dce','no','-D','fast_cast']);
  986. runCs("bin/cs/bin/Test-Debug.exe");
  987. runCommand("haxe", ['compile-cs-unsafe$compl.hxml','-D','fast_cast']);
  988. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  989. runCommand("haxe", ['compile-cs$compl.hxml',"-D","erase_generics",'-D','fast_cast']);
  990. runCs("bin/cs/bin/Test-Debug.exe");
  991. runCommand("haxe", ['compile-cs-unsafe$compl.hxml',"-D","erase_generics",'-D','fast_cast']);
  992. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  993. runCommand("haxe", ['compile-cs$compl.hxml',"-D","no_root",'-D','fast_cast']);
  994. runCs("bin/cs/bin/Test-Debug.exe");
  995. runCommand("haxe", ['compile-cs-unsafe$compl.hxml',"-D","no_root","-D","erase_generics",'-D','fast_cast']);
  996. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  997. changeDirectory(sysDir);
  998. runCommand("haxe", ["compile-cs.hxml",'-D','fast_cast']);
  999. runCs("bin/cs/bin/Main-Debug.exe", []);
  1000. changeDirectory(miscDir + "csTwoLibs");
  1001. for (i in 1...5)
  1002. {
  1003. runCommand("haxe", ['compile-$i.hxml','-D','fast_cast']);
  1004. runCs("bin/main/bin/Main.exe");
  1005. }
  1006. case Flash9:
  1007. setupFlashPlayerDebugger();
  1008. runCommand("haxe", ["compile-flash9.hxml", "-D", "fdb", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
  1009. var success = runFlash("bin/unit9.swf");
  1010. if (!success)
  1011. fail();
  1012. case As3:
  1013. setupFlashPlayerDebugger();
  1014. //setup flex sdk
  1015. if (commandSucceed("mxmlc", ["--version"])) {
  1016. infoMsg('mxmlc has already been installed.');
  1017. } else {
  1018. var flexVersion = "4.14.1";
  1019. runCommand("wget", ['http://archive.apache.org/dist/flex/${flexVersion}/binaries/apache-flex-sdk-${flexVersion}-bin.tar.gz'], true);
  1020. runCommand("tar", ["-xf", 'apache-flex-sdk-${flexVersion}-bin.tar.gz', "-C", Sys.getEnv("HOME")]);
  1021. var flexsdkPath = Sys.getEnv("HOME") + '/apache-flex-sdk-${flexVersion}-bin';
  1022. addToPATH(flexsdkPath + "/bin");
  1023. var playerglobalswcFolder = flexsdkPath + "/player";
  1024. FileSystem.createDirectory(playerglobalswcFolder + "/11.1");
  1025. runCommand("wget", ["-nv", "http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc", "-O", playerglobalswcFolder + "/11.1/playerglobal.swc"], true);
  1026. File.saveContent(flexsdkPath + "/env.properties", 'env.PLAYERGLOBAL_HOME=$playerglobalswcFolder');
  1027. runCommand("mxmlc", ["--version"]);
  1028. }
  1029. runCommand("haxe", ["compile-as3.hxml", "-D", "fdb"].concat(args));
  1030. var success = runFlash("bin/unit9_as3.swf");
  1031. if (!success)
  1032. fail();
  1033. case Hl:
  1034. runCommand("haxe", ["compile-hl.hxml"]);
  1035. case ThirdParty:
  1036. getPhpDependencies();
  1037. getJavaDependencies();
  1038. getJSDependencies();
  1039. getCsDependencies();
  1040. getPythonDependencies();
  1041. getCppDependencies();
  1042. //getOpenFLDependencies();
  1043. //testPolygonalDs();
  1044. // if (systemName == "Linux") testFlambe(); //#3439
  1045. testHxTemplo();
  1046. testMUnit();
  1047. testHaxeQuake();
  1048. //testOpenflSamples();
  1049. //testFlixelDemos();
  1050. case t:
  1051. throw "unknown target: " + t;
  1052. }
  1053. } catch(f:Failure) {
  1054. success = false;
  1055. }
  1056. switch (ci) {
  1057. case TravisCI:
  1058. Sys.println('travis_fold:end:test-${test}');
  1059. case _:
  1060. //pass
  1061. }
  1062. if (success) {
  1063. successMsg('test ${test} succeeded');
  1064. } else {
  1065. failMsg('test ${test} failed');
  1066. }
  1067. }
  1068. if (
  1069. (switch [ci, systemName] {
  1070. case [TravisCI, "Linux"]: true;
  1071. case _: false;
  1072. })
  1073. &&
  1074. Lambda.exists(tests, function(t) return switch (t) {
  1075. case Js | Cpp | Cs | Java | Php | Python | Neko | Flash9 | As3: true;
  1076. case _: false;
  1077. })
  1078. ) {
  1079. saveOutput();
  1080. }
  1081. if (success) {
  1082. deploy();
  1083. } else {
  1084. Sys.exit(1);
  1085. }
  1086. }
  1087. static function testHxTemplo() {
  1088. infoMsg("Test hx-templo:");
  1089. changeDirectory(unitDir);
  1090. haxelibInstallGit("Simn", "hxparse", "development", "src");
  1091. haxelibInstallGit("Simn", "hxtemplo");
  1092. var buildArgs = [
  1093. "-cp", "src",
  1094. "-cp", "test",
  1095. "-main", "Test",
  1096. "-lib", "hxparse",
  1097. "-dce", "full"
  1098. ];
  1099. changeDirectory(getHaxelibPath("hxtemplo") + "..");
  1100. runCommand("haxe", ["build.hxml"]);
  1101. }
  1102. static function testPolygonalDs() {
  1103. infoMsg("Test polygonal-ds:");
  1104. changeDirectory(unitDir);
  1105. haxelibInstallGit("Simn", "ds", "python-support", null, false, "polygonal-ds");
  1106. haxelibInstallGit("polygonal", "core", "master", "src", false, "polygonal-core");
  1107. haxelibInstallGit("polygonal", "printf", "master", "src", false, "polygonal-printf");
  1108. changeDirectory(getHaxelibPath("polygonal-ds"));
  1109. runCommand("haxe", ["build.hxml"]);
  1110. runCommand("python3", ["unit.py"]);
  1111. runCommand("node", ["unit.js"]);
  1112. }
  1113. static function testMUnit() {
  1114. infoMsg("Test MUnit:");
  1115. changeDirectory(unitDir);
  1116. haxelibInstallGit("massiveinteractive", "mconsole", "master", "src");
  1117. haxelibInstallGit("massiveinteractive", "MassiveCover", "master", "src", false, "mcover");
  1118. haxelibInstallGit("massiveinteractive", "MassiveLib", "master", "src", false, "mlib");
  1119. haxelibInstallGit("massiveinteractive", "MassiveUnit", "2.1.2", "src", false, "munit");
  1120. changeDirectory(Path.join([getHaxelibPath("munit"), "..", "tool"]));
  1121. runCommand("haxe", ["build.hxml"]);
  1122. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  1123. changeDirectory("../");
  1124. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  1125. }
  1126. static function testHaxeQuake() {
  1127. infoMsg("Test HaxeQuake:");
  1128. changeDirectory(unitDir);
  1129. runCommand("git", ["clone", "https://github.com/nadako/HaxeQuake"]);
  1130. changeDirectory("HaxeQuake/Client");
  1131. runCommand("haxe", ["build.hxml"]);
  1132. }
  1133. static function testFlambe() {
  1134. infoMsg("Test Flambe:");
  1135. changeDirectory(unitDir);
  1136. runCommand("git", ["clone", "https://github.com/aduros/flambe"]);
  1137. runCommand("sh", ["flambe/bin/run-travis"]);
  1138. }
  1139. //static function testOpenflSamples() {
  1140. //infoMsg("Test OpenFL Samples:");
  1141. //
  1142. //changeDirectory(unitDir);
  1143. //
  1144. //haxelibInstallGit("jgranick", "actuate");
  1145. //haxelibInstallGit("jgranick", "box2d");
  1146. //haxelibInstallGit("jgranick", "layout");
  1147. //haxelibInstallGit("openfl", "swf");
  1148. //haxelibInstallGit("openfl", "openfl-samples");
  1149. //
  1150. //var path = getHaxelibPath("openfl-samples");
  1151. //var old = Sys.getEnv("pwd");
  1152. //Sys.putEnv("pwd", path);
  1153. //parseTravisFile(haxe.io.Path.join([path, ".travis.yml"]), true);
  1154. //if (old != null) {
  1155. //Sys.putEnv("pwd", old);
  1156. //}
  1157. //}
  1158. static function testFlixelDemos() {
  1159. infoMsg("Test Flixel Demos:");
  1160. changeDirectory(unitDir);
  1161. getOpenFLDependencies();
  1162. haxelibInstall("systools");
  1163. haxelibInstall("spinehx");
  1164. haxelibInstall("nape");
  1165. haxelibInstall("task");
  1166. haxelibInstallGit("larsiusprime", "firetongue");
  1167. haxelibInstallGit("YellowAfterLife", "openfl-bitfive");
  1168. haxelibInstallGit("HaxeFlixel", "flixel");
  1169. haxelibInstallGit("HaxeFlixel", "flixel-addons");
  1170. haxelibInstallGit("HaxeFlixel", "flixel-ui");
  1171. haxelibInstallGit("HaxeFlixel", "flixel-demos");
  1172. haxelibInstallGit("HaxeFlixel", "flixel-tools");
  1173. haxelibRun(["flixel-tools", "testdemos", "-flash"]);
  1174. haxelibRun(["flixel-tools", "testdemos", "-neko"]);
  1175. haxelibRun(["flixel-tools", "testdemos", "-html5"]);
  1176. }
  1177. }