Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for scoped setups #18

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion scripts/AliasScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")));
}
}
51 changes: 48 additions & 3 deletions src/hxp/HXML.hx
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ abstract HXML(Array<String>)
/**
Builds the current HXML using Haxe.
**/
public function build():Int
public function build(workingDirectory:String = ""):Int
{
return System.runCommand("", "haxe " + this.join(" "));
return System.runCommand(workingDirectory, "haxe " + this.join(" "));
}

/**
Expand Down Expand Up @@ -390,6 +390,46 @@ abstract HXML(Array<String>)
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 (hxml == null)
{
Log.error("The specified target path \"" + path + "\" does not exist");
}

if (fromDirectory != "" && fromDirectory != hxmlDirectory)
{
var lines:Array<String> = cast hxml;

for (i in 0...lines.length)
{
if (lines[i].indexOf("-cp ") == 0)
{
var quote:Int = lines[i].indexOf('"');
var cp:String;

if (quote > 0)
{
cp = lines[i].substring(quote + 1, lines[i].lastIndexOf("\""));
}
else
{
cp = lines[i].substr("-cp ".length);
}

lines[i] = "-cp \"" + Path.normalize(hxmlDirectory + "/" + cp) + "\"";
}
}

lines.push('-cp "$hxmlDirectory"');
}

return hxml.build(fromDirectory);
}

public static function fromFile(path:String):HXML
{
if (FileSystem.exists(path))
Expand All @@ -410,7 +450,12 @@ abstract HXML(Array<String>)

for (line in lines)
{
value.push(StringTools.trim(line));
line = StringTools.trim(line);

if (!StringTools.startsWith(line, "#"))
{
value.push(line);
}
}
}

Expand Down
34 changes: 12 additions & 22 deletions src/hxp/Haxelib.hx
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class Haxelib

public static function runCommand(path:String, args:Array<String>, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false):Int
{
var command:String;

if (pathOverrides.exists("haxelib"))
{
var script = Path.combine(pathOverrides.get("haxelib"), "run.n");
Expand All @@ -414,26 +416,21 @@ class Haxelib
Log.error("Cannot find haxelib script: " + script);
}

return System.runCommand(path, "neko", [script].concat(args), safeExecute, ignoreErrors, print);
command = 'neko "$script"';
}
else
{
// var haxe = Sys.getEnv ("HAXEPATH");
var command = "haxelib";

// if (haxe != null) {

// command = Path.combine (haxe, command);

// }

return System.runCommand(path, command, args, safeExecute, ignoreErrors, print);
command = "haxelib";
}

return System.runCommand(path, command + " " + args.join(" "), safeExecute, ignoreErrors, print);
}

public static function runProcess(path:String, args:Array<String>, 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");
Expand All @@ -443,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);
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);
command = "haxelib";
}

return System.runProcess(path, command + " " + args.join(" "), waitForOutput, safeExecute, ignoreErrors, print, returnErrorValue);
}

public static function setOverridePath(haxelib:Haxelib, path:String):Void
Expand Down
2 changes: 1 addition & 1 deletion src/hxp/PlatformTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/hxp/System.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,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 == "") {
Expand Down