diff --git a/lime/project/HXProject.hx b/lime/project/HXProject.hx index 3d1172013..876fed0cc 100644 --- a/lime/project/HXProject.hx +++ b/lime/project/HXProject.hx @@ -71,6 +71,7 @@ class HXProject { public static var _command:String; public static var _debug:Bool; + public static var _environment:Map; public static var _target:Platform; public static var _targetFlags:Map; public static var _templatePaths:Array; @@ -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 (); - environment = Sys.environment (); + + if (_environment != null) { + + environment = _environment; + + } else { + + environment = Sys.environment (); + + } + haxedefs = new Map (); haxeflags = new Array (); haxelibs = new Array (); @@ -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 = []; try { diff --git a/lime/project/ProjectXMLParser.hx b/lime/project/ProjectXMLParser.hx index 44fe35e35..5e46489b1 100644 --- a/lime/project/ProjectXMLParser.hx +++ b/lime/project/ProjectXMLParser.hx @@ -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 (); } diff --git a/lime/tools/helpers/HaxelibHelper.hx b/lime/tools/helpers/HaxelibHelper.hx new file mode 100644 index 000000000..f76d1b105 --- /dev/null +++ b/lime/tools/helpers/HaxelibHelper.hx @@ -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 ""; + + } + + +} \ No newline at end of file diff --git a/lime/tools/helpers/ProcessHelper.hx b/lime/tools/helpers/ProcessHelper.hx index 5c5474e39..a4b910c49 100644 --- a/lime/tools/helpers/ProcessHelper.hx +++ b/lime/tools/helpers/ProcessHelper.hx @@ -248,7 +248,7 @@ class ProcessHelper { } - public static function runProcess (path:String, command:String, args:Array , waitForOutput:Bool = true, safeExecute:Bool = true, ignoreErrors:Bool = false, print:Bool = false):String { + 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 { 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, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool):String { + private static function _runProcess (path:String, command:String, args:Array, waitForOutput:Bool, safeExecute:Bool, ignoreErrors:Bool, returnErrorValue:Bool):String { var oldPath:String = ""; @@ -376,15 +376,15 @@ class ProcessHelper { } result = process.exitCode (); - process.close(); + process.close (); - //if (result == 0) { + output = buffer.getBytes ().toString (); + + if (output == "") { - output = buffer.getBytes ().toString (); + var error = process.stderr.readAll ().toString (); - if (output == "") { - - var error = process.stderr.readAll ().toString (); + if (result != 0 || error != "") { if (ignoreErrors) { @@ -400,17 +400,25 @@ class ProcessHelper { } - return null; - - /*if (error != "") { + if (returnErrorValue) { - LogHelper.error (error); + return output; - }*/ + } else { + + return null; + + } } - //} + /*if (error != "") { + + LogHelper.error (error); + + }*/ + + } } diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index 13e92985e..5d11cb3d5 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -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; @@ -20,8 +19,8 @@ import utils.publish.*; import utils.CreateTemplate; import utils.JavaExternGenerator; import utils.PlatformSetup; - - + + class CommandLineTools { @@ -32,6 +31,7 @@ class CommandLineTools { private var additionalArguments:Array ; private var command:String; private var debug:Bool; + private var environment:Map; private var includePaths:Array ; private var overrides:HXProject; private var project:HXProject; @@ -48,6 +48,7 @@ class CommandLineTools { additionalArguments = new Array (); command = ""; debug = false; + environment = Sys.environment (); includePaths = new Array (); projectDefines = new Map (); targetFlags = new Map (); @@ -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); + } } - // TODO: Nicer solution + // Not sure why this gets no output? - if (Sys.getEnv ("HAXE_STD_PATH") == null && !userDefines.exists ("HAXE_STD_PATH")) { + //var haxeVersion = ProcessHelper.runProcess ("", "haxe", [ "-version" ], true, true, true); + //environment.set ("haxe", haxeVersion); + //environment.set ("haxe_ver", haxeVersion); + + 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,9 +1424,10 @@ class CommandLineTools { HXProject._command = command; HXProject._debug = debug; + HXProject._environment = environment; HXProject._target = target; HXProject._targetFlags = targetFlags; - HXProject._userDefines = userDefines; + HXProject._userDefines = userDefines; try { Sys.setCwd (Path.directory (projectFile)); } catch (e:Dynamic) {}