From 041db4d98e6369ed858d106a63f48e6552c1ab09 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 16 Aug 2017 10:57:01 -0700 Subject: [PATCH] Allow fallback to alternate tools if setting HAXELIB_PATH in project --- lime/project/HXProject.hx | 1 + lime/project/ProjectXMLParser.hx | 27 ++++++++++++++++++++++++--- lime/tools/helpers/HaxelibHelper.hx | 4 ++-- tools/CommandLineTools.hx | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lime/project/HXProject.hx b/lime/project/HXProject.hx index 9a7499255..fa25e2fb4 100644 --- a/lime/project/HXProject.hx +++ b/lime/project/HXProject.hx @@ -70,6 +70,7 @@ class HXProject { private var defaultApp:ApplicationData; private var defaultMeta:MetaData; private var defaultWindow:WindowData; + private var needRerun:Bool; public static var _command:String; public static var _debug:Bool; diff --git a/lime/project/ProjectXMLParser.hx b/lime/project/ProjectXMLParser.hx index d08b514f4..f7ff7049a 100644 --- a/lime/project/ProjectXMLParser.hx +++ b/lime/project/ProjectXMLParser.hx @@ -1163,9 +1163,30 @@ class ProjectXMLParser extends HXProject { var name = substitute (element.att.name); - defines.set (name, value); - environment.set (name, value); - setenv (name, value); + if (name == "HAXELIB_PATH") { + + var currentPath = HaxelibHelper.getRepositoryPath (); + + defines.set (name, value); + environment.set (name, value); + setenv (name, value); + + var newPath = HaxelibHelper.getRepositoryPath (true); + + if (currentPath != newPath) { + + needRerun = true; + return; + + } + + } else { + + defines.set (name, value); + environment.set (name, value); + setenv (name, value); + + } case "error": diff --git a/lime/tools/helpers/HaxelibHelper.hx b/lime/tools/helpers/HaxelibHelper.hx index cd9adfe59..c52fb0e13 100644 --- a/lime/tools/helpers/HaxelibHelper.hx +++ b/lime/tools/helpers/HaxelibHelper.hx @@ -81,9 +81,9 @@ class HaxelibHelper { } - public static function getRepositoryPath ():String { + public static function getRepositoryPath (clearCache:Bool = false):String { - if (repositoryPath == null) { + if (repositoryPath == null || clearCache) { var cache = LogHelper.verbose; LogHelper.verbose = debug; diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index 14415859e..bb1b39a08 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -20,6 +20,8 @@ import utils.CreateTemplate; import utils.JavaExternGenerator; import utils.PlatformSetup; +@:access(lime.project.HXProject) + class CommandLineTools { @@ -1695,6 +1697,30 @@ class CommandLineTools { } + if (project != null && project.needRerun && !project.targetFlags.exists ("norerun")) { + + HaxelibHelper.pathOverrides.remove ("lime"); + var workingDirectory = Sys.getCwd (); + var limePath = HaxelibHelper.getPath (new Haxelib ("lime"), true, true); + Sys.setCwd (workingDirectory); + + LogHelper.info ("", LogHelper.accentColor + "Requesting alternate tools from custom haxelib path...\x1b[0m\n\n"); + + var args = Sys.args (); + args.pop (); + + Sys.setCwd (limePath); + + args = [ PathHelper.combine (limePath, "run.n") ].concat (args); + args.push ("--haxelib-lime=" + limePath); + args.push ("-norerun"); + args.push (workingDirectory); + + Sys.exit (Sys.command ("neko", args)); + return null; + + } + if (project == null || (command != "rebuild" && project.sources.length == 0 && !FileSystem.exists (project.app.main + ".hx"))) { LogHelper.error ("You must have a \"project.xml\" file or specify another valid project file when using the '" + command + "' command");