12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package runci.targets;
- import sys.FileSystem;
- import runci.System.*;
- import runci.Config.*;
- class Php {
- static var miscPhpDir(get,never):String;
- static inline function get_miscPhpDir() return miscDir + 'php/';
- static public function getPhpDependencies() {
- var phpCmd = commandResult("php", ["-v"]);
- var phpVerReg = ~/PHP ([0-9]+\.[0-9]+)/i;
- var phpVer = if (phpVerReg.match(phpCmd.stdout))
- Std.parseFloat(phpVerReg.matched(1));
- else
- null;
- if (phpCmd.exitCode == 0 && phpVer != null && phpVer >= 7.0) {
- switch systemName {
- case "Linux":
- var phpInfo = commandResult("php", ["-i"]);
- if(phpInfo.stdout.indexOf("mbstring => enabled") < 0) {
- Linux.requireAptPackages(["php-mbstring"]);
- }
- case _:
- }
- infoMsg('php $phpVer has already been installed.');
- return;
- }
- switch systemName {
- case "Linux":
- Linux.requireAptPackages(["php-cli", "php-mbstring"]);
- case "Mac":
- runCommand("brew", ["install", "php"], true);
- case "Windows":
- runCommand("cinst", ["php", "-version", "7.1.8", "-y"], true);
- case _:
- throw 'unknown system: $systemName';
- }
- runCommand("php", ["-v"]);
- }
- static public function run(args:Array<String>) {
- getPhpDependencies();
- changeDirectory(miscPhpDir);
- runCommand("haxe", ["run.hxml"]);
- var binDir = "bin/php";
- var prefixes = [[]];
- if(isCi()) {
- prefixes.push(['-D', 'php-prefix=haxe']);
- prefixes.push(['-D', 'php-prefix=my.pack']);
- }
- for(prefix in prefixes) {
- changeDirectory(unitDir);
- if(isCi())
- deleteDirectoryRecursively(binDir);
- runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
- runThroughPhpVersions(runCommand.bind(_, [binDir + "/index.php"]));
- changeDirectory(sysDir);
- if(isCi())
- deleteDirectoryRecursively(binDir);
- runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
- runThroughPhpVersions(runSysTest.bind(_, ["bin/php/Main/index.php"]));
- }
- }
- static function runThroughPhpVersions(fn:(phpCmd:String)->Void) {
- switch [ci, systemName] {
- case [GithubActions, "Linux"]:
- for(version in ['7.4', '8.0']) {
- fn('php$version');
- }
- case _:
- fn('php');
- }
- }
- }
|