Php.hx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  54. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  55. runThroughPhpVersions(runCommand.bind(_, [binDir + "/index.php"]));
  56. changeDirectory(sysDir);
  57. if(isCi()) {
  58. deleteDirectoryRecursively(binDir);
  59. }
  60. runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
  61. runThroughPhpVersions(runCommand.bind(_, ["bin/php/Main/index.php"]));
  62. }
  63. }
  64. static function runThroughPhpVersions(fn:(phpCmd:String)->Void) {
  65. switch [ci, systemName] {
  66. case [GithubActions, "Linux"]:
  67. for(version in ['7.1', '7.2', '7.3', '7.4']) {
  68. fn('php$version');
  69. }
  70. case _:
  71. fn('php');
  72. }
  73. }
  74. }