Php.hx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package runci.targets;
  2. import runci.System.*;
  3. import runci.Config.*;
  4. using haxe.io.Path;
  5. class Php {
  6. static final miscPhpDir = getMiscSubDir('php');
  7. static final windowsPhpIni = cwd + 'PHP.ini';
  8. static var windowsPhpExtPath(get, null) = null;
  9. static function get_windowsPhpExtPath() {
  10. if (windowsPhpExtPath != null)
  11. return windowsPhpExtPath;
  12. final phpPath = commandResult("where", ["php"]).stdout;
  13. return windowsPhpExtPath = Path.join([phpPath.directory(), "ext"]);
  14. }
  15. static function generateArgs(file:String) {
  16. if (systemName != "Windows")
  17. return [file];
  18. return [
  19. "-c",
  20. windowsPhpIni,
  21. "-d",
  22. 'extension_dir=$windowsPhpExtPath',
  23. file
  24. ];
  25. }
  26. static public function getPhpDependencies() {
  27. final phpCmd = commandResult("php", ["-v"]);
  28. final phpVerReg = ~/PHP ([0-9]+\.[0-9]+)/i;
  29. final phpVer = if (phpVerReg.match(phpCmd.stdout))
  30. Std.parseFloat(phpVerReg.matched(1));
  31. else
  32. null;
  33. if (phpCmd.exitCode == 0 && phpVer != null && phpVer >= 7.0) {
  34. switch systemName {
  35. case "Linux":
  36. var phpInfo = commandResult("php", ["-i"]).stdout;
  37. if(phpInfo.indexOf("mbstring => enabled") < 0) {
  38. Linux.requireAptPackages(["php-mbstring"]);
  39. }
  40. case _:
  41. }
  42. infoMsg('php $phpVer has already been installed.');
  43. return;
  44. }
  45. switch systemName {
  46. case "Linux":
  47. Linux.requireAptPackages(["php-cli", "php-mbstring", "php-sqlite3"]);
  48. case "Mac":
  49. runNetworkCommand("brew", ["install", "php"]);
  50. case "Windows":
  51. runNetworkCommand("cinst", ["php", "-version", "7.1.8", "-y"]);
  52. case _:
  53. throw 'unknown system: $systemName';
  54. }
  55. runCommand("php", ["-v"]);
  56. }
  57. static public function run(args:Array<String>) {
  58. getPhpDependencies();
  59. changeDirectory(miscPhpDir);
  60. runCommand("haxe", ["run.hxml"]);
  61. final binDir = "bin/php";
  62. final prefixes = [[]];
  63. if(isCi()) {
  64. prefixes.push(['-D', 'php-prefix=haxe']);
  65. prefixes.push(['-D', 'php-prefix=my.pack']);
  66. }
  67. for(prefix in prefixes) {
  68. changeDirectory(unitDir);
  69. if(isCi())
  70. deleteDirectoryRecursively(binDir);
  71. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  72. runCommand("php", generateArgs(binDir + "/index.php"));
  73. changeDirectory(sysDir);
  74. if(isCi())
  75. deleteDirectoryRecursively(binDir);
  76. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  77. runSysTest("php", generateArgs(binDir + "/Main/index.php"));
  78. }
  79. }
  80. }