RunCi.hx 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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 deploy():Void {
  605. if (
  606. Sys.getEnv("DEPLOY") != null
  607. ) {
  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(doInstaller);
  633. }
  634. deployNightlies();
  635. }
  636. }
  637. }
  638. static function deployBintray():Void {
  639. if (
  640. Sys.getEnv("BINTRAY") != null &&
  641. Sys.getEnv("BINTRAY_USERNAME") != null &&
  642. Sys.getEnv("BINTRAY_API_KEY") != null
  643. ) {
  644. // generate bintray config
  645. var tpl = new Template(File.getContent("extra/bintray.tpl.json"));
  646. var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
  647. var json = tpl.execute({
  648. packageSubject: {
  649. var sub = Sys.getEnv("BINTRAY_SUBJECT");
  650. sub != null ? sub : Sys.getEnv("BINTRAY_USERNAME");
  651. },
  652. os: systemName.toLowerCase(),
  653. versionName: '${haxeVer}+${compatDate}.${gitInfo.commit.substr(0,7)}',
  654. versionDesc: "Automated CI build.",
  655. gitRepo: gitInfo.repo,
  656. gitBranch: gitInfo.branch,
  657. gitCommit: gitInfo.commit,
  658. gitDate: gitInfo.date,
  659. });
  660. var path = "extra/bintray.json";
  661. File.saveContent("extra/bintray.json", json);
  662. infoMsg("saved " + FileSystem.absolutePath(path) + " with content:");
  663. Sys.println(json);
  664. }
  665. }
  666. static function shouldDeployInstaller() {
  667. if (systemName == 'Linux') {
  668. return false;
  669. }
  670. if (gitInfo.branch == 'nightly-travis') {
  671. return true;
  672. }
  673. var rev = Sys.getEnv('ADD_REVISION');
  674. return rev != null && rev != "0";
  675. }
  676. static function isDeployApiDocsRequired () {
  677. return gitInfo.branch == "development" &&
  678. Sys.getEnv("DEPLOY_API_DOCS") != null &&
  679. Sys.getEnv("deploy_key_decrypt") != null;
  680. }
  681. /**
  682. Deploy doc to api.haxe.org.
  683. */
  684. static function deployApiDoc():Void {
  685. if (
  686. gitInfo.branch == "development" &&
  687. Sys.getEnv("DEPLOY") != null &&
  688. Sys.getEnv("deploy_key_decrypt") != null
  689. ) {
  690. // setup deploy_key
  691. runCommand("openssl aes-256-cbc -k \"$deploy_key_decrypt\" -in extra/deploy_key.enc -out extra/deploy_key -d");
  692. runCommand("chmod 600 extra/deploy_key");
  693. runCommand("ssh-add extra/deploy_key");
  694. runCommand("make", ["-s", "deploy_doc"]);
  695. }
  696. }
  697. /**
  698. Deploy source package to hxbuilds s3
  699. */
  700. static function deployNightlies(doInstaller:Bool):Void {
  701. var gitTime = commandResult("git", ["show", "-s", "--format=%ct", "HEAD"]).stdout;
  702. var tzd = {
  703. var z = Date.fromTime(0);
  704. z.getHours() * 60 * 60 * 1000 + z.getMinutes() * 60 * 1000;
  705. };
  706. var time = Date.fromTime(Std.parseFloat(gitTime) * 1000 - tzd);
  707. if (
  708. (gitInfo.branch == "development" ||
  709. gitInfo.branch == "master" ||
  710. gitInfo.branch == "three_four_three" ||
  711. gitInfo.branch == "nightly-travis") &&
  712. Sys.getEnv("HXBUILDS_AWS_ACCESS_KEY_ID") != null &&
  713. Sys.getEnv("HXBUILDS_AWS_SECRET_ACCESS_KEY") != null &&
  714. Sys.getEnv("TRAVIS_PULL_REQUEST") != "true"
  715. ) {
  716. if (ci == TravisCI) {
  717. runCommand("make", ["-s", "package_unix"]);
  718. if (doInstaller) {
  719. getLatestNeko();
  720. runCommand("make", ["-s", 'package_installer_mac']);
  721. }
  722. if (systemName == 'Linux') {
  723. // source
  724. for (file in sys.FileSystem.readDirectory('out')) {
  725. if (file.startsWith('haxe') && file.endsWith('_src.tar.gz')) {
  726. submitToS3("source", 'out/$file');
  727. break;
  728. }
  729. }
  730. }
  731. for (file in sys.FileSystem.readDirectory('out')) {
  732. if (file.startsWith('haxe')) {
  733. if (file.endsWith('_bin.tar.gz')) {
  734. var name = systemName == "Linux" ? 'linux64' : 'mac';
  735. submitToS3(name, 'out/$file');
  736. } else if (file.endsWith('_installer.tar.gz')) {
  737. submitToS3('mac-installer', 'out/$file');
  738. }
  739. }
  740. }
  741. } else {
  742. if (doInstaller) {
  743. getLatestNeko();
  744. var cygRoot = Sys.getEnv("CYG_ROOT");
  745. if (cygRoot != null) {
  746. runCommand('$cygRoot/bin/bash', ['-lc', "cd \"$OLDPWD\" && make -s -f Makefile.win package_installer_win"]);
  747. } else {
  748. runCommand("make", ['-f', 'Makefile.win', "-s", 'package_installer_win']);
  749. }
  750. }
  751. for (file in sys.FileSystem.readDirectory('out')) {
  752. if (file.startsWith('haxe')) {
  753. if (file.endsWith('_bin.zip')) {
  754. submitToS3('windows', 'out/$file');
  755. } else if (file.endsWith('_installer.zip')) {
  756. submitToS3('windows-installer', 'out/$file');
  757. }
  758. }
  759. }
  760. }
  761. } else {
  762. trace('Not deploying nightlies');
  763. }
  764. }
  765. static function getLatestNeko() {
  766. if (!FileSystem.exists('installer')) {
  767. FileSystem.createDirectory('installer');
  768. }
  769. var src = 'http://nekovm.org/media/neko-2.1.0-';
  770. var suffix = systemName == 'Windows' ? 'win.zip' : 'osx64.tar.gz';
  771. src += suffix;
  772. runCommand("wget", [src, '-O', 'installer/neko-$suffix'], true);
  773. }
  774. static function createNsiInstaller() {
  775. if (!FileSystem.exists('installer')) {
  776. FileSystem.createDirectory('installer');
  777. }
  778. getLatestNeko();
  779. }
  780. static function fileExtension(file:String) {
  781. file = haxe.io.Path.withoutDirectory(file);
  782. var idx = file.indexOf('.');
  783. if (idx < 0) {
  784. return '';
  785. } else {
  786. return file.substr(idx);
  787. }
  788. }
  789. static function submitToS3(kind:String, sourceFile:String) {
  790. var date = DateTools.format(Date.now(), '%Y-%m-%d');
  791. var ext = fileExtension(sourceFile);
  792. var fileName = 'haxe_${date}_${gitInfo.branch}_${gitInfo.commit.substr(0,7)}${ext}';
  793. var changeLatest = gitInfo.branch == "development";
  794. Sys.putEnv('AWS_ACCESS_KEY_ID', Sys.getEnv('HXBUILDS_AWS_ACCESS_KEY_ID'));
  795. Sys.putEnv('AWS_SECRET_ACCESS_KEY', Sys.getEnv('HXBUILDS_AWS_SECRET_ACCESS_KEY'));
  796. runCommand('aws s3 cp --region us-east-1 "$sourceFile" "$S3_HXBUILDS_ADDR/$kind/$fileName"');
  797. if (changeLatest) {
  798. runCommand('aws s3 cp --region us-east-1 "$sourceFile" "$S3_HXBUILDS_ADDR/$kind/haxe_latest$ext"');
  799. }
  800. Indexer.index('$S3_HXBUILDS_ADDR/$kind/');
  801. runCommand('aws s3 cp --region us-east-1 index.html "$S3_HXBUILDS_ADDR/$kind/index.html"');
  802. }
  803. /**
  804. Deploy source package to ppa:haxe/snapshots.
  805. */
  806. static function deployPPA():Void {
  807. if (
  808. gitInfo.branch == "development" &&
  809. Sys.getEnv("DEPLOY") != null &&
  810. Sys.getEnv("haxeci_decrypt") != null
  811. ) {
  812. // setup deb info
  813. runCommand("git config --global user.name \"${DEBFULLNAME}\"");
  814. runCommand("git config --global user.email \"${DEBEMAIL}\"");
  815. // setup haxeci_ssh
  816. runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_ssh.enc -out extra/haxeci_ssh -d");
  817. runCommand("chmod 600 extra/haxeci_ssh");
  818. runCommand("ssh-add extra/haxeci_ssh");
  819. // setup haxeci_sec.gpg
  820. runCommand("openssl aes-256-cbc -k \"$haxeci_decrypt\" -in extra/haxeci_sec.gpg.enc -out extra/haxeci_sec.gpg -d");
  821. runCommand("gpg --allow-secret-key-import --import extra/haxeci_sec.gpg");
  822. runCommand("sudo apt-get install devscripts git-buildpackage ubuntu-dev-tools dh-make -y");
  823. var compatDate = ~/[^0-9]/g.replace(gitInfo.date, "");
  824. var SNAPSHOT_VERSION = '${haxeVerFull}+1SNAPSHOT${compatDate}+${gitInfo.commit.substr(0,7)}';
  825. runCommand('cp out/haxe*_src.tar.gz "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz"');
  826. changeDirectory("..");
  827. runCommand("git clone https://github.com/HaxeFoundation/haxe-debian.git");
  828. changeDirectory("haxe-debian");
  829. runCommand("git checkout upstream");
  830. runCommand("git checkout next");
  831. runCommand('gbp import-orig "../haxe_${SNAPSHOT_VERSION}.orig.tar.gz" -u "${SNAPSHOT_VERSION}" --debian-branch=next');
  832. runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
  833. runCommand("debuild -S -sa");
  834. runCommand("backportpackage -d yakkety --upload ${PPA} --yes ../haxe_*.dsc");
  835. runCommand("backportpackage -d xenial --upload ${PPA} --yes ../haxe_*.dsc");
  836. runCommand("backportpackage -d wily --upload ${PPA} --yes ../haxe_*.dsc");
  837. runCommand("backportpackage -d vivid --upload ${PPA} --yes ../haxe_*.dsc");
  838. runCommand("backportpackage -d trusty --upload ${PPA} --yes ../haxe_*.dsc");
  839. runCommand("git checkout debian/changelog");
  840. runCommand("git merge -X ours --no-edit origin/next-precise");
  841. runCommand('dch -v "1:${SNAPSHOT_VERSION}-1" --urgency low "snapshot build"');
  842. runCommand("debuild -S -sa");
  843. runCommand("backportpackage -d precise --upload ${PPA} --yes ../haxe_*.dsc");
  844. }
  845. }
  846. static function main():Void {
  847. Sys.putEnv("OCAMLRUNPARAM", "b");
  848. var tests:Array<TEST> = switch (Sys.getEnv("TEST")) {
  849. case null:
  850. [Macro];
  851. case env:
  852. [for (v in env.split(",")) v.trim().toLowerCase()];
  853. }
  854. Sys.println('Going to test: $tests');
  855. for (test in tests) {
  856. switch (ci) {
  857. case TravisCI:
  858. Sys.println('travis_fold:start:test-${test}');
  859. case _:
  860. //pass
  861. }
  862. infoMsg('test $test');
  863. var success = true;
  864. try {
  865. changeDirectory(unitDir);
  866. var args = switch (ci) {
  867. case TravisCI:
  868. ["-D","travis"];
  869. case AppVeyor:
  870. ["-D","appveyor"];
  871. case _:
  872. [];
  873. }
  874. switch (test) {
  875. case Macro:
  876. runCommand("haxe", ["compile-macro.hxml"].concat(args));
  877. changeDirectory(displayDir);
  878. runCommand("haxe", ["build.hxml"]);
  879. changeDirectory(miscDir);
  880. getCsDependencies();
  881. getPythonDependencies();
  882. runCommand("haxe", ["compile.hxml"]);
  883. changeDirectory(sysDir);
  884. runCommand("haxe", ["compile-macro.hxml"]);
  885. runCommand("haxe", ["compile-each.hxml", "--run", "Main"]);
  886. case Neko:
  887. getSpodDependencies();
  888. runCommand("haxe", ["compile-neko.hxml", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
  889. runCommand("neko", ["bin/unit.n"]);
  890. changeDirectory(sysDir);
  891. runCommand("haxe", ["compile-neko.hxml"]);
  892. runCommand("neko", ["bin/neko/sys.n"]);
  893. case Php7:
  894. getSpodDependencies();
  895. runCommand("haxe", ["compile-php7.hxml"].concat(args));
  896. runCommand("php", ["bin/php7/index.php"]);
  897. changeDirectory(sysDir);
  898. runCommand("haxe", ["compile-php7.hxml"]);
  899. runCommand("php", ["bin/php7/Main/index.php"]);
  900. case Php:
  901. getSpodDependencies();
  902. getPhpDependencies();
  903. runCommand("haxe", ["compile-php.hxml"].concat(args));
  904. runCommand("php", ["bin/php/index.php"]);
  905. changeDirectory(sysDir);
  906. runCommand("haxe", ["compile-php.hxml"]);
  907. runCommand("php", ["bin/php/Main/index.php"]);
  908. case Python:
  909. var pys = getPythonDependencies();
  910. runCommand("haxe", ["compile-python.hxml"].concat(args));
  911. for (py in pys) {
  912. runCommand(py, ["bin/unit.py"]);
  913. }
  914. changeDirectory(sysDir);
  915. runCommand("haxe", ["compile-python.hxml"]);
  916. for (py in pys) {
  917. runCommand(py, ["bin/python/sys.py"]);
  918. }
  919. changeDirectory(miscDir + "pythonImport");
  920. runCommand("haxe", ["compile.hxml"]);
  921. for (py in pys) {
  922. runCommand(py, ["test.py"]);
  923. }
  924. case Lua:
  925. getLuaDependencies();
  926. var envpath = Sys.getEnv("HOME") + '/lua_env';
  927. addToPATH(envpath + '/bin');
  928. for (lv in ["-l5.1", "-l5.2", "-l5.3", "-j2.0", "-j2.1" ]){
  929. if (systemName == "Mac" && lv.startsWith("-j")) continue;
  930. Sys.println('--------------------');
  931. Sys.println('Lua Version: $lv');
  932. runCommand("hererocks", [envpath, lv, "-rlatest", "-i"]);
  933. trace('path: ' + Sys.getEnv("PATH"));
  934. runCommand("lua",["-v"]);
  935. runCommand("luarocks",[]);
  936. installLuaVersionDependencies(lv);
  937. changeDirectory(unitDir);
  938. runCommand("haxe", ["compile-lua.hxml"].concat(args));
  939. runCommand("lua", ["bin/unit.lua"]);
  940. changeDirectory(sysDir);
  941. runCommand("haxe", ["compile-lua.hxml"].concat(args));
  942. runCommand("lua", ["bin/lua/sys.lua"]);
  943. }
  944. case Cpp:
  945. getCppDependencies();
  946. getSpodDependencies();
  947. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M32"].concat(args));
  948. runCpp("bin/cpp/TestMain-debug", []);
  949. switch (ci) {
  950. case AppVeyor:
  951. //save time...
  952. case _:
  953. runCommand("rm", ["-rf", "cpp"]);
  954. runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"].concat(args));
  955. runCpp("bin/cpp/TestMain-debug", []);
  956. runCommand("haxe", ["compile-cppia-host.hxml"]);
  957. runCommand("haxe", ["compile-cppia.hxml"]);
  958. runCpp("bin/cppia/Host-debug", ["bin/unit.cppia"]);
  959. }
  960. changeDirectory(sysDir);
  961. runCommand("haxe", ["compile-cpp.hxml"]);
  962. runCpp("bin/cpp/Main-debug", []);
  963. // if (Sys.systemName() == "Mac")
  964. // {
  965. // changeDirectory(miscDir + "cppObjc");
  966. // runCommand("haxe", ["build.hxml"]);
  967. // runCpp("bin/TestObjc-debug");
  968. // }
  969. case Js:
  970. getJSDependencies();
  971. var jsOutputs = [
  972. for (es3 in [[], ["-D", "js-es=3"]])
  973. for (unflatten in [[], ["-D", "js-unflatten"]])
  974. for (classic in [[], ["-D", "js-classic"]])
  975. {
  976. var extras = args.concat(es3).concat(unflatten).concat(classic);
  977. runCommand("haxe", ["compile-js.hxml"].concat(extras));
  978. var output = if (extras.length > 0) {
  979. "bin/js/" + extras.join("") + "/unit.js";
  980. } else {
  981. "bin/js/default/unit.js";
  982. }
  983. var outputDir = Path.directory(output);
  984. if (!FileSystem.exists(outputDir)) {
  985. FileSystem.createDirectory(outputDir);
  986. }
  987. FileSystem.rename("bin/unit.js", output);
  988. FileSystem.rename("bin/unit.js.map", output + ".map");
  989. runCommand("node", ["-e", "require('./" + output + "').unit.TestMain.nodejsMain();"]);
  990. output;
  991. }
  992. ];
  993. var env = Sys.environment();
  994. if (
  995. env.exists("SAUCE") &&
  996. env.exists("SAUCE_USERNAME") &&
  997. env.exists("SAUCE_ACCESS_KEY")
  998. ) {
  999. // sauce-connect should have been started
  1000. // var scVersion = "sc-4.3-linux";
  1001. // runCommand("wget", ['https://saucelabs.com/downloads/${scVersion}.tar.gz'], true);
  1002. // runCommand("tar", ["-xf", '${scVersion}.tar.gz']);
  1003. // //start sauce-connect
  1004. // var scReadyFile = "sauce-connect-ready-" + Std.random(100);
  1005. // var sc = new Process('${scVersion}/bin/sc', [
  1006. // "-i", Sys.getEnv("TRAVIS_JOB_NUMBER"),
  1007. // "-f", scReadyFile
  1008. // ]);
  1009. // while(!FileSystem.exists(scReadyFile)) {
  1010. // Sys.sleep(0.5);
  1011. // }
  1012. runCommand("npm", ["install", "wd", "q"], true);
  1013. haxelibInstall("hxnodejs");
  1014. runCommand("haxe", ["compile-saucelabs-runner.hxml"]);
  1015. var server = new Process("nekotools", ["server"]);
  1016. runCommand("node", ["bin/RunSauceLabs.js"].concat([for (js in jsOutputs) "unit-js.html?js=" + js.urlEncode()]));
  1017. server.close();
  1018. // sc.close();
  1019. }
  1020. infoMsg("Test optimization:");
  1021. changeDirectory(optDir);
  1022. runCommand("haxe", ["run.hxml"]);
  1023. case Java:
  1024. getSpodDependencies();
  1025. getJavaDependencies();
  1026. runCommand("haxe", ["compile-java.hxml"].concat(args));
  1027. runCommand("java", ["-jar", "bin/java/TestMain-Debug.jar"]);
  1028. runCommand("haxe", ["compile-java.hxml","-dce","no"].concat(args));
  1029. runCommand("java", ["-jar", "bin/java/TestMain-Debug.jar"]);
  1030. changeDirectory(sysDir);
  1031. runCommand("haxe", ["compile-java.hxml"]);
  1032. runCommand("java", ["-jar", "bin/java/Main-Debug.jar"]);
  1033. infoMsg("Testing java-lib extras");
  1034. changeDirectory('$unitDir/bin');
  1035. runCommand("git", ["clone", "https://github.com/waneck/java-lib-tests.git", "--depth", "1"], true);
  1036. for (dir in FileSystem.readDirectory('java-lib-tests'))
  1037. {
  1038. var path = 'java-lib-tests/$dir';
  1039. if (FileSystem.isDirectory(path)) for (file in FileSystem.readDirectory(path))
  1040. {
  1041. if (file.endsWith('.hxml'))
  1042. {
  1043. runCommand("haxe", ["--cwd",'java-lib-tests/$dir',file]);
  1044. }
  1045. }
  1046. }
  1047. case Cs:
  1048. getSpodDependencies();
  1049. getCsDependencies();
  1050. var compl = switch [ci, systemName] {
  1051. case [TravisCI, "Linux"]:
  1052. "-travis";
  1053. case _:
  1054. "";
  1055. };
  1056. for (fastcast in [[], ["-D", "fast_cast"]])
  1057. for (noroot in [[], ["-D", "no_root"]])
  1058. for (erasegenerics in [[], ["-D", "erase_generics"]])
  1059. {
  1060. var extras = fastcast.concat(erasegenerics).concat(noroot);
  1061. runCommand("haxe", ['compile-cs$compl.hxml'].concat(extras));
  1062. runCs("bin/cs/bin/TestMain-Debug.exe");
  1063. runCommand("haxe", ['compile-cs-unsafe$compl.hxml'].concat(extras));
  1064. runCs("bin/cs_unsafe/bin/TestMain-Debug.exe");
  1065. }
  1066. runCommand("haxe", ['compile-cs$compl.hxml','-dce','no']);
  1067. runCs("bin/cs/bin/TestMain-Debug.exe");
  1068. changeDirectory(sysDir);
  1069. runCommand("haxe", ["compile-cs.hxml",'-D','fast_cast']);
  1070. runCs("bin/cs/bin/Main-Debug.exe", []);
  1071. changeDirectory(miscDir + "csTwoLibs");
  1072. for (i in 1...5)
  1073. {
  1074. runCommand("haxe", ['compile-$i.hxml','-D','fast_cast']);
  1075. runCs("bin/main/bin/Main.exe");
  1076. }
  1077. case Flash9:
  1078. setupFlashPlayerDebugger();
  1079. runCommand("haxe", ["compile-flash9.hxml", "-D", "fdb", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
  1080. var success = runFlash("bin/unit9.swf");
  1081. if (!success)
  1082. fail();
  1083. case As3:
  1084. setupFlashPlayerDebugger();
  1085. //setup flex sdk
  1086. if (commandSucceed("mxmlc", ["--version"])) {
  1087. infoMsg('mxmlc has already been installed.');
  1088. } else {
  1089. var apacheMirror = Json.parse(Http.requestUrl("http://www.apache.org/dyn/closer.lua?as_json=1")).preferred;
  1090. var flexVersion = "4.16.0";
  1091. runCommand("wget", ['${apacheMirror}/flex/${flexVersion}/binaries/apache-flex-sdk-${flexVersion}-bin.tar.gz'], true);
  1092. runCommand("tar", ["-xf", 'apache-flex-sdk-${flexVersion}-bin.tar.gz', "-C", Sys.getEnv("HOME")]);
  1093. var flexsdkPath = Sys.getEnv("HOME") + '/apache-flex-sdk-${flexVersion}-bin';
  1094. addToPATH(flexsdkPath + "/bin");
  1095. var playerglobalswcFolder = flexsdkPath + "/player";
  1096. FileSystem.createDirectory(playerglobalswcFolder + "/11.1");
  1097. runCommand("wget", ["-nv", "http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc", "-O", playerglobalswcFolder + "/11.1/playerglobal.swc"], true);
  1098. File.saveContent(flexsdkPath + "/env.properties", 'env.PLAYERGLOBAL_HOME=$playerglobalswcFolder');
  1099. runCommand("mxmlc", ["--version"]);
  1100. }
  1101. runCommand("haxe", ["compile-as3.hxml", "-D", "fdb"].concat(args));
  1102. var success = runFlash("bin/unit9_as3.swf");
  1103. if (!success)
  1104. fail();
  1105. case Hl:
  1106. runCommand("haxe", ["compile-hl.hxml"]);
  1107. case ThirdParty:
  1108. getPhpDependencies();
  1109. getJavaDependencies();
  1110. getJSDependencies();
  1111. getCsDependencies();
  1112. getPythonDependencies();
  1113. getCppDependencies();
  1114. //getOpenFLDependencies();
  1115. //testPolygonalDs();
  1116. // if (systemName == "Linux") testFlambe(); //#3439
  1117. testHxTemplo();
  1118. testMUnit();
  1119. testHaxeQuake();
  1120. //testOpenflSamples();
  1121. //testFlixelDemos();
  1122. case t:
  1123. throw "unknown target: " + t;
  1124. }
  1125. } catch(f:Failure) {
  1126. success = false;
  1127. }
  1128. switch (ci) {
  1129. case TravisCI:
  1130. Sys.println('travis_fold:end:test-${test}');
  1131. case _:
  1132. //pass
  1133. }
  1134. if (success) {
  1135. successMsg('test ${test} succeeded');
  1136. } else {
  1137. failMsg('test ${test} failed');
  1138. }
  1139. }
  1140. if (success) {
  1141. deploy();
  1142. } else {
  1143. Sys.exit(1);
  1144. }
  1145. }
  1146. static function testHxTemplo() {
  1147. infoMsg("Test hx-templo:");
  1148. changeDirectory(unitDir);
  1149. haxelibInstallGit("Simn", "hxparse", "master", "src");
  1150. haxelibInstallGit("Simn", "hxtemplo");
  1151. var buildArgs = [
  1152. "-cp", "src",
  1153. "-cp", "test",
  1154. "-main", "Test",
  1155. "-lib", "hxparse",
  1156. "-dce", "full"
  1157. ];
  1158. changeDirectory(getHaxelibPath("hxtemplo") + "..");
  1159. runCommand("haxe", ["build.hxml"]);
  1160. }
  1161. static function testPolygonalDs() {
  1162. infoMsg("Test polygonal-ds:");
  1163. changeDirectory(unitDir);
  1164. haxelibInstallGit("Simn", "ds", "python-support", null, false, "polygonal-ds");
  1165. haxelibInstallGit("polygonal", "core", "master", "src", false, "polygonal-core");
  1166. haxelibInstallGit("polygonal", "printf", "master", "src", false, "polygonal-printf");
  1167. changeDirectory(getHaxelibPath("polygonal-ds"));
  1168. runCommand("haxe", ["build.hxml"]);
  1169. runCommand("python3", ["unit.py"]);
  1170. runCommand("node", ["unit.js"]);
  1171. }
  1172. static function testMUnit() {
  1173. infoMsg("Test MUnit:");
  1174. changeDirectory(unitDir);
  1175. haxelibInstallGit("massiveinteractive", "mconsole", "master", "src");
  1176. haxelibInstallGit("massiveinteractive", "MassiveCover", "master", "src", false, "mcover");
  1177. haxelibInstallGit("massiveinteractive", "MassiveLib", "master", "src", false, "mlib");
  1178. haxelibInstallGit("massiveinteractive", "MassiveUnit", "2.1.2", "src", false, "munit");
  1179. changeDirectory(Path.join([getHaxelibPath("munit"), "..", "tool"]));
  1180. runCommand("haxe", ["build.hxml"]);
  1181. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  1182. changeDirectory("../");
  1183. haxelibRun(["munit", "test", "-result-exit-code", "-neko"], true);
  1184. }
  1185. static function testHaxeQuake() {
  1186. infoMsg("Test HaxeQuake:");
  1187. changeDirectory(unitDir);
  1188. runCommand("git", ["clone", "https://github.com/nadako/HaxeQuake"]);
  1189. changeDirectory("HaxeQuake/Client");
  1190. runCommand("haxe", ["build.hxml"]);
  1191. }
  1192. static function testFlambe() {
  1193. infoMsg("Test Flambe:");
  1194. changeDirectory(unitDir);
  1195. runCommand("git", ["clone", "https://github.com/aduros/flambe"]);
  1196. runCommand("sh", ["flambe/bin/run-travis"]);
  1197. }
  1198. //static function testOpenflSamples() {
  1199. //infoMsg("Test OpenFL Samples:");
  1200. //
  1201. //changeDirectory(unitDir);
  1202. //
  1203. //haxelibInstallGit("jgranick", "actuate");
  1204. //haxelibInstallGit("jgranick", "box2d");
  1205. //haxelibInstallGit("jgranick", "layout");
  1206. //haxelibInstallGit("openfl", "swf");
  1207. //haxelibInstallGit("openfl", "openfl-samples");
  1208. //
  1209. //var path = getHaxelibPath("openfl-samples");
  1210. //var old = Sys.getEnv("pwd");
  1211. //Sys.putEnv("pwd", path);
  1212. //parseTravisFile(haxe.io.Path.join([path, ".travis.yml"]), true);
  1213. //if (old != null) {
  1214. //Sys.putEnv("pwd", old);
  1215. //}
  1216. //}
  1217. static function testFlixelDemos() {
  1218. infoMsg("Test Flixel Demos:");
  1219. changeDirectory(unitDir);
  1220. getOpenFLDependencies();
  1221. haxelibInstall("systools");
  1222. haxelibInstall("spinehx");
  1223. haxelibInstall("nape");
  1224. haxelibInstall("task");
  1225. haxelibInstallGit("larsiusprime", "firetongue");
  1226. haxelibInstallGit("YellowAfterLife", "openfl-bitfive");
  1227. haxelibInstallGit("HaxeFlixel", "flixel");
  1228. haxelibInstallGit("HaxeFlixel", "flixel-addons");
  1229. haxelibInstallGit("HaxeFlixel", "flixel-ui");
  1230. haxelibInstallGit("HaxeFlixel", "flixel-demos");
  1231. haxelibInstallGit("HaxeFlixel", "flixel-tools");
  1232. haxelibRun(["flixel-tools", "testdemos", "-flash"]);
  1233. haxelibRun(["flixel-tools", "testdemos", "-neko"]);
  1234. haxelibRun(["flixel-tools", "testdemos", "-html5"]);
  1235. }
  1236. }