From d13dd67fe7ea30dc89e9f9ef1c0f72ee59b9a0a4 Mon Sep 17 00:00:00 2001 From: dpomier Date: Wed, 29 Jan 2020 11:40:27 +0100 Subject: [PATCH 01/13] allow running processes with commands that are not executables --- src/hxp/System.hx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hxp/System.hx b/src/hxp/System.hx index 7aed146..afd233f 100644 --- a/src/hxp/System.hx +++ b/src/hxp/System.hx @@ -1076,7 +1076,7 @@ class System } public static function runProcess(path:String, command:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, - ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false):String + ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false, allowNonExecutables = false):String { if (print) { @@ -1113,7 +1113,7 @@ class System Log.error("The specified target path \"" + path + "\" does not exist"); } - return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue); + return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue, allowNonExecutables); } catch (e:Dynamic) { @@ -1127,12 +1127,12 @@ class System } else { - return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue); + return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue, allowNonExecutables); } } private static function _runProcess(path:String, command:String, args:Array, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool, - returnErrorValue:Bool):String + returnErrorValue:Bool, allowNonExecutables:Bool):String { var oldPath:String = ""; @@ -1168,7 +1168,7 @@ class System if (!dryRun) { - var process = new Process(command, args); + var process = allowNonExecutables ? new Process('$command ${args.join(" ")}', null) : new Process(command, args); var buffer = new BytesOutput(); if (waitForOutput) From db42e12e7e8d73860b946d29f40d55be314bbd7d Mon Sep 17 00:00:00 2001 From: dpomier Date: Wed, 29 Jan 2020 11:41:12 +0100 Subject: [PATCH 02/13] fix running 'haxelib path lib' when using lix --- src/hxp/Haxelib.hx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index 0db5ddc..8010eb3 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -128,7 +128,7 @@ class Haxelib var cacheDryRun = System.dryRun; System.dryRun = false; - output = Haxelib.runProcess(workingDirectory, ["path", name], true, true, true); + output = Haxelib.runProcess(workingDirectory, ["path", name], true, true, true, false, false, true); if (output == null) output = ""; System.dryRun = cacheDryRun; @@ -432,7 +432,7 @@ class Haxelib } public static function runProcess(path:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, - print:Bool = false, returnErrorValue:Bool = false):String + print:Bool = false, returnErrorValue:Bool = false, allowNonExecutables:Bool = false):String { if (pathOverrides.exists("haxelib")) { @@ -443,7 +443,7 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue); + return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, allowNonExecutables); } else { @@ -456,7 +456,7 @@ class Haxelib // } - return System.runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue); + return System.runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, allowNonExecutables); } } From 37e9b151ef61d632c1380471448a12ccd9aa7063 Mon Sep 17 00:00:00 2001 From: dpomier Date: Wed, 29 Jan 2020 12:21:26 +0100 Subject: [PATCH 03/13] minor change --- src/hxp/System.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hxp/System.hx b/src/hxp/System.hx index afd233f..526c559 100644 --- a/src/hxp/System.hx +++ b/src/hxp/System.hx @@ -1168,7 +1168,7 @@ class System if (!dryRun) { - var process = allowNonExecutables ? new Process('$command ${args.join(" ")}', null) : new Process(command, args); + var process = allowNonExecutables ? new Process(command + " " + args.join(" ")) : new Process(command, args); var buffer = new BytesOutput(); if (waitForOutput) From 4a8d1d19a7170a450f763e1bd74f65e9c797d9be Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 09:42:57 +0100 Subject: [PATCH 04/13] allow running haxelib commands that are not executables --- src/hxp/Haxelib.hx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index 8010eb3..5793271 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -403,8 +403,11 @@ class Haxelib return versions.get(haxelib.name); } - public static function runCommand(path:String, args:Array, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false):Int + public static function runCommand(path:String, args:Array, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false, + allowNonExecutables:Bool = false):Int { + var command:String; + if (pathOverrides.exists("haxelib")) { var script = Path.combine(pathOverrides.get("haxelib"), "run.n"); @@ -414,21 +417,21 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - return System.runCommand(path, "neko", [script].concat(args), safeExecute, ignoreErrors, print); + command = "neko"; + args = [script].concat(args); } else { - // var haxe = Sys.getEnv ("HAXEPATH"); - var command = "haxelib"; - - // if (haxe != null) { - - // command = Path.combine (haxe, command); - - // } + command = "haxelib"; + } - return System.runCommand(path, command, args, safeExecute, ignoreErrors, print); + if (allowNonExecutables) + { + command += " " + args.join(" "); + args = null; } + + return System.runCommand(path, command, args, safeExecute, ignoreErrors, print); } public static function runProcess(path:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, From e53facaba02debac6db99ab08c11f359c01f5140 Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 09:43:12 +0100 Subject: [PATCH 05/13] run formatter --- src/hxp/Haxelib.hx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index 5793271..af048a2 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -446,7 +446,8 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, allowNonExecutables); + return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, + allowNonExecutables); } else { From b655af4e915276dcc24611115adfa85c7c67be79 Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 09:44:07 +0100 Subject: [PATCH 06/13] add support to build hxml from a different working directory --- src/hxp/HXML.hx | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/hxp/HXML.hx b/src/hxp/HXML.hx index e52ff16..3e3d77c 100644 --- a/src/hxp/HXML.hx +++ b/src/hxp/HXML.hx @@ -332,9 +332,9 @@ abstract HXML(Array) /** Builds the current HXML using Haxe. **/ - public function build():Int + public function build(workingDirectory:String = ""):Int { - return System.runCommand("", "haxe " + this.join(" "), null); + return System.runCommand(workingDirectory, "haxe " + this.join(" "), null); } /** @@ -390,6 +390,38 @@ abstract HXML(Array) this.push("-D " + name + (value == null ? "" : "=" + Std.string(value))); } + public static function buildFile(path:String, fromDirectory:String = ""):Int + { + var hxml:HXML = fromFile(path); + var hxmlDirectory = Path.directory(path); + + if (fromDirectory != "" && fromDirectory != hxmlDirectory) + { + var lines:Array = cast hxml; + + for (i in 0...lines.length) + { + if (lines[i].indexOf("-cp ") == 0) + { + var quote:Int = lines[i].indexOf('"'); + + if (quote > 0) + { + lines[i] = "-cp \"" + hxmlDirectory + "/" + lines[i].substr(quote + 1); + } + else + { + lines[i] = "-cp " + hxmlDirectory + "/" + lines[i].substr(4); + } + } + } + + lines.push('-cp "$hxmlDirectory"'); + } + + return hxml.build(fromDirectory); + } + public static function fromFile(path:String):HXML { if (FileSystem.exists(path)) @@ -410,7 +442,12 @@ abstract HXML(Array) for (line in lines) { - value.push(StringTools.trim(line)); + line = StringTools.trim(line); + + if (!StringTools.startsWith(line, "#")) + { + value.push(line); + } } } From cae7dfd7a93d4699a4289896a0c0c9e59ae306dc Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 09:45:30 +0100 Subject: [PATCH 07/13] fix running SliasScript from lix-pm --- scripts/AliasScript.hx | 2 +- src/hxp/System.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/AliasScript.hx b/scripts/AliasScript.hx index ec34b33..342c494 100644 --- a/scripts/AliasScript.hx +++ b/scripts/AliasScript.hx @@ -7,6 +7,6 @@ class AliasScript public static function main() { var args = ["run", Compiler.getDefine("command")].concat(Sys.args()); - Sys.exit(Sys.command("haxelib", args)); + Sys.exit(Sys.command("haxelib " + args.join(" "))); } } diff --git a/src/hxp/System.hx b/src/hxp/System.hx index 526c559..28bb822 100644 --- a/src/hxp/System.hx +++ b/src/hxp/System.hx @@ -1284,7 +1284,7 @@ class System // try { - // var process = new Process ("haxe", [ "-version" ]); + // var process = new Process ("haxe -version"); // _haxeVersion = StringTools.trim (process.stderr.readAll ().toString ()); // if (_haxeVersion == "") { From 9230c7f965fe32b2fe81ac4f5368ab664a76989c Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 11:32:33 +0100 Subject: [PATCH 08/13] always run non executable commands for haxelib --- src/hxp/Haxelib.hx | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index af048a2..440d490 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -403,8 +403,7 @@ class Haxelib return versions.get(haxelib.name); } - public static function runCommand(path:String, args:Array, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false, - allowNonExecutables:Bool = false):Int + public static function runCommand(path:String, args:Array, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false):Int { var command:String; @@ -418,24 +417,18 @@ class Haxelib } command = "neko"; - args = [script].concat(args); + args = ['"$script"'].concat(args); } else { command = "haxelib"; } - if (allowNonExecutables) - { - command += " " + args.join(" "); - args = null; - } - - return System.runCommand(path, command, args, safeExecute, ignoreErrors, print); + return System.runCommand(path, command + " " + args.join(" "), null, safeExecute, ignoreErrors, print); } public static function runProcess(path:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, - print:Bool = false, returnErrorValue:Bool = false, allowNonExecutables:Bool = false):String + print:Bool = false, returnErrorValue:Bool = false):String { if (pathOverrides.exists("haxelib")) { @@ -446,8 +439,7 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, - allowNonExecutables); + return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, true); } else { @@ -460,7 +452,7 @@ class Haxelib // } - return System.runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, allowNonExecutables); + return System.runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, true); } } From 77acc62f37ef2aa63d6768d041e4a3755cb85564 Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 4 Feb 2020 11:36:39 +0100 Subject: [PATCH 09/13] refactor --- src/hxp/Haxelib.hx | 2 +- src/hxp/PlatformTools.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index 440d490..e2a27f1 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -128,7 +128,7 @@ class Haxelib var cacheDryRun = System.dryRun; System.dryRun = false; - output = Haxelib.runProcess(workingDirectory, ["path", name], true, true, true, false, false, true); + output = Haxelib.runProcess(workingDirectory, ["path", name], true, true, true); if (output == null) output = ""; System.dryRun = cacheDryRun; diff --git a/src/hxp/PlatformTools.hx b/src/hxp/PlatformTools.hx index e3d6629..683f971 100644 --- a/src/hxp/PlatformTools.hx +++ b/src/hxp/PlatformTools.hx @@ -50,7 +50,7 @@ class PlatformTools { Log.info("", " - \x1b[1mStarting local web server:\x1b[0m http://localhost:" + port); - var args = ["run", "http-server", path, "-p", Std.string(port), "-c-1", "--cors"]; + var args = ["run", "http-server", '"$path"', "-p", Std.string(port), "-c-1", "--cors"]; if (!openBrowser && !Log.verbose) { From 40841a1ff056bfe18c518a02c18772f7786c934e Mon Sep 17 00:00:00 2001 From: dpomier Date: Fri, 7 Feb 2020 14:42:04 +0100 Subject: [PATCH 10/13] Revert d13dd67 --- src/hxp/System.hx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hxp/System.hx b/src/hxp/System.hx index 28bb822..4cf7114 100644 --- a/src/hxp/System.hx +++ b/src/hxp/System.hx @@ -1076,7 +1076,7 @@ class System } public static function runProcess(path:String, command:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, - ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false, allowNonExecutables = false):String + ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false):String { if (print) { @@ -1113,7 +1113,7 @@ class System Log.error("The specified target path \"" + path + "\" does not exist"); } - return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue, allowNonExecutables); + return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue); } catch (e:Dynamic) { @@ -1127,12 +1127,12 @@ class System } else { - return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue, allowNonExecutables); + return _runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue); } } private static function _runProcess(path:String, command:String, args:Array, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool, - returnErrorValue:Bool, allowNonExecutables:Bool):String + returnErrorValue:Bool):String { var oldPath:String = ""; @@ -1168,7 +1168,7 @@ class System if (!dryRun) { - var process = allowNonExecutables ? new Process(command + " " + args.join(" ")) : new Process(command, args); + var process = new Process(command, args); var buffer = new BytesOutput(); if (waitForOutput) From 7f16433652261a75c920f42b7520065d00a7fdde Mon Sep 17 00:00:00 2001 From: dpomier Date: Fri, 7 Feb 2020 14:53:17 +0100 Subject: [PATCH 11/13] update Haxelib for #21 --- src/hxp/Haxelib.hx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/hxp/Haxelib.hx b/src/hxp/Haxelib.hx index e2a27f1..bbeb6a9 100644 --- a/src/hxp/Haxelib.hx +++ b/src/hxp/Haxelib.hx @@ -416,20 +416,21 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - command = "neko"; - args = ['"$script"'].concat(args); + command = 'neko "$script"'; } else { command = "haxelib"; } - return System.runCommand(path, command + " " + args.join(" "), null, safeExecute, ignoreErrors, print); + return System.runCommand(path, command + " " + args.join(" "), safeExecute, ignoreErrors, print); } public static function runProcess(path:String, args:Array, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false):String { + var command:String; + if (pathOverrides.exists("haxelib")) { var script = Path.combine(pathOverrides.get("haxelib"), "run.n"); @@ -439,21 +440,14 @@ class Haxelib Log.error("Cannot find haxelib script: " + script); } - return System.runProcess(path, "neko", [script].concat(args), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, true); + command = 'neko "$script"'; } else { - // var haxe = Sys.getEnv ("HAXEPATH"); - var command = "haxelib"; - - // if (haxe != null) { - - // command = Path.combine (haxe, command); - - // } - - return System.runProcess(path, command, args, waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue, true); + command = "haxelib"; } + + return System.runProcess(path, command + " " + args.join(" "), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue); } public static function setOverridePath(haxelib:Haxelib, path:String):Void From 6671c38631e1333d0b823a4e1828de7be8e00046 Mon Sep 17 00:00:00 2001 From: dpomier Date: Fri, 7 Feb 2020 16:26:12 +0100 Subject: [PATCH 12/13] error when building unexisting hxml file --- src/hxp/HXML.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hxp/HXML.hx b/src/hxp/HXML.hx index 3e3d77c..dabec41 100644 --- a/src/hxp/HXML.hx +++ b/src/hxp/HXML.hx @@ -395,6 +395,11 @@ abstract HXML(Array) var hxml:HXML = fromFile(path); var hxmlDirectory = Path.directory(path); + if (hxml == null) + { + Log.error("The specified target path \"" + path + "\" does not exist"); + } + if (fromDirectory != "" && fromDirectory != hxmlDirectory) { var lines:Array = cast hxml; From 0c24eed309a10f8faf409951f0772844112531ce Mon Sep 17 00:00:00 2001 From: dpomier Date: Tue, 18 Feb 2020 13:42:13 +0100 Subject: [PATCH 13/13] improve class path relocation --- src/hxp/HXML.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hxp/HXML.hx b/src/hxp/HXML.hx index a1520cc..945120b 100644 --- a/src/hxp/HXML.hx +++ b/src/hxp/HXML.hx @@ -409,15 +409,18 @@ abstract HXML(Array) if (lines[i].indexOf("-cp ") == 0) { var quote:Int = lines[i].indexOf('"'); + var cp:String; if (quote > 0) { - lines[i] = "-cp \"" + hxmlDirectory + "/" + lines[i].substr(quote + 1); + cp = lines[i].substring(quote + 1, lines[i].lastIndexOf("\"")); } else { - lines[i] = "-cp " + hxmlDirectory + "/" + lines[i].substr(4); + cp = lines[i].substr("-cp ".length); } + + lines[i] = "-cp \"" + Path.normalize(hxmlDirectory + "/" + cp) + "\""; } }