Php.hx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package runci.targets;
  2. import sys.FileSystem;
  3. import runci.System.*;
  4. import runci.Config.*;
  5. class Php {
  6. static var miscPhpDir(get,never):String;
  7. static inline function get_miscPhpDir() return miscDir + 'php/';
  8. static public function getPhpDependencies() {
  9. var phpCmd = commandResult("php", ["-v"]);
  10. var phpVerReg = ~/PHP ([0-9]+\.[0-9]+)/i;
  11. var phpVer = if (phpVerReg.match(phpCmd.stdout))
  12. Std.parseFloat(phpVerReg.matched(1));
  13. else
  14. null;
  15. if (phpCmd.exitCode == 0 && phpVer != null && phpVer >= 7.0) {
  16. infoMsg('php ${phpVer} has already been installed.');
  17. return;
  18. }
  19. switch [ci, systemName] {
  20. case [TravisCI, "Linux"]:
  21. runCommand("phpenv", ["global", "7.0"], false, true);
  22. case [_, "Linux"]:
  23. Linux.requireAptPackages(["php-cli", "php-mbstring"]);
  24. case [_, "Mac"]:
  25. runCommand("brew", ["install", "php"], true);
  26. case [_, "Windows"]:
  27. runCommand("cinst", ["php", "-version", "7.1.8", "-y"], true);
  28. case _:
  29. throw 'unknown combination: $ci, $systemName';
  30. }
  31. runCommand("php", ["-v"]);
  32. }
  33. static public function run(args:Array<String>) {
  34. getPhpDependencies();
  35. var binDir = "bin/php";
  36. var prefixes = [[]];
  37. if(isCi()) {
  38. prefixes.push(['-D', 'php-prefix=haxe']);
  39. prefixes.push(['-D', 'php-prefix=my.pack']);
  40. }
  41. for(prefix in prefixes) {
  42. changeDirectory(unitDir);
  43. if(isCi()) {
  44. deleteDirectoryRecursively(binDir);
  45. }
  46. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  47. runThroughPhpVersions(runCommand.bind("php", [binDir + "/index.php"]));
  48. changeDirectory(sysDir);
  49. if(isCi()) {
  50. deleteDirectoryRecursively(binDir);
  51. }
  52. runCommand("haxe", ["compile-php.hxml"].concat(prefix));
  53. runThroughPhpVersions(runCommand.bind("php", ["bin/php/Main/index.php"]));
  54. changeDirectory(miscPhpDir);
  55. runThroughPhpVersions(runCommand.bind("haxe", ["run.hxml"]));
  56. }
  57. }
  58. static function runThroughPhpVersions(fn:()->Void) {
  59. if(ci == TravisCI && systemName == "Linux") {
  60. for(version in ['7.0', '7.1'/*, '7.2', '7.3'*/]) { //7.2 and 7.3 are not available on travis Ubuntu trusty
  61. runCommand("phpenv", ["global", version]);
  62. fn();
  63. }
  64. } else {
  65. fn();
  66. }
  67. }
  68. }