RunCi.hx 40 KB

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