Add support for ${var >= value} and other comparisons in XML project files
This commit is contained in:
@@ -71,6 +71,7 @@ class HXProject {
|
||||
|
||||
public static var _command:String;
|
||||
public static var _debug:Bool;
|
||||
public static var _environment:Map<String, String>;
|
||||
public static var _target:Platform;
|
||||
public static var _targetFlags:Map<String, String>;
|
||||
public static var _templatePaths:Array<String>;
|
||||
@@ -95,6 +96,7 @@ class HXProject {
|
||||
HXProject._targetFlags = Unserializer.run (args[4]);
|
||||
HXProject._templatePaths = Unserializer.run (args[5]);
|
||||
if (args.length > 6) HXProject._userDefines = Unserializer.run (args[6]);
|
||||
if (args.length > 7) HXProject._environment = Unserializer.run (args[7]);
|
||||
|
||||
initialize ();
|
||||
|
||||
@@ -227,7 +229,17 @@ class HXProject {
|
||||
}
|
||||
|
||||
dependencies = new Array <Dependency> ();
|
||||
|
||||
if (_environment != null) {
|
||||
|
||||
environment = _environment;
|
||||
|
||||
} else {
|
||||
|
||||
environment = Sys.environment ();
|
||||
|
||||
}
|
||||
|
||||
haxedefs = new Map <String, Dynamic> ();
|
||||
haxeflags = new Array <String> ();
|
||||
haxelibs = new Array <Haxelib> ();
|
||||
@@ -453,7 +465,7 @@ class HXProject {
|
||||
FileHelper.copyFile (path, classFile);
|
||||
|
||||
ProcessHelper.runCommand ("", "haxe", [ name, "-main", "lime.project.HXProject", "-cp", tempDirectory, "-neko", nekoOutput, "-cp", PathHelper.combine (PathHelper.getHaxelib (new Haxelib ("lime")), "tools"), "-lib", "lime", "-D", "lime-curl", "-D", "native", "-D", "lime-native", "-D", "lime-cffi" ]);
|
||||
ProcessHelper.runCommand ("", "neko", [ FileSystem.fullPath (nekoOutput), HXProject._command, name, Std.string (HXProject._target), Std.string (HXProject._debug), Serializer.run (HXProject._targetFlags), Serializer.run (HXProject._templatePaths), Serializer.run (HXProject._userDefines), temporaryFile ]);
|
||||
ProcessHelper.runCommand ("", "neko", [ FileSystem.fullPath (nekoOutput), HXProject._command, name, Std.string (HXProject._target), Std.string (HXProject._debug), Serializer.run (HXProject._targetFlags), Serializer.run (HXProject._templatePaths), Serializer.run (HXProject._userDefines), Serializer.run (HXProject._environment), temporaryFile ]);
|
||||
|
||||
var tPaths:Array<String> = [];
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,7 @@ import haxe.io.Path;
|
||||
import haxe.xml.Fast;
|
||||
import lime.tools.helpers.ArrayHelper;
|
||||
import lime.tools.helpers.CommandHelper;
|
||||
import lime.tools.helpers.HaxelibHelper;
|
||||
import lime.tools.helpers.LogHelper;
|
||||
import lime.tools.helpers.ObjectHelper;
|
||||
import lime.tools.helpers.PathHelper;
|
||||
@@ -180,7 +181,11 @@ class ProjectXMLParser extends HXProject {
|
||||
required = substitute (required);
|
||||
var check = StringTools.trim (required);
|
||||
|
||||
if (check != "" && !defines.exists (check) && (environment == null || !environment.exists (check)) && check != command) {
|
||||
if (check == "false") {
|
||||
|
||||
matchRequired = false;
|
||||
|
||||
} else if (check != "" && check != "true" && !defines.exists (check) && (environment == null || !environment.exists (check)) && check != command) {
|
||||
|
||||
matchRequired = false;
|
||||
|
||||
@@ -1261,6 +1266,7 @@ class ProjectXMLParser extends HXProject {
|
||||
|
||||
}
|
||||
|
||||
defines.set (haxelib.name, HaxelibHelper.getVersion (haxelib));
|
||||
haxelibs.push (haxelib);
|
||||
|
||||
var includeProject = HXProject.fromHaxelib (haxelib, defines);
|
||||
@@ -2077,53 +2083,83 @@ class ProjectXMLParser extends HXProject {
|
||||
}
|
||||
|
||||
|
||||
private function replaceVariable (string:String):String {
|
||||
|
||||
if (string.substr (0, 8) == "haxelib:") {
|
||||
|
||||
var path = PathHelper.getHaxelib (new Haxelib (string.substr (8)), true);
|
||||
return PathHelper.standardize (path);
|
||||
|
||||
} else if (defines.exists (string)) {
|
||||
|
||||
return defines.get (string);
|
||||
|
||||
} else if (environment != null && environment.exists (string)) {
|
||||
|
||||
return environment.get (string);
|
||||
|
||||
} else {
|
||||
|
||||
var substring = StringTools.replace (string, " ", "");
|
||||
var index, value;
|
||||
|
||||
if (substring.indexOf ("==") > -1) {
|
||||
|
||||
index = substring.indexOf ("==");
|
||||
value = replaceVariable (substring.substr (0, index));
|
||||
|
||||
return Std.string (value == substring.substr (index + 2));
|
||||
|
||||
} else if (substring.indexOf ("<=") > -1) {
|
||||
|
||||
index = substring.indexOf ("<=");
|
||||
value = replaceVariable (substring.substr (0, index));
|
||||
|
||||
return Std.string (value <= substring.substr (index + 2));
|
||||
|
||||
} else if (substring.indexOf ("<") > -1) {
|
||||
|
||||
index = substring.indexOf ("<");
|
||||
value = replaceVariable (substring.substr (0, index));
|
||||
|
||||
return Std.string (value < substring.substr (index + 1));
|
||||
|
||||
} else if (substring.indexOf (">=") > -1) {
|
||||
|
||||
index = substring.indexOf (">=");
|
||||
value = replaceVariable (substring.substr (0, index));
|
||||
|
||||
return Std.string (value >= substring.substr (index + 2));
|
||||
|
||||
} else if (substring.indexOf (">") > -1) {
|
||||
|
||||
index = substring.indexOf (">");
|
||||
value = replaceVariable (substring.substr (0, index));
|
||||
|
||||
return Std.string (value > substring.substr (index + 1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function substitute (string:String):String {
|
||||
|
||||
var newString = string;
|
||||
|
||||
while (doubleVarMatch.match (newString)) {
|
||||
|
||||
var substring = doubleVarMatch.matched (1);
|
||||
|
||||
if (substring.substr (0, 8) == "haxelib:") {
|
||||
|
||||
var path = PathHelper.getHaxelib (new Haxelib (substring.substr (8)), true);
|
||||
substring = PathHelper.standardize (path);
|
||||
|
||||
} else if (defines.exists (substring)) {
|
||||
|
||||
substring = defines.get (substring);
|
||||
|
||||
} else if (environment != null && environment.exists (substring)) {
|
||||
|
||||
substring = environment.get (substring);
|
||||
|
||||
}
|
||||
|
||||
newString = doubleVarMatch.matchedLeft () + "${" + substring + "}" + doubleVarMatch.matchedRight ();
|
||||
newString = doubleVarMatch.matchedLeft () + "${" + replaceVariable (doubleVarMatch.matched (1)) + "}" + doubleVarMatch.matchedRight ();
|
||||
|
||||
}
|
||||
|
||||
while (varMatch.match (newString)) {
|
||||
|
||||
var substring = varMatch.matched (1);
|
||||
|
||||
if (substring.substr (0, 8) == "haxelib:") {
|
||||
|
||||
var path = PathHelper.getHaxelib (new Haxelib (substring.substr (8)), true);
|
||||
substring = PathHelper.standardize (path);
|
||||
|
||||
} else if (defines.exists (substring)) {
|
||||
|
||||
substring = defines.get (substring);
|
||||
|
||||
} else if (environment != null && environment.exists (substring)) {
|
||||
|
||||
substring = environment.get (substring);
|
||||
|
||||
}
|
||||
|
||||
newString = varMatch.matchedLeft () + substring + varMatch.matchedRight ();
|
||||
newString = varMatch.matchedLeft () + replaceVariable (varMatch.matched (1)) + varMatch.matchedRight ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
41
lime/tools/helpers/HaxelibHelper.hx
Normal file
41
lime/tools/helpers/HaxelibHelper.hx
Normal file
@@ -0,0 +1,41 @@
|
||||
package lime.tools.helpers;
|
||||
|
||||
|
||||
import haxe.Json;
|
||||
import lime.project.Haxelib;
|
||||
import sys.io.File;
|
||||
import sys.FileSystem;
|
||||
|
||||
|
||||
class HaxelibHelper {
|
||||
|
||||
|
||||
public static function getVersion (haxelib:Haxelib = null):String {
|
||||
|
||||
if (haxelib == null) {
|
||||
|
||||
haxelib = new Haxelib ("lime");
|
||||
|
||||
}
|
||||
|
||||
if (haxelib.version != "") {
|
||||
|
||||
return haxelib.version;
|
||||
|
||||
}
|
||||
|
||||
var path = PathHelper.getHaxelib (haxelib, true) + "/haxelib.json";
|
||||
|
||||
if (FileSystem.exists (path)) {
|
||||
|
||||
var json = Json.parse (File.getContent (path));
|
||||
return json.version;
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -248,7 +248,7 @@ class ProcessHelper {
|
||||
}
|
||||
|
||||
|
||||
public static function runProcess (path:String, command:String, args:Array <String>, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false):String {
|
||||
public static function runProcess (path:String, command:String, args:Array <String>, waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false, returnErrorValue:Bool = false):String {
|
||||
|
||||
if (print) {
|
||||
|
||||
@@ -284,7 +284,7 @@ class ProcessHelper {
|
||||
|
||||
}
|
||||
|
||||
return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors);
|
||||
return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue);
|
||||
|
||||
} catch (e:Dynamic) {
|
||||
|
||||
@@ -300,14 +300,14 @@ class ProcessHelper {
|
||||
|
||||
} else {
|
||||
|
||||
return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors);
|
||||
return _runProcess (path, command, args, waitForOutput, safeExecute, ignoreErrors, returnErrorValue);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function _runProcess (path:String, command:String, args:Array<String>, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool):String {
|
||||
private static function _runProcess (path:String, command:String, args:Array<String>, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool, returnErrorValue:Bool):String {
|
||||
|
||||
var oldPath:String = "";
|
||||
|
||||
@@ -376,9 +376,7 @@ class ProcessHelper {
|
||||
}
|
||||
|
||||
result = process.exitCode ();
|
||||
process.close();
|
||||
|
||||
//if (result == 0) {
|
||||
process.close ();
|
||||
|
||||
output = buffer.getBytes ().toString ();
|
||||
|
||||
@@ -386,6 +384,8 @@ class ProcessHelper {
|
||||
|
||||
var error = process.stderr.readAll ().toString ();
|
||||
|
||||
if (result != 0 || error != "") {
|
||||
|
||||
if (ignoreErrors) {
|
||||
|
||||
output = error;
|
||||
@@ -400,8 +400,18 @@ class ProcessHelper {
|
||||
|
||||
}
|
||||
|
||||
if (returnErrorValue) {
|
||||
|
||||
return output;
|
||||
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*if (error != "") {
|
||||
|
||||
LogHelper.error (error);
|
||||
@@ -410,8 +420,6 @@ class ProcessHelper {
|
||||
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
if (oldPath != "") {
|
||||
|
||||
@@ -4,7 +4,6 @@ package;
|
||||
//import openfl.text.Font;
|
||||
//import openfl.utils.ByteArray;
|
||||
//import openfl.utils.CompressionAlgorithm;
|
||||
import haxe.Json;
|
||||
import haxe.Serializer;
|
||||
import haxe.Unserializer;
|
||||
import haxe.io.Path;
|
||||
@@ -32,6 +31,7 @@ class CommandLineTools {
|
||||
private var additionalArguments:Array <String>;
|
||||
private var command:String;
|
||||
private var debug:Bool;
|
||||
private var environment:Map<String, String>;
|
||||
private var includePaths:Array <String>;
|
||||
private var overrides:HXProject;
|
||||
private var project:HXProject;
|
||||
@@ -48,6 +48,7 @@ class CommandLineTools {
|
||||
additionalArguments = new Array <String> ();
|
||||
command = "";
|
||||
debug = false;
|
||||
environment = Sys.environment ();
|
||||
includePaths = new Array <String> ();
|
||||
projectDefines = new Map <String, String> ();
|
||||
targetFlags = new Map <String, String> ();
|
||||
@@ -61,7 +62,7 @@ class CommandLineTools {
|
||||
PathHelper.haxelibOverrides.set ("lime-tools", PathHelper.combine (PathHelper.getHaxelib (new Haxelib ("lime")), "tools"));
|
||||
|
||||
processArguments ();
|
||||
version = getVersion ();
|
||||
version = HaxelibHelper.getVersion ();
|
||||
|
||||
if (targetFlags.exists ("openfl")) {
|
||||
|
||||
@@ -266,9 +267,11 @@ class CommandLineTools {
|
||||
}
|
||||
|
||||
HXProject._command = command;
|
||||
HXProject._environment = environment;
|
||||
HXProject._debug = debug;
|
||||
HXProject._target = target;
|
||||
HXProject._targetFlags = targetFlags;
|
||||
HXProject._userDefines = userDefines;
|
||||
|
||||
var project = null;
|
||||
|
||||
@@ -885,7 +888,7 @@ class CommandLineTools {
|
||||
LogHelper.println ("\x1b[37m 888 \x1b[0m");
|
||||
|
||||
LogHelper.println ("");
|
||||
LogHelper.println ("\x1b[1mOpenFL Command-Line Tools\x1b[0;1m (" + getVersion (new Haxelib ("openfl")) + "-L" + StringHelper.generateUUID (5, null, StringHelper.generateHashCode (version)) + ")\x1b[0m");
|
||||
LogHelper.println ("\x1b[1mOpenFL Command-Line Tools\x1b[0;1m (" + HaxelibHelper.getVersion (new Haxelib ("openfl")) + "-L" + StringHelper.generateUUID (5, null, StringHelper.generateHashCode (version)) + ")\x1b[0m");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -1206,20 +1209,6 @@ class CommandLineTools {
|
||||
}
|
||||
|
||||
|
||||
private function getVersion (haxelib:Haxelib = null):String {
|
||||
|
||||
if (haxelib == null) {
|
||||
|
||||
haxelib = new Haxelib ("lime");
|
||||
|
||||
}
|
||||
|
||||
var json = Json.parse (File.getContent (PathHelper.getHaxelib (haxelib, true) + "/haxelib.json"));
|
||||
return json.version;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function initializeProject (project:HXProject = null, targetName:String = ""):HXProject {
|
||||
|
||||
LogHelper.info ("", LogHelper.accentColor + "Initializing project..." + LogHelper.resetColor);
|
||||
@@ -1377,45 +1366,53 @@ class CommandLineTools {
|
||||
|
||||
if (PlatformHelper.hostPlatform == Platform.WINDOWS) {
|
||||
|
||||
if (Sys.getEnv ("JAVA_HOME") != null) {
|
||||
if (environment.get ("JAVA_HOME") != null) {
|
||||
|
||||
var javaPath = PathHelper.combine (Sys.getEnv ("JAVA_HOME"), "bin");
|
||||
var javaPath = PathHelper.combine (environment.get ("JAVA_HOME"), "bin");
|
||||
var value;
|
||||
|
||||
if (PlatformHelper.hostPlatform == Platform.WINDOWS) {
|
||||
|
||||
Sys.putEnv ("PATH", javaPath + ";" + Sys.getEnv ("PATH"));
|
||||
value = javaPath + ";" + Sys.getEnv ("PATH");
|
||||
|
||||
} else {
|
||||
|
||||
Sys.putEnv ("PATH", javaPath + ":" + Sys.getEnv ("PATH"));
|
||||
value = javaPath + ":" + Sys.getEnv ("PATH");
|
||||
|
||||
}
|
||||
|
||||
environment.set ("PATH", value);
|
||||
Sys.putEnv ("PATH", value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// Not sure why this gets no output?
|
||||
|
||||
// TODO: Nicer solution
|
||||
//var haxeVersion = ProcessHelper.runProcess ("", "haxe", [ "-version" ], true, true, true);
|
||||
//environment.set ("haxe", haxeVersion);
|
||||
//environment.set ("haxe_ver", haxeVersion);
|
||||
|
||||
if (Sys.getEnv ("HAXE_STD_PATH") == null && !userDefines.exists ("HAXE_STD_PATH")) {
|
||||
if (!environment.exists ("HAXE_STD_PATH")) {
|
||||
|
||||
if (PlatformHelper.hostPlatform == Platform.WINDOWS) {
|
||||
|
||||
userDefines.set ("HAXE_STD_PATH", "C:\\HaxeToolkit\\haxe\\std\\");
|
||||
environment.set ("HAXE_STD_PATH", "C:\\HaxeToolkit\\haxe\\std\\");
|
||||
|
||||
} else {
|
||||
|
||||
if (FileSystem.exists ("/usr/lib/haxe")) {
|
||||
|
||||
userDefines.set ("HAXE_STD_PATH", "/usr/lib/haxe/std");
|
||||
environment.set ("HAXE_STD_PATH", "/usr/lib/haxe/std");
|
||||
|
||||
} else if (FileSystem.exists ("/usr/share/haxe")) {
|
||||
|
||||
userDefines.set ("HAXE_STD_PATH", "/usr/share/haxe/std");
|
||||
environment.set ("HAXE_STD_PATH", "/usr/share/haxe/std");
|
||||
|
||||
} else {
|
||||
|
||||
userDefines.set ("HAXE_STD_PATH", "/usr/local/lib/haxe/std");
|
||||
environment.set ("HAXE_STD_PATH", "/usr/local/lib/haxe/std");
|
||||
|
||||
}
|
||||
|
||||
@@ -1427,6 +1424,7 @@ class CommandLineTools {
|
||||
|
||||
HXProject._command = command;
|
||||
HXProject._debug = debug;
|
||||
HXProject._environment = environment;
|
||||
HXProject._target = target;
|
||||
HXProject._targetFlags = targetFlags;
|
||||
HXProject._userDefines = userDefines;
|
||||
|
||||
Reference in New Issue
Block a user