RunCi.hx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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 Php = "php";
  19. var Cpp = "cpp";
  20. var Flash9 = "flash9";
  21. var As3 = "as3";
  22. var Java = "java";
  23. var Cs = "cs";
  24. var Python = "python";
  25. var ThirdParty = "third-party";
  26. }
  27. enum Ci {
  28. TravisCI;
  29. AppVeyor;
  30. }
  31. /**
  32. Will be run by CI services, currently TravisCI and AppVeyor.
  33. TravisCI:
  34. Setting file: ".travis.yml".
  35. Build result: https://travis-ci.org/HaxeFoundation/haxe
  36. AppVeyor:
  37. Setting file: "appveyor.yml".
  38. Build result: https://ci.appveyor.com/project/HaxeFoundation/haxe
  39. */
  40. class RunCi {
  41. static function successMsg(msg:String):Void {
  42. Sys.println('\x1b[32m' + msg + '\x1b[0m');
  43. }
  44. static function failMsg(msg:String):Void {
  45. Sys.println('\x1b[31m' + msg + '\x1b[0m');
  46. }
  47. static function infoMsg(msg:String):Void {
  48. Sys.println('\x1b[36m' + msg + '\x1b[0m');
  49. }
  50. /**
  51. Run a command using `Sys.command()`.
  52. If the command exits with non-zero code, exit the whole script with the same code.
  53. If `useRetry` is `true`, the command will be re-run if it exits with non-zero code (3 trials).
  54. It is useful for running network-dependent commands.
  55. */
  56. static function runCommand(cmd:String, args:Array<String>, useRetry:Bool = false):Void {
  57. var trials = useRetry ? 3 : 1;
  58. var exitCode:Int = 1;
  59. while (trials-->0) {
  60. Sys.println('Command: $cmd $args');
  61. var t = Timer.stamp();
  62. exitCode = Sys.command(cmd, args);
  63. var dt = Math.round(Timer.stamp() - t);
  64. if (exitCode == 0)
  65. successMsg('Command exited with $exitCode in ${dt}s: $cmd $args');
  66. else
  67. failMsg('Command exited with $exitCode in ${dt}s: $cmd $args');
  68. if (exitCode == 0) {
  69. return;
  70. } else if (trials > 0) {
  71. Sys.println('Command will be re-run...');
  72. }
  73. }
  74. Sys.exit(exitCode);
  75. }
  76. static function isAptPackageInstalled(aptPackage:String):Bool {
  77. return commandSucceed("dpkg-query", ["-W", "-f='${Status}'", aptPackage]);
  78. }
  79. static function requireAptPackages(packages:Array<String>):Void {
  80. var notYetInstalled = [for (p in packages) if (!isAptPackageInstalled(p)) p];
  81. if (notYetInstalled.length > 0)
  82. runCommand("sudo", ["apt-get", "install", "-y"].concat(notYetInstalled), true);
  83. }
  84. static function haxelibInstallGit(account:String, repository:String, ?branch:String, ?srcPath:String, useRetry:Bool = false, ?altName:String):Void {
  85. var name:String = (altName == null) ? repository : altName;
  86. try {
  87. getHaxelibPath(name);
  88. infoMsg('$name has already been installed.');
  89. } catch (e:Dynamic) {
  90. var args:Array<String> = ["git", name, 'https://github.com/$account/$repository'];
  91. if (branch != null) {
  92. args.push(branch);
  93. }
  94. if (srcPath != null) {
  95. args.push(srcPath);
  96. }
  97. runCommand("haxelib", args, useRetry);
  98. }
  99. }
  100. static function haxelibInstall(library:String):Void {
  101. try {
  102. getHaxelibPath(library);
  103. infoMsg('$library has already been installed.');
  104. } catch (e:Dynamic) {
  105. runCommand("haxelib", ["install", library]);
  106. }
  107. }
  108. static function haxelibRun(args:Array<String>, useRetry:Bool = false):Void {
  109. runCommand("haxelib", ["run"].concat(args), useRetry);
  110. }
  111. static function getHaxelibPath(libName:String) {
  112. var proc = new Process("haxelib", ["path", libName]);
  113. var result;
  114. var code = proc.exitCode();
  115. do {
  116. result = proc.stdout.readLine();
  117. if (!result.startsWith("-L")) {
  118. break;
  119. }
  120. } while(true);
  121. proc.close();
  122. if (code != 0) {
  123. throw 'Failed to get haxelib path ($result)';
  124. }
  125. return result;
  126. }
  127. static function changeDirectory(path:String) {
  128. Sys.println('Changing directory to $path');
  129. Sys.setCwd(path);
  130. }
  131. static function setupFlashPlayerDebugger():Void {
  132. var mmcfgPath = switch (systemName) {
  133. case "Linux":
  134. Sys.getEnv("HOME") + "/mm.cfg";
  135. case "Mac":
  136. "/Library/Application Support/Macromedia/mm.cfg";
  137. case _:
  138. throw "unsupported system";
  139. }
  140. switch (systemName) {
  141. case "Linux":
  142. Sys.putEnv("DISPLAY", ":99.0");
  143. runCommand("sh", ["-e", "/etc/init.d/xvfb", "start"]);
  144. Sys.putEnv("AUDIODEV", "null");
  145. requireAptPackages(["libgd2-xpm", "ia32-libs", "ia32-libs-multiarch"]);
  146. runCommand("wget", ["-nv", "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz"], true);
  147. runCommand("tar", ["-xf", "flashplayer_11_sa_debug.i386.tar.gz", "-C", Sys.getEnv("HOME")]);
  148. File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
  149. runCommand(Sys.getEnv("HOME") + "/flashplayerdebugger", ["-v"]);
  150. case "Mac":
  151. runCommand("brew", ["cask", "install", "flash-player-debugger"]);
  152. var dir = Path.directory(mmcfgPath);
  153. runCommand("sudo", ["mkdir", "-p", dir]);
  154. runCommand("sudo", ["chmod", "a+w", dir]);
  155. File.saveContent(mmcfgPath, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
  156. }
  157. }
  158. static function runFlash(swf:String):Void {
  159. swf = FileSystem.fullPath(swf);
  160. Sys.println('going to run $swf');
  161. switch (systemName) {
  162. case "Linux":
  163. new Process(Sys.getEnv("HOME") + "/flashplayerdebugger", [swf]);
  164. case "Mac":
  165. Sys.command("open", ["-a", Sys.getEnv("HOME") + "/Applications/Flash Player Debugger.app", swf]);
  166. }
  167. //wait a little until flashlog.txt is created
  168. var flashlogPath = switch (systemName) {
  169. case "Linux":
  170. Sys.getEnv("HOME") + "/.macromedia/Flash_Player/Logs/flashlog.txt";
  171. case "Mac":
  172. Sys.getEnv("HOME") + "/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
  173. case _:
  174. throw "unsupported system";
  175. }
  176. for (t in 0...5) {
  177. runCommand("sleep", ["2"]);
  178. if (FileSystem.exists(flashlogPath))
  179. break;
  180. }
  181. if (!FileSystem.exists(flashlogPath)) {
  182. failMsg('$flashlogPath not found.');
  183. Sys.exit(1);
  184. }
  185. //read flashlog.txt continously
  186. var traceProcess = new Process("tail", ["-f", flashlogPath]);
  187. var line = "";
  188. while (true) {
  189. try {
  190. line = traceProcess.stdout.readLine();
  191. Sys.println(line);
  192. if (line.indexOf("SUCCESS: ") >= 0) {
  193. Sys.exit(line.indexOf("SUCCESS: true") >= 0 ? 0 : 1);
  194. }
  195. } catch (e:haxe.io.Eof) {}
  196. }
  197. Sys.exit(1);
  198. }
  199. static function runCs(exe:String, ?args:Array<String>):Void {
  200. if (args == null) args = [];
  201. exe = FileSystem.fullPath(exe);
  202. switch (systemName) {
  203. case "Linux", "Mac":
  204. runCommand("mono", [exe].concat(args));
  205. case "Windows":
  206. runCommand(exe, args);
  207. }
  208. }
  209. static function runCpp(bin:String, ?args:Array<String>):Void {
  210. if (args == null) args = [];
  211. bin = FileSystem.fullPath(bin);
  212. runCommand(bin, args);
  213. }
  214. static function parseCommand(cmd:String) {
  215. var args = [];
  216. var offset = 0;
  217. var cur = new StringBuf();
  218. var inString = false;
  219. while(true) {
  220. switch(cmd.fastCodeAt(offset++)) {
  221. case '"'.code:
  222. inString = !inString;
  223. case ' '.code if (!inString):
  224. if (cur.length > 0) {
  225. args.push(cur.toString());
  226. cur = new StringBuf();
  227. }
  228. case '\\'.code:
  229. cur.addChar(cmd.fastCodeAt(offset++));
  230. case "$".code:
  231. switch (cmd.fastCodeAt(offset)) {
  232. case '('.code:
  233. ++offset;
  234. var env = new StringBuf();
  235. while(true) {
  236. switch(cmd.fastCodeAt(offset++)) {
  237. case ')'.code:
  238. break;
  239. case c:
  240. env.addChar(c);
  241. }
  242. }
  243. cur.add(Sys.getEnv(env.toString()));
  244. case _:
  245. cur.addChar("$".code);
  246. }
  247. case c:
  248. cur.addChar(c);
  249. }
  250. if (offset == cmd.length) {
  251. break;
  252. }
  253. }
  254. if (cur.length > 0) {
  255. args.push(cur.toString());
  256. }
  257. return args;
  258. }
  259. //static function parseTravisFile(path:String, ignoreBeforeInstall = false) {
  260. //var yaml:TravisConfig = yaml.Yaml.read(path, Parser.options().useObjects());
  261. //if (!ignoreBeforeInstall) {
  262. //for (code in yaml.before_install) {
  263. //var args = parseCommand(code);
  264. //var cmd = args.shift();
  265. //runCommand(cmd, args);
  266. //}
  267. //}
  268. //for (code in yaml.script) {
  269. //var args = parseCommand(code);
  270. //var cmd = args.shift();
  271. //runCommand(cmd, args);
  272. //}
  273. //}
  274. static function commandSucceed(cmd:String, args:Array<String>):Bool {
  275. return try {
  276. var p = new Process(cmd, args);
  277. var succeed = p.exitCode() == 0;
  278. p.close();
  279. succeed;
  280. } catch(e:Dynamic) false;
  281. }
  282. static function commandResult(cmd:String, args:Array<String>):{
  283. stdout:String,
  284. stderr:String,
  285. exitCode:Int
  286. } {
  287. var p = new Process(cmd, args);
  288. var out = {
  289. stdout: p.stdout.readAll().toString(),
  290. stderr: p.stderr.readAll().toString(),
  291. exitCode: p.exitCode()
  292. }
  293. p.close();
  294. return out;
  295. }
  296. static function addToPATH(path:String):Void {
  297. switch (systemName) {
  298. case "Windows":
  299. Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + path);
  300. case "Mac", "Linux":
  301. Sys.putEnv("PATH", Sys.getEnv("PATH") + ":" + path);
  302. }
  303. }
  304. static function getPhpDependencies() {
  305. switch (systemName) {
  306. case "Linux":
  307. if (commandSucceed("php", ["-v"])) {
  308. infoMsg('php has already been installed.');
  309. } else {
  310. requireAptPackages(["php5-cli", "php5-mysql", "php5-sqlite"]);
  311. }
  312. case "Mac":
  313. //pass
  314. case "Windows":
  315. if (commandSucceed("php", ["-v"])) {
  316. infoMsg('php has already been installed.');
  317. } else {
  318. runCommand("cinst", ["php", "-version", "5.6.3", "-y"], true);
  319. addToPATH("C:\\tools\\php");
  320. }
  321. }
  322. runCommand("php", ["-v"]);
  323. }
  324. static var gotCppDependencies = false;
  325. static function getCppDependencies() {
  326. if (gotCppDependencies) return;
  327. //hxcpp dependencies
  328. switch (systemName) {
  329. case "Linux":
  330. requireAptPackages(["gcc-multilib", "g++-multilib"]);
  331. case "Mac":
  332. //pass
  333. }
  334. //install and build hxcpp
  335. try {
  336. getHaxelibPath("hxcpp");
  337. infoMsg('hxcpp has already been installed.');
  338. } catch(e:Dynamic) {
  339. haxelibInstallGit("HaxeFoundation", "hxcpp", true);
  340. var oldDir = Sys.getCwd();
  341. changeDirectory(getHaxelibPath("hxcpp") + "tools/hxcpp/");
  342. runCommand("haxe", ["compile.hxml"]);
  343. changeDirectory(getHaxelibPath("hxcpp") + "project/");
  344. switch (ci) {
  345. case AppVeyor:
  346. runCommand("neko", ["build.n", "windows-m32"]);
  347. case _:
  348. runCommand("neko", ["build.n"]);
  349. }
  350. changeDirectory(oldDir);
  351. }
  352. gotCppDependencies = true;
  353. }
  354. static function getJavaDependencies() {
  355. haxelibInstallGit("HaxeFoundation", "hxjava", true);
  356. runCommand("javac", ["-version"]);
  357. }
  358. static function getJSDependencies() {
  359. switch (systemName) {
  360. case "Linux":
  361. if (commandSucceed("node", ["-v"])) {
  362. infoMsg('node has already been installed.');
  363. } else {
  364. requireAptPackages(["nodejs"]);
  365. }
  366. case "Mac":
  367. //pass
  368. }
  369. runCommand("node", ["-v"]);
  370. }
  371. static function getCsDependencies() {
  372. switch (systemName) {
  373. case "Linux":
  374. if (commandSucceed("mono", ["--version"]))
  375. infoMsg('mono has already been installed.');
  376. else
  377. requireAptPackages(["mono-devel", "mono-mcs"]);
  378. runCommand("mono", ["--version"]);
  379. case "Mac":
  380. if (commandSucceed("mono", ["--version"]))
  381. infoMsg('mono has already been installed.');
  382. else
  383. runCommand("brew", ["install", "mono"], true);
  384. runCommand("mono", ["--version"]);
  385. case "Windows":
  386. //pass
  387. }
  388. haxelibInstallGit("HaxeFoundation", "hxcs", true);
  389. }
  390. static var gotOpenFLDependencies = false;
  391. static function getOpenFLDependencies() {
  392. if (gotOpenFLDependencies) return;
  393. getCppDependencies();
  394. haxelibInstallGit("HaxeFoundation", "format");
  395. haxelibInstallGit("haxenme", "nme");
  396. haxelibInstallGit("haxenme", "nme-dev");
  397. haxelibInstallGit("openfl", "svg");
  398. haxelibInstallGit("openfl", "lime");
  399. haxelibInstallGit("openfl", "lime-tools");
  400. haxelibInstallGit("openfl", "openfl-native");
  401. haxelibInstallGit("openfl", "openfl-html5");
  402. haxelibInstallGit("openfl", "openfl");
  403. switch (systemName) {
  404. case "Linux":
  405. haxelibRun(["openfl", "rebuild", "linux"]);
  406. case "Mac":
  407. haxelibRun(["openfl", "rebuild", "mac"]);
  408. }
  409. haxelibRun(["openfl", "rebuild", "tools"]);
  410. gotOpenFLDependencies = true;
  411. }
  412. /**
  413. Install python and return the names of the installed pythons.
  414. */
  415. static function getPythonDependencies():Array<String> {
  416. switch (systemName) {
  417. case "Linux":
  418. if (commandSucceed("python3", ["-V"]))
  419. infoMsg('python3 has already been installed.');
  420. else
  421. requireAptPackages(["python3"]);
  422. runCommand("python3", ["-V"]);
  423. var pypy = "pypy3";
  424. if (commandSucceed(pypy, ["-V"])) {
  425. infoMsg('pypy3 has already been installed.');
  426. } else {
  427. var pypyVersion = "pypy3-2.4.0-linux64";
  428. runCommand("wget", ['https://bitbucket.org/pypy/pypy/downloads/${pypyVersion}.tar.bz2'], true);
  429. runCommand("tar", ["-xf", '${pypyVersion}.tar.bz2']);
  430. pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
  431. }
  432. runCommand(pypy, ["-V"]);
  433. return ["python3", pypy];
  434. case "Mac":
  435. if (commandSucceed("python3", ["-V"]))
  436. infoMsg('python3 has already been installed.');
  437. else
  438. runCommand("brew", ["install", "python3"], true);
  439. runCommand("python3", ["-V"]);
  440. if (commandSucceed("pypy3", ["-V"]))
  441. infoMsg('pypy3 has already been installed.');
  442. else
  443. runCommand("brew", ["install", "pypy3"], true);
  444. runCommand("pypy3", ["-V"]);
  445. return ["python3", "pypy3"];
  446. case "Windows":
  447. if (commandSucceed("python3", ["-V"]))
  448. infoMsg('python3 has already been installed.');
  449. else
  450. throw "please install python 3.x and make it available as python3 in PATH";
  451. runCommand("python3", ["-V"]);
  452. return ["python3"];
  453. }
  454. return [];
  455. }
  456. static var ci(default, never):Null<Ci> =
  457. if (Sys.getEnv("TRAVIS") == "true")
  458. TravisCI;
  459. else if (Sys.getEnv("APPVEYOR") == "True")
  460. AppVeyor;
  461. else
  462. null;
  463. static var systemName(default, never) = Sys.systemName();
  464. static var cwd(default, never) = Sys.getCwd();
  465. static var repoDir(default, never) = FileSystem.fullPath("..") + "/";
  466. static var unitDir(default, never) = cwd + "unit/";
  467. static var sysDir(default, never) = cwd + "sys/";
  468. static var optDir(default, never) = cwd + "optimization/";
  469. static var miscDir(default, never) = cwd + "misc/";
  470. static var gitInfo(default, never) = {
  471. repo: switch (ci) {
  472. case TravisCI:
  473. Sys.getEnv("TRAVIS_REPO_SLUG");
  474. case AppVeyor:
  475. Sys.getEnv("APPVEYOR_PROJECT_SLUG");
  476. case _:
  477. commandResult("git", ["config", "--get", "remote.origin.url"]).stdout.trim();
  478. },
  479. branch: switch (ci) {
  480. case TravisCI:
  481. Sys.getEnv("TRAVIS_BRANCH");
  482. case AppVeyor:
  483. Sys.getEnv("APPVEYOR_REPO_BRANCH");
  484. case _:
  485. commandResult("git", ["rev-parse", "--abbrev-ref", "HEAD"]).stdout.trim();
  486. },
  487. commit: commandResult("git", ["rev-parse", "HEAD"]).stdout.trim(),
  488. date: {
  489. var gitTime = commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout;
  490. var tzd = {
  491. var z = Date.fromTime(0);
  492. z.getHours() * 60 * 60 * 1000 + z.getMinutes() * 60 * 1000;
  493. }
  494. var time = Date.fromTime(Std.parseFloat(gitTime) * 1000 - tzd);
  495. DateTools.format(time, "%FT%TZ");
  496. }
  497. }
  498. static var haxeVer(default, never) = {
  499. var haxe_ver = haxe.macro.Compiler.getDefine("haxe_ver");
  500. switch (haxe_ver.split(".")) {
  501. case [major]:
  502. major;
  503. case [major, minor] if (minor.length == 1):
  504. '${major}.${minor}';
  505. case [major, minor] if (minor.length > 1):
  506. var minor = minor.charAt(0);
  507. var patch = Std.parseInt(minor.substr(1));
  508. '${major}.${minor}.${patch}';
  509. case _:
  510. throw haxe_ver;
  511. }
  512. }
  513. static function bintray():Void {
  514. if (
  515. Sys.getEnv("BINTRAY") != null &&
  516. Sys.getEnv("BINTRAY_USERNAME") != null &&
  517. Sys.getEnv("BINTRAY_API_KEY") != null
  518. ) {
  519. // generate bintray config
  520. var tpl = new Template(File.getContent("../extra/bintray.tpl.json"));
  521. var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
  522. var json = tpl.execute({
  523. os: systemName.toLowerCase(),
  524. versionName: '${haxeVer}+${compatDate}.${gitInfo.commit.substr(0,7)}',
  525. versionDesc: "Automated CI build.",
  526. gitRepo: gitInfo.repo,
  527. gitBranch: gitInfo.branch,
  528. gitCommit: gitInfo.commit,
  529. gitDate: gitInfo.date,
  530. });
  531. var path = "../extra/bintray.json";
  532. File.saveContent("../extra/bintray.json", json);
  533. infoMsg("saved " + FileSystem.absolutePath(path) + " with content:");
  534. Sys.println(json);
  535. }
  536. }
  537. static function main():Void {
  538. Sys.putEnv("OCAMLRUNPARAM", "b");
  539. bintray();
  540. var tests:Array<TEST> = switch (Sys.getEnv("TEST")) {
  541. case null:
  542. [Macro];
  543. case env:
  544. [for (v in env.split(",")) v.trim().toLowerCase()];
  545. }
  546. Sys.println('Going to test: $tests');
  547. for (test in tests) {
  548. infoMsg('Now test $test');
  549. changeDirectory(unitDir);
  550. switch (test) {
  551. case Macro:
  552. runCommand("haxe", ["compile-macro.hxml"]);
  553. changeDirectory(miscDir);
  554. getCsDependencies();
  555. getPythonDependencies();
  556. runCommand("haxe", ["compile.hxml"]);
  557. switch (ci) {
  558. case AppVeyor:
  559. //save time...
  560. case _:
  561. //generate documentation
  562. haxelibInstallGit("Simn", "hxparse", "development", "src", true);
  563. haxelibInstallGit("Simn", "hxtemplo", true);
  564. haxelibInstallGit("Simn", "hxargs", true);
  565. haxelibInstallGit("dpeek", "haxe-markdown", "master", "src", true, "markdown");
  566. haxelibInstallGit("HaxeFoundation", "hxcpp", true);
  567. haxelibInstallGit("HaxeFoundation", "hxjava", true);
  568. haxelibInstallGit("HaxeFoundation", "hxcs", true);
  569. haxelibInstallGit("dpeek", "dox", true);
  570. changeDirectory(getHaxelibPath("dox"));
  571. runCommand("haxe", ["run.hxml"]);
  572. runCommand("haxe", ["gen.hxml"]);
  573. haxelibRun(["dox", "-o", "bin/api.zip", "-i", "bin/xml"]);
  574. }
  575. changeDirectory(sysDir);
  576. runCommand("haxe", ["compile-macro.hxml"]);
  577. runCommand("haxe", ["compile-each.hxml", "--run", "Main"]);
  578. //BYTECODE
  579. switch (ci) {
  580. case null:
  581. //pass
  582. case TravisCI:
  583. changeDirectory(repoDir);
  584. runCommand("make", ["BYTECODE=1", "-s"]);
  585. // runCommand("sudo", ["make", "install", "-s"]);
  586. changeDirectory(unitDir);
  587. runCommand("haxe", ["compile-macro.hxml"]);
  588. case AppVeyor:
  589. // save time...
  590. // changeDirectory(repoDir);
  591. // runCommand(Sys.getEnv("CYG_ROOT") + "/bin/bash", ["-lc", 'cd \"$$OLDPWD\" && make -s -f Makefile.win BYTECODE=1']);
  592. // changeDirectory(unitDir);
  593. // runCommand("haxe", ["compile-macro.hxml"]);
  594. }
  595. case Neko:
  596. runCommand("haxe", ["compile-neko.hxml"]);
  597. runCommand("neko", ["bin/unit.n"]);
  598. changeDirectory(sysDir);
  599. runCommand("haxe", ["compile-neko.hxml"]);
  600. runCommand("neko", ["bin/neko/sys.n"]);
  601. case Php:
  602. getPhpDependencies();
  603. var args = switch (ci) {
  604. case TravisCI:
  605. ["-D","travis"];
  606. case _:
  607. [];
  608. }
  609. runCommand("haxe", ["compile-php.hxml"].concat(args));
  610. runCommand("php", ["bin/php/index.php"]);
  611. changeDirectory(sysDir);
  612. runCommand("haxe", ["compile-php.hxml"]);
  613. runCommand("php", ["bin/php/Main/index.php"]);
  614. case Python:
  615. var pys = getPythonDependencies();
  616. runCommand("haxe", ["compile-python.hxml"]);
  617. for (py in pys) {
  618. runCommand(py, ["bin/unit.py"]);
  619. }
  620. changeDirectory(sysDir);
  621. runCommand("haxe", ["compile-python.hxml"]);
  622. for (py in pys) {
  623. runCommand(py, ["bin/python/sys.py"]);
  624. }
  625. changeDirectory(miscDir + "pythonImport");
  626. runCommand("haxe", ["compile.hxml"]);
  627. for (py in pys) {
  628. runCommand(py, ["test.py"]);
  629. }
  630. case Cpp:
  631. getCppDependencies();
  632. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M32"]);
  633. runCpp("bin/cpp/Test-debug", []);
  634. switch (ci) {
  635. case AppVeyor:
  636. //save time...
  637. case _:
  638. runCommand("rm", ["-rf", "cpp"]);
  639. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"]);
  640. runCpp("bin/cpp/Test-debug", []);
  641. }
  642. changeDirectory(sysDir);
  643. runCommand("haxe", ["compile-cpp.hxml"]);
  644. runCpp("bin/cpp/Main-debug", []);
  645. if (Sys.systemName() == "Mac")
  646. {
  647. changeDirectory(miscDir + "cppObjc");
  648. runCommand("haxe", ["build.hxml"]);
  649. runCpp("bin/TestObjc-debug");
  650. }
  651. case Js:
  652. getJSDependencies();
  653. var jsOutputs = [
  654. for (es5 in [[], ["-D", "js-es5"]])
  655. for (unflatten in [[], ["-D", "js-unflatten"]])
  656. for (classic in [[], ["-D", "js-classic"]])
  657. {
  658. var extras = [].concat(es5).concat(unflatten).concat(classic);
  659. runCommand("haxe", ["compile-js.hxml"].concat(extras));
  660. var output = if (extras.length > 0) {
  661. "bin/js/" + extras.join("") + "/unit.js";
  662. } else {
  663. "bin/js/default/unit.js";
  664. }
  665. var outputDir = Path.directory(output);
  666. if (!FileSystem.exists(outputDir)) {
  667. FileSystem.createDirectory(outputDir);
  668. }
  669. FileSystem.rename("bin/unit.js", output);
  670. FileSystem.rename("bin/unit.js.map", output + ".map");
  671. runCommand("node", ["-e", "var unit = require('./" + output + "').unit; unit.Test.main(); process.exit(unit.Test.success ? 0 : 1);"]);
  672. output;
  673. }
  674. ];
  675. var env = Sys.environment();
  676. if (
  677. env.exists("SAUCE_USERNAME") && env.exists("SAUCE_ACCESS_KEY") &&
  678. // only run on Linux build
  679. (ci != null ? systemName == "Linux" : true)
  680. ) {
  681. // sauce-connect should have been started
  682. // var scVersion = "sc-4.3-linux";
  683. // runCommand("wget", ['https://saucelabs.com/downloads/${scVersion}.tar.gz'], true);
  684. // runCommand("tar", ["-xf", '${scVersion}.tar.gz']);
  685. // //start sauce-connect
  686. // var scReadyFile = "sauce-connect-ready-" + Std.random(100);
  687. // var sc = new Process('${scVersion}/bin/sc', [
  688. // "-i", Sys.getEnv("TRAVIS_JOB_NUMBER"),
  689. // "-f", scReadyFile
  690. // ]);
  691. // while(!FileSystem.exists(scReadyFile)) {
  692. // Sys.sleep(0.5);
  693. // }
  694. runCommand("npm", ["install", "wd", "q"], true);
  695. haxelibInstallGit("dionjwa", "nodejs-std", "master", null, true, "nodejs");
  696. runCommand("haxe", ["compile-saucelabs-runner.hxml"]);
  697. var server = new Process("nekotools", ["server"]);
  698. runCommand("node", ["bin/RunSauceLabs.js"].concat([for (js in jsOutputs) "unit-js.html?js=" + js.urlEncode()]));
  699. server.close();
  700. // sc.close();
  701. }
  702. infoMsg("Test optimization:");
  703. changeDirectory(optDir);
  704. runCommand("haxe", ["run.hxml"]);
  705. case Java:
  706. getJavaDependencies();
  707. runCommand("haxe", ["compile-java.hxml"]);
  708. runCommand("java", ["-jar", "bin/java/Test-Debug.jar"]);
  709. runCommand("haxe", ["compile-java.hxml","-dce","no"]);
  710. runCommand("java", ["-jar", "bin/java/Test-Debug.jar"]);
  711. changeDirectory(sysDir);
  712. runCommand("haxe", ["compile-java.hxml"]);
  713. runCommand("java", ["-jar", "bin/java/Main-Debug.jar"]);
  714. infoMsg("Testing java-lib extras");
  715. changeDirectory('$unitDir/bin');
  716. runCommand("git", ["clone", "https://github.com/waneck/java-lib-tests.git", "--depth", "1"], true);
  717. for (dir in FileSystem.readDirectory('java-lib-tests'))
  718. {
  719. var path = 'java-lib-tests/$dir';
  720. if (FileSystem.isDirectory(path)) for (file in FileSystem.readDirectory(path))
  721. {
  722. if (file.endsWith('.hxml'))
  723. {
  724. runCommand("haxe", ["--cwd",'java-lib-tests/$dir',file]);
  725. }
  726. }
  727. }
  728. case Cs:
  729. getCsDependencies();
  730. var compl = switch [ci, systemName] {
  731. case [TravisCI, "Linux"]:
  732. "-travis";
  733. case _:
  734. "";
  735. };
  736. runCommand("haxe", ['compile-cs$compl.hxml']);
  737. runCs("bin/cs/bin/Test-Debug.exe");
  738. runCommand("haxe", ['compile-cs$compl.hxml','-dce','no']);
  739. runCs("bin/cs/bin/Test-Debug.exe");
  740. runCommand("haxe", ['compile-cs-unsafe$compl.hxml']);
  741. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  742. runCommand("haxe", ['compile-cs$compl.hxml',"-D","erase_generics"]);
  743. runCs("bin/cs/bin/Test-Debug.exe");
  744. runCommand("haxe", ['compile-cs-unsafe$compl.hxml',"-D","erase_generics"]);
  745. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  746. runCommand("haxe", ['compile-cs$compl.hxml',"-D","no_root"]);
  747. runCs("bin/cs/bin/Test-Debug.exe");
  748. runCommand("haxe", ['compile-cs-unsafe$compl.hxml',"-D","no_root","-D","erase_generics"]);
  749. runCs("bin/cs_unsafe/bin/Test-Debug.exe");
  750. changeDirectory(sysDir);
  751. runCommand("haxe", ["compile-cs.hxml"]);
  752. runCs("bin/cs/bin/Main-Debug.exe", []);
  753. changeDirectory(miscDir + "csTwoLibs");
  754. for (i in 1...5)
  755. {
  756. runCommand("haxe", ['compile-$i.hxml']);
  757. runCs("bin/main/bin/Main.exe");
  758. }
  759. case Flash9:
  760. setupFlashPlayerDebugger();
  761. runCommand("haxe", ["compile-flash9.hxml", "-D", "fdb"]);
  762. runFlash("bin/unit9.swf");
  763. case As3:
  764. setupFlashPlayerDebugger();
  765. //setup flex sdk
  766. if (commandSucceed("mxmlc", ["--version"])) {
  767. infoMsg('mxmlc has already been installed.');
  768. } else {
  769. var flexVersion = "4.14.0";
  770. runCommand("wget", ['http://archive.apache.org/dist/flex/${flexVersion}/binaries/apache-flex-sdk-${flexVersion}-bin.tar.gz'], true);
  771. runCommand("tar", ["-xf", 'apache-flex-sdk-${flexVersion}-bin.tar.gz', "-C", Sys.getEnv("HOME")]);
  772. var flexsdkPath = Sys.getEnv("HOME") + '/apache-flex-sdk-${flexVersion}-bin';
  773. addToPATH(flexsdkPath + "/bin");
  774. var playerglobalswcFolder = flexsdkPath + "/player";
  775. FileSystem.createDirectory(playerglobalswcFolder + "/11.1");
  776. runCommand("wget", ["-nv", "http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc", "-O", playerglobalswcFolder + "/11.1/playerglobal.swc"], true);
  777. File.saveContent(flexsdkPath + "/env.properties", 'env.PLAYERGLOBAL_HOME=$playerglobalswcFolder');
  778. runCommand("mxmlc", ["--version"]);
  779. }
  780. runCommand("haxe", ["compile-as3.hxml", "-D", "fdb"]);
  781. runFlash("bin/unit9_as3.swf");
  782. case ThirdParty:
  783. getPhpDependencies();
  784. getJavaDependencies();
  785. getJSDependencies();
  786. getCsDependencies();
  787. getPythonDependencies();
  788. getCppDependencies();
  789. //getOpenFLDependencies();
  790. //testPolygonalDs();
  791. // if (systemName == "Linux") testFlambe(); //#3439
  792. testHxTemplo();
  793. testMUnit();
  794. //testOpenflSamples();
  795. //testFlixelDemos();
  796. case t:
  797. throw "unknown target: " + t;
  798. }
  799. }
  800. }
  801. static function testHxTemplo() {
  802. infoMsg("Test hx-templo:");
  803. changeDirectory(unitDir);
  804. haxelibInstallGit("Simn", "hxparse", "development", "src");
  805. haxelibInstallGit("Simn", "hxtemplo");
  806. var buildArgs = [
  807. "-cp", "src",
  808. "-cp", "test",
  809. "-main", "Test",
  810. "-lib", "hxparse",
  811. "-dce", "full"
  812. ];
  813. changeDirectory(getHaxelibPath("hxtemplo") + "..");
  814. runCommand("haxe", ["build.hxml"]);
  815. }
  816. static function testPolygonalDs() {
  817. infoMsg("Test polygonal-ds:");
  818. changeDirectory(unitDir);
  819. haxelibInstallGit("Simn", "ds", "python-support", null, false, "polygonal-ds");
  820. haxelibInstallGit("polygonal", "core", "master", "src", false, "polygonal-core");
  821. haxelibInstallGit("polygonal", "printf", "master", "src", false, "polygonal-printf");
  822. changeDirectory(getHaxelibPath("polygonal-ds"));
  823. runCommand("haxe", ["build.hxml"]);
  824. runCommand("python3", ["unit.py"]);
  825. runCommand("node", ["unit.js"]);
  826. }
  827. static function testMUnit() {
  828. infoMsg("Test MUnit:");
  829. changeDirectory(unitDir);
  830. haxelibInstallGit("massiveinteractive", "mconsole", "master", "src");
  831. haxelibInstallGit("massiveinteractive", "MassiveCover", "master", "src", false, "mcover");
  832. haxelibInstallGit("massiveinteractive", "MassiveLib", "master", "src", false, "mlib");
  833. haxelibInstallGit("massiveinteractive", "MassiveUnit", "master", "src", false, "munit");
  834. changeDirectory(Path.join([getHaxelibPath("munit"), "..", "tool"]));
  835. runCommand("haxe", ["build.hxml"]);
  836. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  837. changeDirectory("../");
  838. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  839. }
  840. static function testFlambe() {
  841. infoMsg("Test Flambe:");
  842. changeDirectory(unitDir);
  843. runCommand("git", ["clone", "https://github.com/aduros/flambe"]);
  844. runCommand("sh", ["flambe/bin/run-travis"]);
  845. }
  846. //static function testOpenflSamples() {
  847. //infoMsg("Test OpenFL Samples:");
  848. //
  849. //changeDirectory(unitDir);
  850. //
  851. //haxelibInstallGit("jgranick", "actuate");
  852. //haxelibInstallGit("jgranick", "box2d");
  853. //haxelibInstallGit("jgranick", "layout");
  854. //haxelibInstallGit("openfl", "swf");
  855. //haxelibInstallGit("openfl", "openfl-samples");
  856. //
  857. //var path = getHaxelibPath("openfl-samples");
  858. //var old = Sys.getEnv("pwd");
  859. //Sys.putEnv("pwd", path);
  860. //parseTravisFile(haxe.io.Path.join([path, ".travis.yml"]), true);
  861. //if (old != null) {
  862. //Sys.putEnv("pwd", old);
  863. //}
  864. //}
  865. static function testFlixelDemos() {
  866. infoMsg("Test Flixel Demos:");
  867. changeDirectory(unitDir);
  868. getOpenFLDependencies();
  869. haxelibInstall("systools");
  870. haxelibInstall("spinehx");
  871. haxelibInstall("nape");
  872. haxelibInstall("task");
  873. haxelibInstallGit("larsiusprime", "firetongue");
  874. haxelibInstallGit("YellowAfterLife", "openfl-bitfive");
  875. haxelibInstallGit("HaxeFlixel", "flixel");
  876. haxelibInstallGit("HaxeFlixel", "flixel-addons");
  877. haxelibInstallGit("HaxeFlixel", "flixel-ui");
  878. haxelibInstallGit("HaxeFlixel", "flixel-demos");
  879. haxelibInstallGit("HaxeFlixel", "flixel-tools");
  880. haxelibRun(["flixel-tools", "testdemos", "-flash"]);
  881. haxelibRun(["flixel-tools", "testdemos", "-neko"]);
  882. haxelibRun(["flixel-tools", "testdemos", "-html5"]);
  883. }
  884. }