Php.hx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. switch systemName {
  17. case "Linux":
  18. var phpInfo = commandResult("php", ["-i"]);
  19. if(phpInfo.stdout.indexOf("mbstring => enabled") < 0) {
  20. Linux.requireAptPackages(["php-mbstring"]);
  21. }
  22. case _:
  23. }
  24. infoMsg('php $phpVer has already been installed.');
  25. return;
  26. }
  27. switch systemName {
  28. case "Linux":
  29. Linux.requireAptPackages(["php-cli", "php-mbstring"]);
  30. case "Mac":
  31. runCommand("brew", ["install", "php"], true);
  32. case "Windows":
  33. runCommand("cinst", ["php", "-version", "7.1.8", "-y"], true);
  34. case _:
  35. throw 'unknown system: $systemName';
  36. }
  37. runCommand("php", ["-v"]);
  38. }
  39. static public function run(args:Array<String>) {
  40. getPhpDependencies();
  41. changeDirectory(miscPhpDir);
  42. runCommand("haxe", ["run.hxml"]);
  43. var binDir = "bin/php";
  44. var prefixes = [[]];
  45. if(isCi()) {
  46. prefixes.push(['-D', 'php-prefix=haxe']);
  47. prefixes.push(['-D', 'php-prefix=my.pack']);
  48. }
  49. for(prefix in prefixes) {
  50. changeDirectory(unitDir);
  51. if(isCi())
  52. deleteDirectoryRecursively(binDir);
  53. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  54. runThroughPhpVersions(runCommand.bind(_, [binDir + "/index.php"]));
  55. changeDirectory(sysDir);
  56. if(isCi())
  57. deleteDirectoryRecursively(binDir);
  58. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  59. runThroughPhpVersions(runSysTest.bind(_, ["bin/php/Main/index.php"]));
  60. }
  61. }
  62. static function runThroughPhpVersions(fn:(phpCmd:String)->Void) {
  63. switch [ci, systemName] {
  64. case [GithubActions, "Linux"]:
  65. for(version in ['7.4', '8.0']) {
  66. fn('php$version');
  67. }
  68. case _:
  69. fn('php');
  70. }
  71. }
  72. }