diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index a40e002d1..c47d56c3e 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -9,7 +9,6 @@ import haxe.Unserializer; import haxe.io.Path; import haxe.rtti.Meta; import hxp.helpers.*; -import hxp.platforms.*; import hxp.project.*; import lime.system.CFFI; import sys.io.File; @@ -24,12 +23,12 @@ import utils.PlatformSetup; class CommandLineTools { - - + + public static var commandName = "lime"; public static var defaultLibrary = "lime"; public static var defaultLibraryName = "Lime"; - + private var additionalArguments:Array; private var command:String; private var debug:Bool; @@ -44,10 +43,10 @@ class CommandLineTools { private var userDefines:Map; private var version:String; private var words:Array; - - + + public function new () { - + additionalArguments = new Array (); command = ""; debug = false; @@ -58,837 +57,837 @@ class CommandLineTools { traceEnabled = true; userDefines = new Map (); words = new Array (); - + overrides = new HXProject (); overrides.architectures = []; - + //HaxelibHelper.setOverridePath (new Haxelib ("lime-tools"), PathHelper.combine (HaxelibHelper.getPath (new Haxelib ("lime")), "tools")); - + processArguments (); version = HaxelibHelper.getVersion (); - + if (targetFlags.exists ("openfl")) { - + LogHelper.accentColor = "\x1b[36;1m"; commandName = "openfl"; defaultLibrary = "openfl"; defaultLibraryName = "OpenFL"; - + } - + if (command == "" && targetFlags.exists ("help")) { - + command = "help"; - + } - + if (LogHelper.verbose && command != "help" && command != "") { - + displayInfo (); Sys.println (""); - + } - + switch (command) { - + case "": - + if (targetFlags.exists ("version")) { - + Sys.println (getToolsVersion ()); return; - + } - + displayInfo (true); - + case "help": - + displayHelp (); - + case "config": - + displayConfig (); - + case "setup": - + platformSetup (); - + case "document": - + document (); - + case "generate": - + generate (); - + case "compress": - + compress (); - + case "create": - + createTemplate (); - + case "install", "remove", "upgrade": - + updateLibrary (); - + case "clean", "update", "display", "build", "run", "rerun", /*"install",*/ "uninstall", "trace", "test", "deploy": - + if (words.length < 1 || words.length > 2) { - + LogHelper.error ("Incorrect number of arguments for command '" + command + "'"); return; - + } - + var project = initializeProject (); buildProject (project); - + case "rebuild": - + if (words.length < 1 || words.length > 2) { - + LogHelper.error ("Incorrect number of arguments for command '" + command + "'"); return; - + } - + if (words.length == 1) { - + var haxelibPath = HaxelibHelper.getPath (new Haxelib (words[0]), false); - + if (haxelibPath != "" && haxelibPath != null) { - + words.push ("tools"); - + } - + } - + if (words.length < 2) { - + if (targetFlags.exists ("openfl")) { - + words.unshift ("openfl"); - + } else { - + words.unshift ("lime"); - + } - + } - + var targets = words[1].split (","); - + var haxelib = null; var path = null; var hxmlPath = null; var project = null; - + if (!FileSystem.exists (words[0])) { - + var fullPath = PathHelper.tryFullPath (words[0]); - + if (FileSystem.exists (fullPath)) { - + path = PathHelper.combine (fullPath, "project"); hxmlPath = PathHelper.combine (fullPath, "rebuild.hxml"); - + } else { - + haxelib = new Haxelib (words[0]); - + } - + } else { - + if (FileSystem.isDirectory (words[0])) { - + if (FileSystem.exists (PathHelper.combine (words[0], "Build.xml"))) { - + path = words[0]; - + } else { - + path = PathHelper.combine (words[0], "project/Build.xml"); - + } - + hxmlPath = PathHelper.combine (words[0], "rebuild.hxml"); - + } else { - + path = words[0]; - + if (Path.extension (words[0]) == "hxml") { - + hxmlPath = words[0]; - + } - + } - + var haxelibPath = HaxelibHelper.getPath (new Haxelib (words[0])); - + if (!FileSystem.exists (path) && haxelibPath != null) { - + haxelib = new Haxelib (words[0]); - + } - + } - + if (haxelib != null) { - + var haxelibPath = HaxelibHelper.getPath (haxelib, true); - + switch (haxelib.name) { - + case "hxcpp": - + hxmlPath = PathHelper.combine (haxelibPath, "tools/hxcpp/compile.hxml"); - + case "haxelib": - + hxmlPath = PathHelper.combine (haxelibPath, "../client.hxml"); - + default: - + hxmlPath = PathHelper.combine (haxelibPath, "rebuild.hxml"); - + } - + } - + for (targetName in targets) { var target = null; - + switch (targetName) { - + case "cpp": - + target = PlatformHelper.hostPlatform; targetFlags.set ("cpp", ""); - + case "neko": - + target = PlatformHelper.hostPlatform; targetFlags.set ("neko", ""); - + case "hl": - + target = PlatformHelper.hostPlatform; targetFlags.set ("hl", ""); - + case "java": - + target = PlatformHelper.hostPlatform; targetFlags.set ("java", ""); - + case "nodejs": - + target = PlatformHelper.hostPlatform; targetFlags.set ("nodejs", ""); - + case "cs": - + target = PlatformHelper.hostPlatform; targetFlags.set ("cs", ""); - + case "iphone", "iphoneos": - + target = Platform.IOS; - + case "iphonesim": - + target = Platform.IOS; targetFlags.set ("simulator", ""); - + case "electron": - + target = Platform.HTML5; targetFlags.set ("electron", ""); - + case "firefox", "firefoxos": - + target = Platform.FIREFOX; overrides.haxedefs.set ("firefoxos", ""); - + case "appletv", "appletvos": - + target = Platform.TVOS; - + case "appletvsim": - + target = Platform.TVOS; targetFlags.set ("simulator", ""); - + case "mac", "macos": - + target = Platform.MAC; - + case "rpi", "raspberrypi": - + target = Platform.LINUX; targetFlags.set ("rpi", ""); - + case "webassembly", "wasm": - + target = Platform.EMSCRIPTEN; targetFlags.set ("webassembly", ""); - + default: - + target = cast targetName.toLowerCase (); - + } - + if (target == cast "tools") { - + if (hxmlPath != null && FileSystem.exists (hxmlPath)) { - + var cacheValue = Sys.getEnv ("HAXELIB_PATH"); Sys.putEnv ("HAXELIB_PATH", HaxelibHelper.getRepositoryPath ()); - + ProcessHelper.runCommand (Path.directory (hxmlPath), "haxe", [ Path.withoutDirectory (hxmlPath) ]); - + if (cacheValue != null) { - + Sys.putEnv ("HAXELIB_PATH", cacheValue); - + } - + } - + } else { - + HXProject._command = command; HXProject._environment = environment; HXProject._debug = debug; HXProject._target = target; HXProject._targetFlags = targetFlags; HXProject._userDefines = userDefines; - + var project = null; - + if (haxelib != null) { - + userDefines.set ("rebuild", 1); project = HXProject.fromHaxelib (haxelib, userDefines); - + if (project == null) { - + project = new HXProject (); project.config.set ("project.rebuild.path", PathHelper.combine (HaxelibHelper.getPath (haxelib), "project")); - + } else { - + project.config.set ("project.rebuild.path", PathHelper.combine (HaxelibHelper.getPath (haxelib), project.config.get ("project.rebuild.path"))); - + } - + } else { - + //project = HXProject.fromPath (path); - + if (project == null) { - + project = new HXProject (); - + if (FileSystem.isDirectory (path)) { - + project.config.set ("project.rebuild.path", path); - + } else { - + project.config.set ("project.rebuild.path", Path.directory (path)); project.config.set ("project.rebuild.file", Path.withoutDirectory (path)); - + } - + } - + } - + // this needs to be improved - + var rebuildPath = project.config.get ("project.rebuild.path"); var rebuildFile = project.config.get ("project.rebuild.file"); - + project.merge (overrides); - + for (haxelib in overrides.haxelibs) { - + var includeProject = HXProject.fromHaxelib (haxelib, project.defines); - + if (includeProject != null) { - + for (ndll in includeProject.ndlls) { - + if (ndll.haxelib == null) { - + ndll.haxelib = haxelib; - + } - + } - + project.merge (includeProject); - + } - + } - + project.config.set ("project.rebuild.path", rebuildPath); project.config.set ("project.rebuild.file", rebuildFile); - + // TODO: Fix use of initialize without resetting reference? - + project = initializeProject (project, targetName); buildProject (project); - + if (LogHelper.verbose) { - + LogHelper.println (""); - + } - + } - + } - + case "publish": - + if (words.length < 1 || words.length > 2) { - + LogHelper.error ("Incorrect number of arguments for command '" + command + "'"); return; - + } - + publishProject (); - + case "installer", "copy-if-newer": - + // deprecated? - + default: - + LogHelper.error ("'" + command + "' is not a valid command"); - + } - + } - - + + #if (neko && (haxe_210 || haxe3)) public static function __init__ ():Void { - + var args = Sys.args (); - + if (args.length > 0 && args[0].toLowerCase () == "rebuild") { - + CFFI.enabled = false; - + } - - + + for (arg in args) { - + // TODO: Allow -rebuild without locking native binary? - + if (arg == "-nocffi" || arg == "-rebuild") { - + CFFI.enabled = false; - + } - + } - + var path = ""; - + if (FileSystem.exists ("tools.n")) { - + path = PathHelper.combine (Sys.getCwd (), "../ndll/"); - + } else if (FileSystem.exists ("run.n")) { - + path = Sys.getCwd () + "/ndll/"; - + } - + if (path == "") { - + var process = new Process ("haxelib", [ "path", "lime" ]); - + try { - + while (true) { - + var line = StringTools.trim (process.stdout.readLine ()); trace (line); if (StringTools.startsWith (line, "-L ")) { - + path = StringTools.trim (line.substr (2)); break; - + } - + } - + } catch (e:Dynamic) {} - + process.close (); - + } - + switch (PlatformHelper.hostPlatform) { - + case WINDOWS: - + untyped $loader.path = $array (path + "Windows/", $loader.path); - + case MAC: - + //if (PlatformHelper.hostArchitecture == Architecture.X64) { - + untyped $loader.path = $array (path + "Mac64/", $loader.path); - + //} else { - + // untyped $loader.path = $array (path + "Mac/", $loader.path); - + //} - + case LINUX: - + var arguments = Sys.args (); var raspberryPi = false; - + for (argument in arguments) { - + if (argument == "-rpi") raspberryPi = true; - + } - + if (raspberryPi || PlatformHelper.hostArchitecture == Architecture.ARMV6 || PlatformHelper.hostArchitecture == Architecture.ARMV7) { - + untyped $loader.path = $array (path + "RPi/", $loader.path); - + } else if (PlatformHelper.hostArchitecture == Architecture.X64) { - + untyped $loader.path = $array (path + "Linux64/", $loader.path); - + } else { - + untyped $loader.path = $array (path + "Linux/", $loader.path); - + } - + default: - + } - + } #end - - + + private function buildProject (project:HXProject, command:String = "") { - + if (command == "") { - + command = project.command.toLowerCase (); - + } - + if (project.targetHandlers.exists (Std.string (project.target))) { - + if (command == "build" || command == "test") { - + CommandHelper.executeCommands (project.preBuildCallbacks); - + } - + LogHelper.info ("", LogHelper.accentColor + "Using target platform: " + Std.string (project.target).toUpperCase () + "\x1b[0m"); - + var handler = project.targetHandlers.get (Std.string (project.target)); var projectData = Serializer.run (project); var temporaryFile = PathHelper.getTemporaryFile (); File.saveContent (temporaryFile, projectData); - + var targetDir = HaxelibHelper.getPath (new Haxelib (handler)); var exePath = Path.join ([targetDir, "run.exe"]); var exeExists = FileSystem.exists (exePath); - + var args = [ command, temporaryFile ]; - + if (LogHelper.verbose) args.push ("-verbose"); if (!LogHelper.enableColor) args.push ("-nocolor"); if (!traceEnabled) args.push ("-notrace"); - + if (additionalArguments.length > 0) { - + args.push ("-args"); args = args.concat (additionalArguments); - + } - + if (exeExists) { - + ProcessHelper.runCommand ("", exePath, args); - + } else { - + HaxelibHelper.runCommand ("", [ "run", handler ].concat (args)); - + } - + try { - + FileSystem.deleteFile (temporaryFile); - + } catch (e:Dynamic) {} - + if (command == "build" || command == "test") { - + CommandHelper.executeCommands (project.postBuildCallbacks); - + } - + } else { - + var platform:PlatformTarget = null; - + switch (project.target) { - + case ANDROID: - + platform = new AndroidPlatform (command, project, targetFlags); - + case BLACKBERRY: - + //platform = new BlackBerryPlatform (command, project, targetFlags); - + case IOS: - + platform = new IOSPlatform (command, project, targetFlags); - + case TIZEN: - + //platform = new TizenPlatform (command, project, targetFlags); - + case WEBOS: - + //platform = new WebOSPlatform (command, project, targetFlags); - + case WINDOWS: - + platform = new WindowsPlatform (command, project, targetFlags); - + case MAC: - + platform = new MacPlatform (command, project, targetFlags); - + case LINUX: - + platform = new LinuxPlatform (command, project, targetFlags); - + case FLASH: - + platform = new FlashPlatform (command, project, targetFlags); - + case HTML5: - + platform = new HTML5Platform (command, project, targetFlags); - - case FIREFOX: - - platform = new FirefoxPlatform (command, project, targetFlags); - + + // case FIREFOX: + + // platform = new FirefoxPlatform (command, project, targetFlags); + case EMSCRIPTEN: - + platform = new EmscriptenPlatform (command, project, targetFlags); - + case TVOS: - + platform = new TVOSPlatform (command, project, targetFlags); - + case AIR: - + platform = new AIRPlatform (command, project, targetFlags); - + default: - + } - + if (platform != null) { - + platform.traceEnabled = traceEnabled; platform.execute (additionalArguments); - + } else { - + LogHelper.error ("\"" + Std.string (project.target) + "\" is an unknown target"); - + } - + } - + } - - + + private function compress () { - + if (words.length > 0) { - + //var bytes = new ByteArray (); //bytes.writeUTFBytes (words[0]); //bytes.compress (CompressionAlgorithm.LZMA); //Sys.print (bytes.toString ()); //File.saveBytes (words[0] + ".compress", bytes); - + } - + } - - + + private function createTemplate () { - + LogHelper.info ("", LogHelper.accentColor + "Running command: CREATE\x1b[0m"); - + if (words.length > 0) { - + var colonIndex = words[0].indexOf (":"); - + var projectName = null; var sampleName = null; - + if (colonIndex == -1) { - + projectName = words[0]; - + if (words.length > 1) { - + sampleName = words[1]; - + } - + } else { - + projectName = words[0].substring (0, colonIndex); sampleName = words[0].substr (colonIndex + 1); - + } - + if (projectName == "project" || sampleName == "project") { - + CreateTemplate.createProject (words, userDefines, overrides); - + } else if (projectName == "extension" || sampleName == "extension") { - + CreateTemplate.createExtension (words, userDefines); - + } else { - + if (sampleName == null) { - + var sampleExists = false; var defines = new Map (); defines.set ("create", 1); var project = HXProject.fromHaxelib (new Haxelib (defaultLibrary), defines); - + for (samplePath in project.samplePaths) { - + if (FileSystem.exists (PathHelper.combine (samplePath, projectName))) { - + sampleExists = true; - + } - + } - + if (sampleExists) { - + CreateTemplate.createSample (words, userDefines); - + } else if (HaxelibHelper.getPath (new Haxelib (projectName)) != "") { - + CreateTemplate.listSamples (projectName, userDefines); - + } else if (projectName == "" || projectName == null) { - + CreateTemplate.listSamples (defaultLibrary, userDefines); - + } else { - + CreateTemplate.listSamples (null, userDefines); - + } - + } else { - + CreateTemplate.createSample (words, userDefines); - + } - + } - + } else { - + CreateTemplate.listSamples (defaultLibrary, userDefines); - + } - + } - - + + private function displayConfig ():Void { - + if (words.length == 0) { - + LogHelper.println (File.getContent (ConfigHelper.getConfigPath ())); - + } else if (words.length == 1) { - + var value = ConfigHelper.getConfigValue (words[0]); - + if (value != null) { - + LogHelper.println (value); - + } else { - + LogHelper.error ("\"" + words[0] + "\" is undefined"); - + } - + } else { - + var name = words.shift (); var value = words.join (" "); - + if (name == "remove") { - + ConfigHelper.removeConfigValue (value); - + } else { - + ConfigHelper.writeConfigValue (name, value); - + } - + } - + } - - + + private function displayHelp ():Void { - + var commands = [ - + "config" => "Display or set command-line configuration values", "create" => "Create a new project or extension using templates", "clean" => "Clean the specified project and target", @@ -905,100 +904,100 @@ class CommandLineTools { "remove" => "Remove a library from haxelib", "upgrade" => "Upgrade a library from haxelib", "setup" => "Setup " + defaultLibraryName + " or a specific platform" - + ]; - + var basicCommands = [ "config", "create", "clean", "update", "build", "run", "test", "help" ]; var additionalCommands = [ "trace", "deploy", "display", "rebuild", "install", "remove", "upgrade", "setup" ]; - + if (targetFlags.exists ("openfl")) { - + commands.set ("process", "Process a SWF asset for use with " + defaultLibraryName); additionalCommands.push ("process"); - + } - + var command = (words.length > 0 ? words[0] : ""); var isProjectCommand = false, isBuildCommand = false; - + if (commands.exists (command)) { - + LogHelper.println ("\x1b[1m" + commands.get (command) + "\x1b[0m"); LogHelper.println (""); - + } - + switch (command) { - + case "setup": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " setup\x1b[0m \x1b[3;37m(target)\x1b[0m \x1b[3;37m[options]\x1b[0m"); - + case "clean", "update", "build", "run", "test", "display", "deploy", "trace": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " " + command + "\x1b[0m \x1b[3;37m(project)\x1b[0m \x1b[1m\x1b[0m \x1b[3;37m[options]\x1b[0m"); isProjectCommand = true; isBuildCommand = true; - + case "create": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " create\x1b[0m \x1b[3;37m(library)\x1b[0m \x1b[1mproject\x1b[0m \x1b[3;37m(directory)\x1b[0m \x1b[3;37m[options]\x1b[0m"); LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " create\x1b[0m \x1b[3;37m(library)\x1b[0m \x1b[1mextension\x1b[0m \x1b[3;37m(directory)\x1b[0m \x1b[3;37m[options]\x1b[0m"); LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " create\x1b[0m \x1b[3;37m(library)\x1b[0m \x1b[1m\x1b[0m \x1b[3;37m(directory)\x1b[0m \x1b[3;37m[options]\x1b[0m"); - + case "rebuild": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " rebuild\x1b[0m \x1b[3;37m(library)\x1b[0m \x1b[3;37m(target)\x1b[0m \x1b[3;37m[options]\x1b[0m"); isBuildCommand = true; - + case "config": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " config\x1b[0m \x1b[3;37m(name)\x1b[0m \x1b[3;37m(value)\x1b[0m \x1b[3;37m[options]\x1b[0m"); LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " config remove \x1b[0m \x1b[3;37m[options]\x1b[0m"); - + case "install", "remove", "upgrade": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " " + command + "\x1b[0m \x1b[3;37m(library)\x1b[0m \x1b[3;37m[options]\x1b[0m"); - + case "process": - + LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " process \x1b[0m \x1b[3;37m(directory)\x1b[0m \x1b[3;37m[options]\x1b[0m"); - + default: - + displayInfo (); - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Usage:\x1b[0m \x1b[1m" + commandName + " \x1b[0m \x1b[3;37m[arguments]\x1b[0m"); LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Basic Commands:" + LogHelper.resetColor); LogHelper.println (""); - + for (command in basicCommands) { - + LogHelper.println (" \x1b[1m" + command + "\x1b[0m -- " + commands.get (command)); - + } - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Additional Commands:" + LogHelper.resetColor); LogHelper.println (""); - + for (command in additionalCommands) { - + LogHelper.println (" \x1b[1m" + command + "\x1b[0m -- " + commands.get (command)); - + } - + LogHelper.println (""); LogHelper.println ("For additional help, run \x1b[1m" + commandName + " help \x1b[0m"); - + return; - + } - + if (isBuildCommand || command == "setup") { - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Targets:" + LogHelper.resetColor); LogHelper.println (""); @@ -1015,7 +1014,7 @@ class CommandLineTools { LogHelper.println (" \x1b[1mtvos\x1b[0m -- Create a tvOS application"); //LogHelper.println (" \x1b[1mwebos\x1b[0m -- Create a webOS application"); LogHelper.println (" \x1b[1mwindows\x1b[0m -- Create a Windows application"); - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Target Aliases:" + LogHelper.resetColor); LogHelper.println (""); @@ -1034,61 +1033,61 @@ class CommandLineTools { LogHelper.println (" \x1b[1mrpi\x1b[0;3m/\x1b[0m\x1b[1mraspberrypi\x1b[0m -- Alias for \x1b[1mlinux -rpi\x1b[0m"); LogHelper.println (" \x1b[1melectron\x1b[0m -- Alias for \x1b[1mhtml5 -electron\x1b[0m"); LogHelper.println (" \x1b[1mwebassembly\x1b[0;3m/\x1b[0m\x1b[1mwasm\x1b[0m -- Alias for \x1b[1memscripten -webassembly\x1b[0m"); - + } - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Options:" + LogHelper.resetColor); LogHelper.println (""); - + if (isBuildCommand) { - + LogHelper.println (" \x1b[1m-D\x1b[0;3mvalue\x1b[0m -- Specify a define to use when processing other commands"); LogHelper.println (" \x1b[1m-debug\x1b[0m -- Use debug configuration instead of release"); LogHelper.println (" \x1b[1m-final\x1b[0m -- Use final configuration instead of release"); - + } - + LogHelper.println (" \x1b[1m-v\x1b[0;3m/\x1b[0m\x1b[1m-verbose\x1b[0m -- Print additional information (when available)"); - + if (isBuildCommand && command != "run" && command != "trace") { - + LogHelper.println (" \x1b[1m-clean\x1b[0m -- Add a \"clean\" action before running the current command"); - + } - + LogHelper.println (" \x1b[1m-nocolor\x1b[0m -- Disable ANSI format codes in output"); - + if (command == "run" || command == "test") { - + LogHelper.println (" \x1b[1m-notrace\x1b[0m -- Disable trace output during run or test command"); - + } - - LogHelper.println (" \x1b[1m-dryrun\x1b[0m -- Execute the requested command without making changes"); - + + LogHelper.println (" \x1b[1m-dryrun\x1b[0m -- Execute the requested command without making changes"); + if (isProjectCommand && command != "run" && command != "trace") { - + LogHelper.println (" \x1b[1m-xml\x1b[0m -- Generate XML type information, useful for documentation"); - + } - + if (command == "run" || command == "test") { - + LogHelper.println (" \x1b[1m--\x1b[0;3m/\x1b[0m\x1b[1m-args\x1b[0m ... -- Pass additional arguments at launch"); - + } - + if (isProjectCommand) { - + LogHelper.println (" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-cpp\x1b[0m -- Build with C++ (default behavior)"); LogHelper.println (" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-neko\x1b[0m -- Build with Neko instead of C++"); LogHelper.println (" \x1b[3m(windows|mac|ios|android)\x1b[0m \x1b[1m-air\x1b[0m -- Build with AIR instead of C++"); - + } - + if (isBuildCommand) { - + LogHelper.println (" \x1b[3m(windows|mac|linux|android)\x1b[0m \x1b[1m-static\x1b[0m -- Compile as a static C++ executable"); LogHelper.println (" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-32\x1b[0m -- Compile for 32-bit instead of the OS default"); LogHelper.println (" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-64\x1b[0m -- Compile for 64-bit instead of the OS default"); @@ -1096,23 +1095,23 @@ class CommandLineTools { LogHelper.println (" \x1b[3m(ios|android)\x1b[0m \x1b[1m-armv7\x1b[0m -- Compile for ARMv7 instead of the OS defaults"); LogHelper.println (" \x1b[3m(ios|android)\x1b[0m \x1b[1m-armv7s\x1b[0m -- Compile for ARMv7s instead of the OS defaults"); LogHelper.println (" \x1b[3m(ios)\x1b[0m \x1b[1m-arm64\x1b[0m -- Compile for ARM64 instead of the OS defaults"); - + } - + if (isProjectCommand) { - + LogHelper.println (" \x1b[3m(ios)\x1b[0m \x1b[1m-archive\x1b[0m -- Generate iOS archive during build"); - + } - + if (isProjectCommand) { - + if (command != "run" && command != "trace") { - + LogHelper.println (" \x1b[3m(ios)\x1b[0m \x1b[1m-xcode\x1b[0m -- Launch the generated Xcode project"); - + } - + //LogHelper.println (" \x1b[3m(ios|blackberry|tizen|tvos|webos)\x1b[0m \x1b[1m-simulator\x1b[0m -- Target the device simulator"); LogHelper.println (" \x1b[3m(ios|tvos)\x1b[0m \x1b[1m-simulator\x1b[0m -- Target the device simulator"); LogHelper.println (" \x1b[3m(ios)\x1b[0m \x1b[1m-simulator -ipad\x1b[0m -- Build/test for the iPad Simulator"); @@ -1120,23 +1119,23 @@ class CommandLineTools { LogHelper.println (" \x1b[3m(flash)\x1b[0m \x1b[1m-web\x1b[0m -- Test Flash target using a web template"); LogHelper.println (" \x1b[3m(air)\x1b[0m \x1b[1m-ios\x1b[0m -- Target iOS instead of AIR desktop"); LogHelper.println (" \x1b[3m(air)\x1b[0m \x1b[1m-android\x1b[0m -- Target Android instead of AIR desktop"); - + if (command == "run" || command == "test") { - + LogHelper.println (" \x1b[3m(emscripten|html5|flash)\x1b[0m \x1b[1m-nolaunch\x1b[0m -- Begin test server without launching"); //LogHelper.println (" \x1b[3m(html5)\x1b[0m \x1b[1m-minify\x1b[0m -- Minify output using the Google Closure compiler"); LogHelper.println (" \x1b[3m(emscripten|html5)\x1b[0m \x1b[1m-minify\x1b[0m -- Minify application file"); //LogHelper.println (" \x1b[3m(html5)\x1b[0m \x1b[1m-minify -yui\x1b[0m -- Minify output using the YUI compressor"); LogHelper.println (" \x1b[3m(emscripten|html5|flash)\x1b[0m \x1b[1m--port=\x1b[0;3mvalue\x1b[0m -- Set port for test server"); - + } - + if (command != "run" && command != "trace") { - + LogHelper.println (" \x1b[3m(emscripten)\x1b[0m \x1b[1m-webassembly\x1b[0m -- Compile for WebAssembly instead of asm.js"); - + } - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Experimental Options:" + LogHelper.resetColor); LogHelper.println (""); @@ -1149,10 +1148,10 @@ class CommandLineTools { LogHelper.println (" \x1b[3m(windows)\x1b[0m \x1b[1m-winjs\x1b[0m -- Build for WinJS instead of C++ (implies UWP)"); LogHelper.println (" \x1b[3m(windows)\x1b[0m \x1b[1m-uwp\x1b[0m -- Build for Universal Windows Platform"); LogHelper.println (" \x1b[3m(html5)\x1b[0m \x1b[1m-electron\x1b[0m -- Target Electron instead of the browser"); - - + + if (command != "run" && command != "trace") { - + LogHelper.println (""); LogHelper.println (" " + LogHelper.accentColor + "Project Overrides:" + LogHelper.resetColor); LogHelper.println (""); @@ -1166,28 +1165,28 @@ class CommandLineTools { LogHelper.println (" \x1b[1m--haxelib-\x1b[0;3mname=value\x1b[0m -- Override the path to a haxelib"); LogHelper.println (" \x1b[1m--source\x1b[0;3m=value\x1b[0m -- Add an additional value"); LogHelper.println (" \x1b[1m--certificate-\x1b[0;3moption=value\x1b[0m -- Override a project setting"); - + } - + } - + } - - + + private function displayInfo (showHint:Bool = false):Void { - + // var out = ""; // for (i in 0...80) out += "-"; // LogHelper.println (out); - + if (PlatformHelper.hostPlatform == Platform.WINDOWS) { - + LogHelper.println (""); - + } - + if (targetFlags.exists ("openfl")) { - + LogHelper.println ("\x1b[37m .d88 88b. \x1b[0m\x1b[1;36m888888b 888 \x1b[0m"); LogHelper.println ("\x1b[37md88P\" \"Y88b \x1b[0m\x1b[1;36m888 888 \x1b[0m"); LogHelper.println ("\x1b[37m888 888 \x1b[0m\x1b[1;36m888 888 \x1b[0m"); @@ -1198,12 +1197,12 @@ class CommandLineTools { LogHelper.println ("\x1b[37m \"Y88 88P\" 88888P\" \"Y8888 888 888 \x1b[0m\x1b[1;36m888 \"Y888P \x1b[0m"); LogHelper.println ("\x1b[37m 888 "); LogHelper.println ("\x1b[37m 888 \x1b[0m"); - + LogHelper.println (""); LogHelper.println ("\x1b[1mOpenFL Command-Line Tools\x1b[0;1m (" + getToolsVersion () + ")\x1b[0m"); - + } else { - + LogHelper.println ("\x1b[32m_\x1b[1m/\\\\\\\\\\\\\x1b[0m\x1b[32m______________________________________________\x1b[0m"); LogHelper.println ("\x1b[32m_\x1b[1m\\////\\\\\\\x1b[0m\x1b[32m______________________________________________\x1b[0m"); LogHelper.println ("\x1b[32m_____\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m_____\x1b[1m/\\\\\\\x1b[0m\x1b[32m_____________________________________\x1b[0m"); @@ -1213,1000 +1212,1000 @@ class CommandLineTools { LogHelper.println ("\x1b[32m_________\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m____\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m_\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m__\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m__\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m_\x1b[1m\\//\\\\///////\x1b[0m\x1b[32m____\x1b[0m"); LogHelper.println ("\x1b[32m________\x1b[1m/\\\\\\\\\\\\\\\\\\\x1b[0m\x1b[32m_\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m_\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m__\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m__\x1b[1m\\/\\\\\\\x1b[0m\x1b[32m__\x1b[1m\\//\\\\\\\\\\\\\\\\\\\\\x1b[0m\x1b[32m__\x1b[0m"); LogHelper.println ("\x1b[32m________\x1b[1m\\/////////\x1b[0m\x1b[32m__\x1b[1m\\///\x1b[0m\x1b[32m__\x1b[1m\\///\x1b[0m\x1b[32m___\x1b[1m\\///\x1b[0m\x1b[32m___\x1b[1m\\///\x1b[0m\x1b[32m____\x1b[1m\\//////////\x1b[0m\x1b[32m___\x1b[0m"); - + LogHelper.println (""); LogHelper.println ("\x1b[1mLime Command-Line Tools\x1b[0;1m (" + getToolsVersion () + ")\x1b[0m"); - + } - + if (showHint) { - + LogHelper.println ("Use \x1b[3m" + commandName + " setup\x1b[0m to configure platforms or \x1b[3m" + commandName + " help\x1b[0m for more commands"); - + } - + } - - + + private function document ():Void { - - - + + + } - - + + private function findProjectFile (path:String):String { - + if (FileSystem.exists (PathHelper.combine (path, "project.hxp"))) { - + return PathHelper.combine (path, "project.hxp"); - + } else if (FileSystem.exists (PathHelper.combine (path, "project.lime"))) { - + return PathHelper.combine (path, "project.lime"); - + } else if (FileSystem.exists (PathHelper.combine (path, "project.xml"))) { - + return PathHelper.combine (path, "project.xml"); - + } else if (FileSystem.exists (PathHelper.combine (path, "project.nmml"))) { - + return PathHelper.combine (path, "project.nmml"); - + } else { - + var files = FileSystem.readDirectory (path); var matches = new Map> (); matches.set ("hxp", []); matches.set ("lime", []); matches.set ("nmml", []); matches.set ("xml", []); - + for (file in files) { - + var path = PathHelper.combine (path, file); - + if (FileSystem.exists (path) && !FileSystem.isDirectory (path)) { - + var extension = Path.extension (file); - + if ((extension == "lime" && file != "include.lime") || (extension == "nmml" && file != "include.nmml") || (extension == "xml" && file != "include.xml") || extension == "hxp") { - + matches.get (extension).push (path); - + } - + } - + } - + if (matches.get ("hxp").length > 0) { - + return matches.get ("hxp")[0]; - + } - + if (matches.get ("lime").length > 0) { - + return matches.get ("lime")[0]; - + } - + if (matches.get ("nmml").length > 0) { - + return matches.get ("nmml")[0]; - + } - + if (matches.get ("xml").length > 0) { - + return matches.get ("xml")[0]; - + } - + } - + return ""; - + } - - + + private function generate ():Void { - + if (targetFlags.exists ("font-hash")) { - + var sourcePath = words[0]; var glyphs = "32-255"; - + ProcessHelper.runCommand (Path.directory (sourcePath), "neko", [ HaxelibHelper.getPath (new Haxelib ("lime")) + "/templates/bin/hxswfml.n", "ttf2hash2", Path.withoutDirectory (sourcePath), Path.withoutDirectory (sourcePath) + ".hash", "-glyphs", glyphs ]); - + } else if (targetFlags.exists ("font-details")) { - + //var sourcePath = words[0]; - + //var details = Font.load (sourcePath); //var json = Json.stringify (details); //Sys.print (json); - + } else if (targetFlags.exists ("java-externs")) { - + var config = ConfigHelper.getConfig (); var sourcePath = words[0]; var targetPath = words[1]; - + new JavaExternGenerator (config, sourcePath, targetPath); - + } - + } - - + + private function getBuildNumber (project:HXProject, increment:Bool = true):Void { - + var buildNumber = project.meta.buildNumber; - + if (buildNumber == null || StringTools.startsWith (buildNumber, "git")) { - + buildNumber = getBuildNumber_GIT (project, increment); - + } - + if (buildNumber == null || StringTools.startsWith (buildNumber, "svn")) { - + buildNumber = getBuildNumber_SVN (project, increment); - + } - + if (buildNumber == null) { - + var versionFile = PathHelper.combine (project.app.path, ".build"); var version = 1; - + try { - + if (FileSystem.exists (versionFile)) { - + var previousVersion = Std.parseInt (File.getBytes (versionFile).toString ()); - + if (previousVersion != null) { - + version = previousVersion; - + if (increment) { - + version ++; - + } - + } - + } - + } catch (e:Dynamic) {} - + project.meta.buildNumber = Std.string (version); - + if (increment) { - + try { - + PathHelper.mkdir (project.app.path); - + var output = File.write (versionFile, false); output.writeString (Std.string (version)); output.close (); - + } catch (e:Dynamic) {} - + } - + } - + } - - + + private function getBuildNumber_GIT (project:HXProject, increment:Bool = true):String { - + var cache = LogHelper.mute; LogHelper.mute = true; - + var output = ProcessHelper.runProcess ("", "git", [ "rev-list", "HEAD", "--count" ], true, true, true); - + LogHelper.mute = cache; - + if (output != null) { - + var value = Std.parseInt (output); - + if (value != null) { - + var buildNumber = project.meta.buildNumber; - + if (buildNumber != null && buildNumber.indexOf ("+") > -1) { - + var modifier = Std.parseInt (buildNumber.substr (buildNumber.indexOf ("+") + 1)); - + if (modifier != null) { - + value += modifier; - + } - + } - + return project.meta.buildNumber = Std.string (value); - + } - + } - + return null; - + } - - + + private function getBuildNumber_SVN (project:HXProject, increment:Bool = true):String { - + var cache = LogHelper.mute; LogHelper.mute = true; - + var output = ProcessHelper.runProcess ("", "svn", [ "info" ], true, true, true); - + LogHelper.mute = cache; - + if (output != null) { - + var searchString = "Revision: "; var index = output.indexOf (searchString); - + if (index > -1) { - + var value = Std.parseInt (output.substring (index + searchString.length, output.indexOf ("\n", index))); - + if (value != null) { - + var buildNumber = project.meta.buildNumber; - + if (buildNumber != null && buildNumber.indexOf ("+") > -1) { - + var modifier = Std.parseInt (buildNumber.substr (buildNumber.indexOf ("+") + 1)); - + if (modifier != null) { - + value += modifier; - + } - + } - + return project.meta.buildNumber = Std.string (value); - + } - + } - + } - + return null; - + } - - + + private function getToolsVersion (version:String = null):String { - + if (version == null) version = this.version; - + if (targetFlags.exists ("openfl")) { - + return HaxelibHelper.getVersion (new Haxelib ("openfl")) + "-L" + StringHelper.generateUUID (5, null, StringHelper.generateHashCode (version)); - + } else { - + return version; - + } - + } - - + + private function initializeProject (project:HXProject = null, targetName:String = ""):HXProject { - + LogHelper.info ("", LogHelper.accentColor + "Initializing project..." + LogHelper.resetColor); - + var projectFile = ""; - + if (project == null) { - + if (words.length == 2) { - + if (FileSystem.exists (words[0])) { - + if (FileSystem.isDirectory (words[0])) { - + projectFile = findProjectFile (words[0]); - + } else { - + projectFile = words[0]; - + } - + } - + if (targetName == "") { - + targetName = words[1].toLowerCase (); - + } - + } else { - + projectFile = findProjectFile (Sys.getCwd ()); - + if (targetName == "") { - + targetName = words[0].toLowerCase (); - + } - + } - + if (projectFile == "") { - + LogHelper.error ("You must have a \"project.xml\" file or specify another valid project file when using the '" + command + "' command"); return null; - + } else { - + LogHelper.info ("", LogHelper.accentColor + "Using project file: " + projectFile + LogHelper.resetColor); - + } - + } - + if (runFromHaxelib && !targetFlags.exists ("nolocalrepocheck")) { - + try { - + var forceGlobal = (overrides.haxeflags.indexOf ("--global") > -1); var projectDirectory = Path.directory (projectFile); var localRepository = PathHelper.combine (projectDirectory, ".haxelib"); - + if (!forceGlobal && FileSystem.exists (localRepository) && FileSystem.isDirectory (localRepository)) { - + var overrideExists = HaxelibHelper.pathOverrides.exists ("lime"); var cacheOverride = HaxelibHelper.pathOverrides.get ("lime"); HaxelibHelper.pathOverrides.remove ("lime"); - + var workingDirectory = Sys.getCwd (); Sys.setCwd (projectDirectory); - + var limePath = HaxelibHelper.getPath (new Haxelib ("lime"), true, true); var toolsPath = HaxelibHelper.getPath (new Haxelib ("lime-tools")); - + Sys.setCwd (workingDirectory); - + if (!StringTools.startsWith (toolsPath, limePath)) { - + LogHelper.info ("", LogHelper.accentColor + "Requesting alternate tools from .haxelib repository...\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 ("-nolocalrepocheck"); args.push (workingDirectory); - + Sys.exit (Sys.command ("neko", args)); return null; - + } - + if (overrideExists) { - + HaxelibHelper.pathOverrides.set ("lime", cacheOverride); - + } - + } - + } catch (e:Dynamic) {} - + } - + if (targetFlags.exists ("air")) { - + switch (targetName) { - + case "android": - + targetName = "air"; targetFlags.set ("android", ""); - + case "ios": - + targetName = "air"; targetFlags.set ("ios", ""); - + case "windows": - + targetName = "air"; targetFlags.set ("windows", ""); - + case "mac", "macos": - + targetName = "air"; targetFlags.set ("mac", ""); - + } - + } - + var target = null; - + switch (targetName) { - + case "cpp": - + target = PlatformHelper.hostPlatform; targetFlags.set ("cpp", ""); - + case "neko": - + target = PlatformHelper.hostPlatform; targetFlags.set ("neko", ""); - + case "hl": - + target = PlatformHelper.hostPlatform; targetFlags.set ("hl", ""); - + case "java": - + target = PlatformHelper.hostPlatform; targetFlags.set ("java", ""); - + case "nodejs": - + target = PlatformHelper.hostPlatform; targetFlags.set ("nodejs", ""); - + case "cs": - + target = PlatformHelper.hostPlatform; targetFlags.set ("cs", ""); - + case "iphone", "iphoneos": - + target = Platform.IOS; - + case "iphonesim": - + target = Platform.IOS; targetFlags.set ("simulator", ""); - + case "electron": - + target = Platform.HTML5; targetFlags.set ("electron", ""); - + case "firefox", "firefoxos": - + target = Platform.FIREFOX; overrides.haxedefs.set ("firefoxos", ""); - + case "mac", "macos": - + target = Platform.MAC; overrides.haxedefs.set ("macos", ""); - + case "rpi", "raspberrypi": - + target = Platform.LINUX; targetFlags.set ("rpi", ""); - + case "webassembly", "wasm": - + target = Platform.EMSCRIPTEN; targetFlags.set ("webassembly", ""); - + case "winjs", "uwp": - + target = Platform.WINDOWS; targetFlags.set ("uwp", ""); targetFlags.set ("winjs", ""); - + case "winrt": - + target = Platform.WINDOWS; targetFlags.set ("winrt", ""); - + default: - + target = cast targetName.toLowerCase (); - + } - + HXProject._command = command; HXProject._debug = debug; HXProject._environment = environment; HXProject._target = target; HXProject._targetFlags = targetFlags; HXProject._userDefines = userDefines; - + var config = ConfigHelper.getConfig (); - + if (config != null) { - + for (define in config.defines.keys ()) { - + if (define == define.toUpperCase ()) { - + var value = config.defines.get (define); - + switch (define) { - + case "ANT_HOME": - + if (value == "/usr") { - + value = "/usr/share/ant"; - + } - + if (FileSystem.exists (value)) { - + Sys.putEnv (define, value); - + } - + case "JAVA_HOME": - + if (FileSystem.exists (value)) { - + Sys.putEnv (define, value); - + } - + default: - + Sys.putEnv (define, value); - + } - + } - + } - + } - + if (PlatformHelper.hostPlatform == Platform.WINDOWS) { - + if (environment.get ("JAVA_HOME") != null) { - + var javaPath = PathHelper.combine (environment.get ("JAVA_HOME"), "bin"); var value; - + if (PlatformHelper.hostPlatform == Platform.WINDOWS) { - + value = javaPath + ";" + Sys.getEnv ("PATH"); - + } else { - + value = javaPath + ":" + Sys.getEnv ("PATH"); - + } - + environment.set ("PATH", value); Sys.putEnv ("PATH", value); - + } - + } - + try { - + var process = new Process ("haxe", [ "-version" ]); var haxeVersion = StringTools.trim (process.stderr.readAll ().toString ()); - + if (haxeVersion == "") { haxeVersion = StringTools.trim (process.stdout.readAll ().toString ()); } - + process.close (); - + environment.set ("haxe", haxeVersion); environment.set ("haxe_ver", haxeVersion); - + environment.set ("haxe" + haxeVersion.split (".")[0], "1"); - + } catch (e:Dynamic) {} - + if (!environment.exists ("HAXE_STD_PATH")) { - + if (PlatformHelper.hostPlatform == Platform.WINDOWS) { - + environment.set ("HAXE_STD_PATH", "C:\\HaxeToolkit\\haxe\\std\\"); - + } else { - + if (FileSystem.exists ("/usr/lib/haxe")) { - + environment.set ("HAXE_STD_PATH", "/usr/lib/haxe/std"); - + } else if (FileSystem.exists ("/usr/share/haxe")) { - + environment.set ("HAXE_STD_PATH", "/usr/share/haxe/std"); - + } else { - + environment.set ("HAXE_STD_PATH", "/usr/local/lib/haxe/std"); - + } - + } - + } - + if (project == null) { - + HXProject._command = command; HXProject._debug = debug; HXProject._environment = environment; HXProject._target = target; HXProject._targetFlags = targetFlags; HXProject._userDefines = userDefines; - + try { Sys.setCwd (Path.directory (projectFile)); } catch (e:Dynamic) {} - + if (Path.extension (projectFile) == "lime" || Path.extension (projectFile) == "nmml" || Path.extension (projectFile) == "xml") { - + project = new ProjectXMLParser (Path.withoutDirectory (projectFile), userDefines, includePaths); - + } else if (Path.extension (projectFile) == "hxp") { - + project = HXProject.fromFile (projectFile, userDefines, includePaths); - + if (project != null) { - + project.command = command; project.debug = debug; project.target = target; project.targetFlags = targetFlags; - + } else { - + LogHelper.error ("Could not process \"" + projectFile + "\""); return null; - + } - + } - + } - + 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"); return null; - + } - + if (config != null) { - + config.merge (project); project = config; - + } - + project.haxedefs.set ("tools", version); - + /*if (userDefines.exists ("nme")) { - + project.haxedefs.set ("nme_install_tool", 1); project.haxedefs.set ("nme_ver", version); project.haxedefs.set ("nme" + version.split (".")[0], 1); - + project.config.cpp.buildLibrary = "hxcpp"; project.config.cpp.requireBuild = false; - + }*/ - + project.merge (overrides); - + for (haxelib in project.haxelibs) { - + if (haxelib.name == "lime" && haxelib.version != null && haxelib.version != "" && haxelib.version != "dev" && !haxelib.versionMatches (version)) { - + if (!project.targetFlags.exists ("notoolscheck")) { - + if (targetFlags.exists ("openfl")) { - + for (haxelib in project.haxelibs) { - + if (haxelib.name == "openfl") { - + HaxelibHelper.setOverridePath (haxelib, HaxelibHelper.getPath (haxelib)); - + } - + } - + } - + LogHelper.info ("", LogHelper.accentColor + "Requesting tools version " + getToolsVersion (haxelib.version) + "...\x1b[0m\n\n"); - + HaxelibHelper.pathOverrides.remove ("lime"); var path = HaxelibHelper.getPath (haxelib); - + var args = Sys.args (); var workingDirectory = args.pop (); - + for (haxelib in project.haxelibs) { - + args.push ("--haxelib-" + haxelib.name + "=" + HaxelibHelper.getPath (haxelib)); - + } - + args.push ("-notoolscheck"); - + Sys.setCwd (path); var args = [ PathHelper.combine (path, "run.n") ].concat (args); args.push (workingDirectory); - + Sys.exit (Sys.command ("neko", args)); return null; - + //var args = [ "run", "lime:" + haxelib.version ].concat (args); //Sys.exit (Sys.command ("haxelib", args)); - + } else { - + if (Std.string (version) != Std.string (HaxelibHelper.getVersion (haxelib))) { - + LogHelper.warn ("", LogHelper.accentColor + "Could not switch to requested tools version\x1b[0m"); - + } - + } - + } - + } - + if (overrides.architectures.length > 0) { - + project.architectures = overrides.architectures; - + } - + for (key in projectDefines.keys ()) { - + var components = key.split ("-"); var field = components.shift ().toLowerCase (); var attribute = ""; - + if (components.length > 0) { - + for (i in 1...components.length) { - + components[i] = components[i].substr (0, 1).toUpperCase () + components[i].substr (1).toLowerCase (); - + } - + attribute = components.join (""); - + } - + if (field == "template" && attribute == "path") { - + project.templatePaths.push (projectDefines.get (key)); - + } else if (field == "config") { - + project.config.set (attribute, projectDefines.get (key)); - + } else { - + if (Reflect.hasField (project, field)) { - + var fieldValue = Reflect.field (project, field); - + if (Reflect.hasField (fieldValue, attribute)) { - + if (Std.is (Reflect.field (fieldValue, attribute), String)) { - + Reflect.setField (fieldValue, attribute, projectDefines.get (key)); - + } else if (Std.is (Reflect.field (fieldValue, attribute), Float)) { - + Reflect.setField (fieldValue, attribute, Std.parseFloat (projectDefines.get (key))); - + } else if (Std.is (Reflect.field (fieldValue, attribute), Bool)) { - + Reflect.setField (fieldValue, attribute, (projectDefines.get (key).toLowerCase () == "true" || projectDefines.get (key) == "1")); - + } - + } - + } else { - + project.targetFlags.set (key, projectDefines.get (key)); targetFlags.set (key, projectDefines.get (key)); - + } - + } - + } - + StringMapHelper.copyKeys (userDefines, project.haxedefs); - + getBuildNumber (project, (project.command == "build" || project.command == "test")); - + return project; - + } - - + + public static function main ():Void { - + new CommandLineTools (); - + } - - + + private function platformSetup ():Void { - + LogHelper.info ("", LogHelper.accentColor + "Running command: SETUP" + LogHelper.resetColor); - + if (words.length == 0) { - + PlatformSetup.run ("", userDefines, targetFlags); - + } else if (words.length == 1) { - + PlatformSetup.run (words[0], userDefines, targetFlags); - + } else { - + LogHelper.error ("Incorrect number of arguments for command 'setup'"); return; - + } - + } - - + + private function processArguments ():Void { - + var arguments = Sys.args (); - + if (arguments.length > 0) { - - // When the command-line tools are called from haxelib, + + // When the command-line tools are called from haxelib, // the last argument is the project directory and the - // path to Lime is the current working directory - + // path to Lime is the current working directory + var lastArgument = ""; - + for (i in 0...arguments.length) { - + lastArgument = arguments.pop (); if (lastArgument.length > 0) break; - + } - + lastArgument = new Path (lastArgument).toString (); var isRootDirectory = false; - + if (PlatformHelper.hostPlatform == WINDOWS) { - + isRootDirectory = (lastArgument.length == 3 && lastArgument.charAt (1) == ":" && (lastArgument.charAt (2) == "/" || lastArgument.charAt (2) == "\\")); - + } else { - + isRootDirectory = (lastArgument == "/"); - + } - + if (FileSystem.exists (lastArgument) && FileSystem.isDirectory (lastArgument)) { - + HaxelibHelper.setOverridePath (new Haxelib ("lime-tools"), PathHelper.combine (Sys.getCwd (), "tools")); - + Sys.setCwd (lastArgument); runFromHaxelib = true; - + } else if (!isRootDirectory) { - + arguments.push (lastArgument); - + } - + HaxelibHelper.workingDirectory = Sys.getCwd (); - + } - + if (!runFromHaxelib) { - + var path = null; - + if (FileSystem.exists ("tools.n")) { - + path = PathHelper.combine (Sys.getCwd (), "../"); - + } else if (FileSystem.exists ("run.n")) { - + path = Sys.getCwd (); - + } else { - + LogHelper.error ("Could not run Lime tools from this directory"); - + } - + HaxelibHelper.setOverridePath (new Haxelib ("lime"), path); HaxelibHelper.setOverridePath (new Haxelib ("lime-tools"), PathHelper.combine (path, "tools")); - + } - + var catchArguments = false; var catchHaxeFlag = false; var catchDefine = false; - + for (argument in arguments) { - + var equals = argument.indexOf ("="); - + if (catchHaxeFlag) { - + overrides.haxeflags.push (argument); catchHaxeFlag = false; - + } else if (argument == "-args" || argument == "--") { - + catchArguments = true; - + } else if (catchArguments) { - + additionalArguments.push (argument); - + } else if (argument == "-D") { - + catchDefine = true; - + } else if (equals > 0) { - + var argValue = argument.substr (equals + 1); // if quotes remain on the argValue we need to strip them off // otherwise the compiler really dislikes the result! @@ -2214,277 +2213,277 @@ class CommandLineTools { if (r.match(argValue)) { argValue = r.matched(1); } - + if (catchDefine) { - + userDefines.set (argument, argValue); catchDefine = false; - + } else if (argument.substr (0, 2) == "-D") { - + userDefines.set (argument.substr (2, equals - 2), argValue); - + } else if (argument.substr (0, 2) == "--") { - + // this won't work because it assumes there is only ever one of these. //projectDefines.set (argument.substr (2, equals - 2), argValue); - + var field = argument.substr (2, equals - 2); - + if (field == "haxedef") { - + overrides.haxedefs.set (argValue, 1); - + } else if (field == "haxeflag") { - + overrides.haxeflags.push (argValue); - + } else if (field == "haxelib") { - + var name = argValue; var version = ""; - + if (name.indexOf (":") > -1) { - + version = name.substr (name.indexOf (":") + 1); name = name.substr (0, name.indexOf (":")); - + } - + var i = 0; - + overrides.haxelibs.push (new Haxelib (name, version)); - + } else if (StringTools.startsWith (field, "haxelib-")) { - + var name = field.substr (8); HaxelibHelper.setOverridePath (new Haxelib (name), PathHelper.tryFullPath (argValue)); - + } else if (field == "source") { - + overrides.sources.push (argValue); - + } else if (field == "dependency") { - + overrides.dependencies.push (new Dependency (argValue, "")); - + } else if (StringTools.startsWith (field, "certificate-")) { - + if (overrides.keystore == null) { - + overrides.keystore = new Keystore (); - + } - + field = StringTools.replace (field, "certificate-", ""); - + if (field == "alias-password") field = "aliasPassword"; - + if (Reflect.hasField (overrides.keystore, field)) { - + Reflect.setField (overrides.keystore, field, argValue); - + } - + if (field == "identity") { - + overrides.config.set ("ios.identity", argValue); overrides.config.set ("tvos.identity", argValue); - + } else if (field == "team-id") { - + overrides.config.set ("ios.team-id", argValue); overrides.config.set ("tvos.team-id", argValue); - + } - + } else if (StringTools.startsWith (field, "app-") || StringTools.startsWith (field, "meta-") || StringTools.startsWith (field, "window-")) { - + var split = field.split ("-"); - + var fieldName = split[0]; var property = split[1]; - + for (i in 2...split.length) { - + property += split[i].substr (0, 1).toUpperCase () + split[i].substr (1, split[i].length - 1); - + } - + if (field == "window-allow-high-dpi") property = "allowHighDPI"; if (field == "window-color-depth") property = "colorDepth"; if (field == "meta-build-number") property = "buildNumber"; - + var fieldReference = Reflect.field (overrides, fieldName); - + if (Reflect.hasField (fieldReference, property)) { - + var propertyReference = Reflect.field (fieldReference, property); - + if (Std.is (propertyReference, Bool)) { - + Reflect.setField (fieldReference, property, argValue == "true"); - + } else if (Std.is (propertyReference, Int)) { - + Reflect.setField (fieldReference, property, Std.parseInt (argValue)); - + } else if (Std.is (propertyReference, Float)) { - + Reflect.setField (fieldReference, property, Std.parseFloat (argValue)); - + } else if (Std.is (propertyReference, String)) { - + Reflect.setField (fieldReference, property, argValue); - + } else { - + // TODO: Only certain properties? Reflect.setField (fieldReference, property, argValue); - + } - + } - + } else if (field == "build-library") { - + overrides.config.set ("cpp.buildLibrary", argValue); - + } else if (field == "device") { - + targetFlags.set ("device", argValue); - + } else { - + projectDefines.set (field, argValue); - + } - + } else { - + userDefines.set (argument.substr (0, equals), argValue); - + } - + } else if (catchDefine) { - + userDefines.set (argument, ""); catchDefine = false; - + } else if (argument.substr (0, 2) == "-D") { - + userDefines.set (argument.substr (2), ""); - + } else if (argument.substr (0, 2) == "-I") { - + includePaths.push (argument.substr (2)); - + } else if (argument == "-haxelib-debug") { - + HaxelibHelper.debug = true; - + } else if (argument == "--help" || argument == "-help" || argument == "-h") { - + targetFlags.set ("help", ""); - + } else if (argument.substr (0, 1) == "-") { - + if (argument == "-dce" || argument.substr (1, 1) == "-") { - + overrides.haxeflags.push (argument); - + if (argument == "--remap" || argument == "--connect" || argument == "-dce") { - + catchHaxeFlag = true; - + } - + } else { - + if (argument.substr (0, 4) == "-arm") { - + try { - + var name = argument.substr (1).toUpperCase (); var value = Type.createEnum (Architecture, name); - + if (value != null) { - + overrides.architectures.push (value); - + } - + } catch (e:Dynamic) {} - + } else if (argument == "-64") { - + overrides.architectures.push (Architecture.X64); - + } else if (argument == "-32") { - + overrides.architectures.push (Architecture.X86); - + } else if (argument == "-v" || argument == "-verbose") { - + argument = "-verbose"; - + if (command != "display") { - + LogHelper.verbose = true; - + } - + } else if (argument == "-force-verbose") { - + LogHelper.verbose = true; - + } else if (argument == "-dryrun") { - + ProcessHelper.dryRun = true; - + } else if (argument == "-notrace") { - + traceEnabled = false; - + } else if (argument == "-debug") { - + debug = true; - + } else if (argument == "-nocolor") { - + LogHelper.enableColor = false; - + } - + targetFlags.set (argument.substr (1), ""); - + } - + } else if (command.length == 0) { - + command = argument; - + } else { - + words.push (argument); - + } - + } - + } - - + + private function publishProject () { - + switch (words[words.length - 1]) { - + case "firefox": - + var project = initializeProject (null, "firefox"); - + LogHelper.info ("", LogHelper.accentColor + "Using publishing target: FIREFOX MARKETPLACE" + LogHelper.resetColor); - + //if (FirefoxMarketplace.isValid (project)) { // //buildProject (project, "build"); @@ -2494,74 +2493,74 @@ class CommandLineTools { //FirefoxMarketplace.publish (project); // //} - + } - + } - - + + private function updateLibrary ():Void { - + if ((words.length < 1 && command != "upgrade") || words.length > 1) { - + LogHelper.error ("Incorrect number of arguments for command '" + command + "'"); return; - + } - + LogHelper.info ("", LogHelper.accentColor + "Running command: " + command.toUpperCase () + LogHelper.resetColor); - + var name = defaultLibrary; - + if (words.length > 0) { - + name = words[0]; - + } - + var haxelib = new Haxelib (name); var path = HaxelibHelper.getPath (haxelib); - + switch (command) { - + case "install": - + if (path == null || path == "") { - + PlatformSetup.installHaxelib (haxelib); - + } else { - + PlatformSetup.updateHaxelib (haxelib); - + } - + PlatformSetup.setupHaxelib (haxelib); - + case "remove": - + if (path != null && path != "") { - + HaxelibHelper.runCommand ("", [ "remove", name ]); - + } - + case "upgrade": - + if (path != null && path != "") { - + PlatformSetup.updateHaxelib (haxelib); PlatformSetup.setupHaxelib (haxelib); - + } else { - + LogHelper.warn ("\"" + haxelib.name + "\" is not a valid haxelib, or has not been installed"); - + } - + } - + } - - + + } diff --git a/tools/platforms/AIRPlatform.hx b/tools/platforms/AIRPlatform.hx index bd3935dad..a1490a608 100644 --- a/tools/platforms/AIRPlatform.hx +++ b/tools/platforms/AIRPlatform.hx @@ -2,6 +2,7 @@ package; import haxe.io.Path; +import haxe.Template; import hxp.project.AssetType; import hxp.project.HXProject; import hxp.project.Icon; @@ -24,6 +25,7 @@ class AIRPlatform extends FlashPlatform { private var iconData:Array; + private var splashScreenData:Array; private var targetPlatform:Platform; private var targetPlatformType:PlatformType; @@ -95,6 +97,12 @@ class AIRPlatform extends FlashPlatform { } + for (splashScreen in splashScreenData) { + + files.push (splashScreen.path); + + } + var targetPath = switch (targetPlatform) { case ANDROID: "bin/" + project.app.file + ".apk"; @@ -180,6 +188,31 @@ class AIRPlatform extends FlashPlatform { } + private override function getDisplayHXML ():String { + + var hxml = PathHelper.findTemplate (project.templatePaths, "flash/hxml/" + buildType + ".hxml"); + + var context = project.templateContext; + context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6); + context.OUTPUT_DIR = targetDirectory; + + for (dependency in project.dependencies) { + + if (StringTools.endsWith (dependency.path, ".ane")) { + + context.HAXE_FLAGS += "\n-swf-lib " + dependency.path; + + } + + } + + var template = new Template (File.getContent (hxml)); + + return template.execute (context) + "\n-D display"; + + } + + public override function install ():Void { // TODO: Make separate install step @@ -257,6 +290,14 @@ class AIRPlatform extends FlashPlatform { } + var targetDevice = project.config.getString ("ios.device", "universal"); + var targetDevices = []; + + if (targetDevice != "ipad") targetDevices.push (1); // iphone + if (targetDevice != "iphone") targetDevices.push (2); // ipad + + context.IOS_TARGET_DEVICES = targetDevices; + var iconSizes = [ 16, 29, 32, 36, 40, 48, 50, 57, 58, 60, 72, 75, 76, 80, 87, 96, 100, 114, 120, 128, 144, 152, 167, 180, 192, 512, 1024 ]; var icons = project.icons; iconData = []; @@ -278,19 +319,19 @@ class AIRPlatform extends FlashPlatform { } if (iconData.length > 0) context.icons = iconData; - + context.extensions = new Array(); - + for (dependency in project.dependencies) { - - if (StringTools.endsWith(dependency.path, ".ane")) { - + + if (StringTools.endsWith (dependency.path, ".ane")) { + var extension:Dynamic = { name: dependency.name }; - context.extensions.push(extension); + context.extensions.push (extension); context.HAXE_FLAGS += "\n-swf-lib " + dependency.path; - + } - + } FileHelper.recursiveSmartCopyTemplate (project, "haxe", targetDirectory + "/haxe", context); @@ -344,10 +385,24 @@ class AIRPlatform extends FlashPlatform { } + splashScreenData = []; + + if (project.splashScreens != null) { + + for (splashScreen in project.splashScreens) { + + var path = Path.withoutDirectory (splashScreen.path); + FileHelper.copyFile (splashScreen.path, PathHelper.combine (destination, path), context); + splashScreenData.push ({ path: path }); + + } + + } + } @ignore public override function rebuild ():Void {} -} \ No newline at end of file +} diff --git a/tools/platforms/AndroidPlatform.hx b/tools/platforms/AndroidPlatform.hx index 29a070571..dca3d7cf4 100644 --- a/tools/platforms/AndroidPlatform.hx +++ b/tools/platforms/AndroidPlatform.hx @@ -66,12 +66,14 @@ class AndroidPlatform extends PlatformTarget { var hasARMV5 = (ArrayHelper.containsValue (project.architectures, Architecture.ARMV5) || ArrayHelper.containsValue (project.architectures, Architecture.ARMV6)); var hasARMV7 = ArrayHelper.containsValue (project.architectures, Architecture.ARMV7); + var hasARM64 = ArrayHelper.containsValue (project.architectures, Architecture.ARM64); var hasX86 = ArrayHelper.containsValue (project.architectures, Architecture.X86); var architectures = []; if (hasARMV5) architectures.push (Architecture.ARMV5); if (hasARMV7 || (!hasARMV5 && !hasX86)) architectures.push (Architecture.ARMV7); + if (hasARM64) architectures.push (Architecture.ARM64); if (hasX86) architectures.push (Architecture.X86); for (architecture in architectures) { @@ -95,6 +97,17 @@ class AndroidPlatform extends PlatformTarget { suffix = "-v7.so"; + } else if (architecture == Architecture.ARM64) { + + haxeParams = [ hxml, "-D", "android", "-D", "PLATFORM=android-21" ]; + cppParams = [ "-Dandroid", "-DPLATFORM=android-21" ]; + + haxeParams.push ("-D"); + haxeParams.push ("HXCPP_ARM64"); + cppParams.push ("-DHXCPP_ARM64"); + path = sourceSet + "/jniLibs/arm64-v8a"; + suffix = "-64.so"; + } else if (architecture == Architecture.X86) { haxeParams.push ("-D"); @@ -131,6 +144,16 @@ class AndroidPlatform extends PlatformTarget { } + if (!hasARM64) { + + if (FileSystem.exists (sourceSet + "/jniLibs/arm64-v8a")) { + + PathHelper.removeDirectory (sourceSet + "/jniLibs/arm64-v8a"); + + } + + } + if (!hasX86) { if (FileSystem.exists (sourceSet + "/jniLibs/x86")) { @@ -221,12 +244,14 @@ class AndroidPlatform extends PlatformTarget { var armv5 = (command == "rebuild" || ArrayHelper.containsValue (project.architectures, Architecture.ARMV5) || ArrayHelper.containsValue (project.architectures, Architecture.ARMV6)); var armv7 = (command == "rebuild" || ArrayHelper.containsValue (project.architectures, Architecture.ARMV7)); + var arm64 = (command == "rebuild" || ArrayHelper.containsValue (project.architectures, Architecture.ARM64)); var x86 = (command == "rebuild" || ArrayHelper.containsValue (project.architectures, Architecture.X86)); var commands = []; if (armv5) commands.push ([ "-Dandroid", "-DPLATFORM=android-14" ]); if (armv7) commands.push ([ "-Dandroid", "-DHXCPP_ARMV7", "-DHXCPP_ARM7", "-DPLATFORM=android-14" ]); + if (arm64) commands.push ([ "-Dandroid", "-DHXCPP_ARM64", "-DPLATFORM=android-21" ]); if (x86) commands.push ([ "-Dandroid", "-DHXCPP_X86", "-DPLATFORM=android-14" ]); CPPHelper.rebuild (project, commands); @@ -326,8 +351,8 @@ class AndroidPlatform extends PlatformTarget { context.CPP_DIR = targetDirectory + "/obj"; context.OUTPUT_DIR = targetDirectory; context.ANDROID_INSTALL_LOCATION = project.config.getString ("android.install-location", "auto"); - context.ANDROID_MINIMUM_SDK_VERSION = project.config.getInt ("android.minimum-sdk-version", 9); - context.ANDROID_TARGET_SDK_VERSION = project.config.getInt ("android.target-sdk-version", 19); + context.ANDROID_MINIMUM_SDK_VERSION = project.config.getInt ("android.minimum-sdk-version", 14); + context.ANDROID_TARGET_SDK_VERSION = project.config.getInt ("android.target-sdk-version", 26); context.ANDROID_EXTENSIONS = project.config.getArrayString ("android.extension"); context.ANDROID_PERMISSIONS = project.config.getArrayString ("android.permission", [ "android.permission.WAKE_LOCK", "android.permission.INTERNET", "android.permission.VIBRATE", "android.permission.ACCESS_NETWORK_STATE" ]); context.ANDROID_GRADLE_VERSION = project.config.getString ("android.gradle-version", "2.10"); @@ -336,7 +361,7 @@ class AndroidPlatform extends PlatformTarget { if (!project.environment.exists ("ANDROID_SDK") || !project.environment.exists ("ANDROID_NDK_ROOT")) { - var command = "lime"; + var command = #if lime "lime" #else "hxp" #end; var toolsBase = Type.resolveClass ("CommandLineTools"); if (toolsBase != null) command = Reflect.field (toolsBase, "commandName"); @@ -478,4 +503,4 @@ class AndroidPlatform extends PlatformTarget { } -} \ No newline at end of file +} diff --git a/tools/platforms/FlashPlatform.hx b/tools/platforms/FlashPlatform.hx index 069bf9304..47c7251dc 100644 --- a/tools/platforms/FlashPlatform.hx +++ b/tools/platforms/FlashPlatform.hx @@ -4,7 +4,6 @@ package; import haxe.io.Path; import haxe.Json; import haxe.Template; -import hxp.helpers.CompatibilityHelper; import hxp.helpers.DeploymentHelper; import hxp.helpers.FileHelper; import hxp.helpers.FlashHelper; @@ -292,4 +291,4 @@ class FlashPlatform extends PlatformTarget { @ignore public override function rebuild ():Void {} @ignore public override function uninstall ():Void {} -} \ No newline at end of file +} diff --git a/tools/platforms/HTML5Platform.hx b/tools/platforms/HTML5Platform.hx index ade6f0894..5d8b2f2bc 100644 --- a/tools/platforms/HTML5Platform.hx +++ b/tools/platforms/HTML5Platform.hx @@ -3,7 +3,9 @@ package; import haxe.io.Path; import haxe.Template; -// import lime.text.Font; +#if lime +import lime.text.Font; +#end import hxp.helpers.DeploymentHelper; import hxp.helpers.ElectronHelper; import hxp.helpers.FileHelper; @@ -387,24 +389,16 @@ class HTML5Platform extends PlatformTarget { if (embeddedAsset.type == "font" && embeddedAsset.sourcePath == asset.sourcePath) { - // var font = Font.fromFile (asset.sourcePath); + #if lime + var font = Font.fromFile (asset.sourcePath); - // embeddedAsset.ascender = font.ascender; - // embeddedAsset.descender = font.descender; - // embeddedAsset.height = font.height; - // embeddedAsset.numGlyphs = font.numGlyphs; - // embeddedAsset.underlinePosition = font.underlinePosition; - // embeddedAsset.underlineThickness = font.underlineThickness; - // embeddedAsset.unitsPerEM = font.unitsPerEM; - - embeddedAsset.ascender = 0; - embeddedAsset.descender = 0; - embeddedAsset.height = 0; - embeddedAsset.numGlyphs = 0; - embeddedAsset.underlinePosition = 0; - embeddedAsset.underlineThickness = 0; - embeddedAsset.unitsPerEM = 0; - embeddedAsset.fontName = "sans"; + embeddedAsset.ascender = font.ascender; + embeddedAsset.descender = font.descender; + embeddedAsset.height = font.height; + embeddedAsset.numGlyphs = font.numGlyphs; + embeddedAsset.underlinePosition = font.underlinePosition; + embeddedAsset.underlineThickness = font.underlineThickness; + embeddedAsset.unitsPerEM = font.unitsPerEM; if (shouldEmbedFont) { @@ -426,6 +420,7 @@ class HTML5Platform extends PlatformTarget { } break; + #end } @@ -493,4 +488,4 @@ class HTML5Platform extends PlatformTarget { @ignore public override function uninstall ():Void {} -} \ No newline at end of file +} diff --git a/tools/platforms/IOSPlatform.hx b/tools/platforms/IOSPlatform.hx index 70f5e64a6..7803e0d10 100644 --- a/tools/platforms/IOSPlatform.hx +++ b/tools/platforms/IOSPlatform.hx @@ -17,7 +17,9 @@ import hxp.helpers.PlatformHelper; import hxp.helpers.ProcessHelper; import hxp.helpers.StringHelper; import hxp.helpers.WatchHelper; +#if lime import lime.graphics.Image; +#end import hxp.project.Architecture; import hxp.project.Asset; import hxp.project.AssetType; @@ -573,12 +575,14 @@ class IOSPlatform extends PlatformTarget { if (!FileSystem.exists (imagePath)) { + #if lime LogHelper.info ("", " - \x1b[1mGenerating image:\x1b[0m " + imagePath); var image = new Image (null, 0, 0, size.w, size.h, (0xFF << 24) | (project.window.background & 0xFFFFFF)); - var bytes = image.encode ("png"); + var bytes = image.encode (PNG); File.saveBytes (imagePath, bytes); + #end } diff --git a/tools/platforms/TVOSPlatform.hx b/tools/platforms/TVOSPlatform.hx index d00743d2e..a88c71fe9 100644 --- a/tools/platforms/TVOSPlatform.hx +++ b/tools/platforms/TVOSPlatform.hx @@ -1,4 +1,4 @@ -package lime.tools.platforms; +package; //import openfl.display.BitmapData; @@ -17,7 +17,9 @@ import hxp.helpers.PlatformHelper; import hxp.helpers.ProcessHelper; import hxp.helpers.StringHelper; import hxp.helpers.WatchHelper; +#if lime import lime.graphics.Image; +#end import hxp.project.Architecture; import hxp.project.Asset; import hxp.project.AssetType; @@ -33,201 +35,201 @@ import sys.FileSystem; class TVOSPlatform extends PlatformTarget { - - + + public function new (command:String, _project:HXProject, targetFlags:Map ) { - + super (command, _project, targetFlags); - + targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("tvos.output-directory", "tvos")); - + } - - + + public override function build ():Void { - + if (project.targetFlags.exists ("xcode") && PlatformHelper.hostPlatform == Platform.MAC) { - + ProcessHelper.runCommand ("", "open", [ targetDirectory + "/" + project.app.file + ".xcodeproj" ] ); - + } else { - + TVOSHelper.build (project, targetDirectory); - + if (noOutput) return; - + if (!project.targetFlags.exists ("simulator")) { - + TVOSHelper.sign (project, targetDirectory + "/bin"); - + } - + } - + } - - + + public override function clean ():Void { - + if (FileSystem.exists (targetDirectory)) { - + PathHelper.removeDirectory (targetDirectory); - + } - + } - - + + public override function deploy ():Void { - + TVOSHelper.deploy (project, targetDirectory); - + } - - + + public override function display ():Void { - + Sys.println (getDisplayHXML ()); - + } - - + + private function generateContext ():Dynamic { - + // project = project.clone (); - + project.sources.unshift (""); project.sources = PathHelper.relocatePaths (project.sources, PathHelper.combine (targetDirectory, project.app.file + "/haxe")); //project.dependencies.push ("stdc++"); - + if (project.targetFlags.exists ("xml")) { - + project.haxeflags.push ("-xml " + targetDirectory + "/types.xml"); - + } - + if (project.targetFlags.exists ("final")) { - + project.haxedefs.set ("final", ""); - + } - + if (!project.config.exists ("tvos.identity")) { - + project.config.set ("tvos.identity", "tvOS Developer"); - + } - + var context = project.templateContext; - + context.HAS_ICON = false; context.HAS_LAUNCH_IMAGE = false; context.OBJC_ARC = false; context.KEY_STORE_IDENTITY = project.config.getString ("tvos.identity"); - + context.linkedLibraries = []; - + for (dependency in project.dependencies) { - + if (!StringTools.endsWith (dependency.name, ".framework") && !StringTools.endsWith (dependency.name, ".tbd") && !StringTools.endsWith (dependency.path, ".framework")) { - + if (dependency.path != "") { - + var name = Path.withoutDirectory (Path.withoutExtension (dependency.path)); - + project.config.push ("tvos.linker-flags", "-force_load $SRCROOT/$PRODUCT_NAME/lib/$CURRENT_ARCH/" + Path.withoutDirectory (dependency.path)); - + if (StringTools.startsWith (name, "lib")) { - + name = name.substring (3, name.length); - + } - + context.linkedLibraries.push (name); - + } else if (dependency.name != "") { - + context.linkedLibraries.push (dependency.name); - + } - + } - + } - + var valid_archs = new Array (); var arm64 = false; var architectures = project.architectures; - + if (architectures == null || architectures.length == 0) { - + architectures = [ Architecture.ARM64 ]; - + } - + /*if (project.config.getString ("ios.device", "universal") == "universal" || project.config.getString ("ios.device") == "iphone") { - + if (project.config.getFloat ("ios.deployment", 5.1) < 5) { - + ArrayHelper.addUnique (architectures, Architecture.ARMV6); - + } - + }*/ - + for (architecture in project.architectures) { - + switch (architecture) { - + case ARM64: valid_archs.push ("arm64"); arm64 = true; default: - + } - + } - + context.CURRENT_ARCHS = "( " + valid_archs.join(",") + ") "; - + valid_archs.push ("i386"); - + context.VALID_ARCHS = valid_archs.join(" "); context.THUMB_SUPPORT = ""; - + var requiredCapabilities = []; - + requiredCapabilities.push( { name: "arm64", value: true } ); - + context.REQUIRED_CAPABILITY = requiredCapabilities; context.ARM64 = arm64; context.TARGET_DEVICES = switch (project.config.getString ("tvos.device", "appletv")) { case "appletv": "3"; default: "3"; } context.DEPLOYMENT = project.config.getString ("tvos.deployment", "9.0"); - + if (project.config.getString ("tvos.compiler") == "llvm" || project.config.getString ("tvos.compiler", "clang") == "clang") { - + context.OBJC_ARC = true; - + } - + context.IOS_COMPILER = project.config.getString ("tvos.compiler", "clang"); context.CPP_BUILD_LIBRARY = project.config.getString ("cpp.buildLibrary", "hxcpp"); - + var json = Json.parse (File.getContent (PathHelper.getHaxelib (new Haxelib ("hxcpp"), true) + "/haxelib.json")); - + if (Std.parseFloat (json.version) > 3.1) { - + context.CPP_LIBPREFIX = "lib"; - + } else { - + context.CPP_LIBPREFIX = ""; - + } - + context.IOS_LINKER_FLAGS = ["-stdlib=libc++"].concat (project.config.getArrayString ("tvos.linker-flags")); context.IOS_NON_EXEMPT_ENCRYPTION = project.config.getBool ("tvos.non-exempt-encryption", true); - + switch (project.window.orientation) { - + case PORTRAIT: context.IOS_APP_ORIENTATION = "UIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDown"; case LANDSCAPE: @@ -238,151 +240,151 @@ class TVOSPlatform extends PlatformTarget { //context.IOS_APP_ORIENTATION = "UIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRightUIInterfaceOrientationPortrait"; default: context.IOS_APP_ORIENTATION = "UIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRightUIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDown"; - + } - + context.ADDL_PBX_BUILD_FILE = ""; context.ADDL_PBX_FILE_REFERENCE = ""; context.ADDL_PBX_FRAMEWORKS_BUILD_PHASE = ""; context.ADDL_PBX_FRAMEWORK_GROUP = ""; - + context.frameworkSearchPaths = []; - + for (dependency in project.dependencies) { - + var name = null; var path = null; var fileType = null; - + if (Path.extension (dependency.name) == "framework") { - + name = dependency.name; path = "/System/Library/Frameworks/" + dependency.name; fileType = "wrapper.framework"; - + } else if (Path.extension (dependency.name) == "tbd") { - + name = dependency.name; path = "usr/lib/" + dependency.name; fileType = "sourcecode.text-based-dylib-definition"; - + } else if (Path.extension (dependency.path) == "framework") { - + name = Path.withoutDirectory (dependency.path); path = PathHelper.tryFullPath (dependency.path); fileType = "wrapper.framework"; - + } - + if (name != null) { - + var frameworkID = "11C0000000000018" + StringHelper.getUniqueID (); var fileID = "11C0000000000018" + StringHelper.getUniqueID (); - + ArrayHelper.addUnique (context.frameworkSearchPaths, Path.directory (path)); - + context.ADDL_PBX_BUILD_FILE += " " + frameworkID + " /* " + name + " in Frameworks */ = {isa = PBXBuildFile; fileRef = " + fileID + " /* " + name + " */; };\n"; context.ADDL_PBX_FILE_REFERENCE += " " + fileID + " /* " + name + " */ = {isa = PBXFileReference; lastKnownFileType = \"" + fileType + "\"; name = \"" + name + "\"; path = \"" + path + "\"; sourceTree = SDKROOT; };\n"; context.ADDL_PBX_FRAMEWORKS_BUILD_PHASE += " " + frameworkID + " /* " + name + " in Frameworks */,\n"; context.ADDL_PBX_FRAMEWORK_GROUP += " " + fileID + " /* " + name + " */,\n"; - + } - + } - + context.HXML_PATH = PathHelper.findTemplate (project.templatePaths, "tvos/PROJ/haxe/Build.hxml"); context.PRERENDERED_ICON = project.config.getBool ("tvos.prerenderedIcon", false); - + var haxelibPath = project.environment.get ("HAXELIB_PATH"); - + if (haxelibPath != null) { - + context.HAXELIB_PATH = 'export HAXELIB_PATH=$haxelibPath;'; - + } else { - + context.HAXELIB_PATH = ''; - + } - + return context; - + } - - + + private function getDisplayHXML ():String { - + var hxml = PathHelper.findTemplate (project.templatePaths, "tvos/PROJ/haxe/Build.hxml"); var template = new Template (File.getContent (hxml)); - + var context = generateContext (); context.OUTPUT_DIR = targetDirectory; - + return template.execute (context) + "\n-D display"; - + } - - + + public override function rebuild ():Void { - + var arm64 = (command == "rebuild" || (project.architectures.indexOf (Architecture.ARM64) > -1 && !project.targetFlags.exists ("simulator"))); var i386 = (command == "rebuild" || project.targetFlags.exists ("simulator")); var x86_64 = (command == "rebuild" || project.targetFlags.exists ("simulator")); - + var commands = []; - + if (arm64) commands.push ([ "-Dtvos", "-Dappletvos", "-DHXCPP_CPP11", "-DHXCPP_ARM64", "-DOBJC_ARC", "-DENABLE_BITCODE" ]); if (i386) commands.push ([ "-Dtvos", "-Dappletvsim", "-Dsimulator", "-DHXCPP_CPP11", "-DOBJC_ARC", "-DENABLE_BITCODE" ]); if (x86_64) commands.push ([ "-Dtvos", "-Dappletvsim", "-Dsimulator", "-DHXCPP_M64", "-DHXCPP_CPP11", "-DOBJC_ARC", "-DENABLE_BITCODE" ]); - + CPPHelper.rebuild (project, commands); - + } - - + + public override function run ():Void { - + if (project.targetFlags.exists ("xcode")) return; - + TVOSHelper.launch (project, targetDirectory); - + } - - + + public override function update ():Void { - + // project = project.clone (); - + for (asset in project.assets) { - + if (asset.embed && asset.sourcePath == "") { - + var path = PathHelper.combine (targetDirectory + "/" + project.app.file + "/obj/tmp", asset.targetPath); PathHelper.mkdir (Path.directory (path)); FileHelper.copyAsset (asset, path); asset.sourcePath = path; - + } - + } - + //var manifest = new Asset (); //manifest.id = "__manifest__"; //manifest.data = AssetHelper.createManifest (project).serialize (); //manifest.resourceName = manifest.flatName = manifest.targetPath = "manifest"; //manifest.type = AssetType.TEXT; //project.assets.push (manifest); - + var context = generateContext (); context.OUTPUT_DIR = targetDirectory; - + var projectDirectory = targetDirectory + "/" + project.app.file + "/"; - + PathHelper.mkdir (targetDirectory); PathHelper.mkdir (projectDirectory); PathHelper.mkdir (projectDirectory + "/haxe"); PathHelper.mkdir (projectDirectory + "/haxe/lime/installer"); - + var iconSizes:Array = [ { name : "Icon-Small.png", size : 29 }, { name : "Icon-Small-40.png", size : 40 }, @@ -399,30 +401,30 @@ class TVOSPlatform extends PlatformTarget { { name : "Icon-76@2x.png", size : 152 }, { name : "Icon-60@3x.png", size : 180 }, ]; - + context.HAS_ICON = true; - + var iconPath = PathHelper.combine (projectDirectory, "Images.xcassets/AppIcon.appiconset"); PathHelper.mkdir (iconPath); - + var icons = project.icons; - + if (icons.length == 0) { - + icons = [ new Icon (PathHelper.findTemplate (project.templatePaths, "default/icon.svg")) ]; - + } - + for (iconSize in iconSizes) { - + if (!IconHelper.createIcon (icons, iconSize.size, iconSize.size, PathHelper.combine (iconPath, iconSize.name))) { - + context.HAS_ICON = false; - + } - + } - + var splashSizes:Array = [ { name: "Default.png", w: 320, h: 480 }, // iPhone, portrait { name: "Default@2x.png", w: 640, h: 960 }, // iPhone Retina, portrait @@ -435,215 +437,218 @@ class TVOSPlatform extends PlatformTarget { { name: "Default-736h@3x.png", w: 1242, h: 2208 }, // iPhone 6 Plus, portrait { name: "Default-736h-Landscape@3x.png", w: 2208, h: 1242 }, // iPhone 6 Plus, landscape ]; - + var splashScreenPath = PathHelper.combine (projectDirectory, "Images.xcassets/LaunchImage.launchimage"); PathHelper.mkdir (splashScreenPath); - + for (size in splashSizes) { - + var match = false; - + for (splashScreen in project.splashScreens) { - + if (splashScreen.width == size.w && splashScreen.height == size.h && Path.extension (splashScreen.path) == "png") { - + FileHelper.copyFile (splashScreen.path, PathHelper.combine (splashScreenPath, size.name)); match = true; - + } - + } - + if (!match) { - + var imagePath = PathHelper.combine (splashScreenPath, size.name); - + if (!FileSystem.exists (imagePath)) { - + + #if lime LogHelper.info ("", " - \x1b[1mGenerating image:\x1b[0m " + imagePath); - + var image = new Image (null, 0, 0, size.w, size.h, (0xFF << 24) | (project.window.background & 0xFFFFFF)); - var bytes = image.encode ("png"); - + var bytes = image.encode (PNG); + File.saveBytes (imagePath, bytes); - + #end + } - + } - + } - + context.HAS_LAUNCH_IMAGE = true; - + PathHelper.mkdir (projectDirectory + "/resources"); PathHelper.mkdir (projectDirectory + "/haxe/build"); - + FileHelper.recursiveSmartCopyTemplate (project, "tvos/resources", projectDirectory + "/resources", context, true, false); FileHelper.recursiveSmartCopyTemplate (project, "tvos/PROJ/haxe", projectDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "haxe", projectDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "tvos/PROJ/Classes", projectDirectory + "/Classes", context); FileHelper.recursiveSmartCopyTemplate (project, "tvos/PROJ/Images.xcassets", projectDirectory + "/Images.xcassets", context); + FileHelper.copyFileTemplate (project.templatePaths, "tvos/PROJ/PROJ-Entitlements.plist", projectDirectory + "/" + project.app.file + "-Entitlements.plist", context); FileHelper.copyFileTemplate (project.templatePaths, "tvos/PROJ/PROJ-Info.plist", projectDirectory + "/" + project.app.file + "-Info.plist", context); FileHelper.copyFileTemplate (project.templatePaths, "tvos/PROJ/PROJ-Prefix.pch", projectDirectory + "/" + project.app.file + "-Prefix.pch", context); FileHelper.recursiveSmartCopyTemplate (project, "tvos/PROJ.xcodeproj", targetDirectory + "/" + project.app.file + ".xcodeproj", context); - + //SWFHelper.generateSWFClasses (project, projectDirectory + "/haxe"); - + PathHelper.mkdir (projectDirectory + "/lib"); - + for (archID in 0...3) { - + var arch = [ "arm64", "i386", "x86_64" ][archID]; - + if (arch == "arm64" && !context.ARM64) continue; - + var libExt = [ ".appletvos-64.a", ".appletvsim.a", ".appletvsim-64.a" ][archID]; - + PathHelper.mkdir (projectDirectory + "/lib/" + arch); PathHelper.mkdir (projectDirectory + "/lib/" + arch + "-debug"); - + for (ndll in project.ndlls) { - + //if (ndll.haxelib != null) { - + var releaseLib = PathHelper.getLibraryPath (ndll, "AppleTV", "lib", libExt); LogHelper.info("releaseLib: " + releaseLib); var debugLib = PathHelper.getLibraryPath (ndll, "AppleTV", "lib", libExt, true); var releaseDest = projectDirectory + "/lib/" + arch + "/lib" + ndll.name + ".a"; LogHelper.info("releaseDest: " + releaseDest); var debugDest = projectDirectory + "/lib/" + arch + "-debug/lib" + ndll.name + ".a"; - + if (!FileSystem.exists (releaseLib)) { - + releaseLib = PathHelper.getLibraryPath (ndll, "AppleTV", "lib", ".appletvos-64.a"); LogHelper.info("alternative releaseLib: " + releaseLib); debugLib = PathHelper.getLibraryPath (ndll, "AppleTV", "lib", ".appletvos-64.a", true); - + } - + FileHelper.copyIfNewer (releaseLib, releaseDest); - + if (FileSystem.exists (debugLib) && debugLib != releaseLib) { - + FileHelper.copyIfNewer (debugLib, debugDest); - + } else if (FileSystem.exists (debugDest)) { - + FileSystem.deleteFile (debugDest); - + } - + //} - + } - + for (dependency in project.dependencies) { - + if (StringTools.endsWith (dependency.path, ".a")) { - + var fileName = Path.withoutDirectory (dependency.path); - + if (!StringTools.startsWith (fileName, "lib")) { - + fileName = "lib" + fileName; - + } - + FileHelper.copyIfNewer (dependency.path, projectDirectory + "/lib/" + arch + "/" + fileName); - + } - + } - + } - + PathHelper.mkdir (projectDirectory + "/assets"); - + for (asset in project.assets) { - + if (asset.type != AssetType.TEMPLATE) { - + var targetPath = PathHelper.combine (projectDirectory + "/assets/", asset.resourceName); - + //var sourceAssetPath:String = projectDirectory + "haxe/" + asset.sourcePath; - + PathHelper.mkdir (Path.directory (targetPath)); FileHelper.copyAssetIfNewer (asset, targetPath); - + //PathHelper.mkdir (Path.directory (sourceAssetPath)); //FileHelper.linkFile (flatAssetPath, sourceAssetPath, true, true); - + } else { - + var targetPath = PathHelper.combine (projectDirectory, asset.targetPath); - + PathHelper.mkdir (Path.directory (targetPath)); FileHelper.copyAsset (asset, targetPath, context); - + } - + } - + if (project.targetFlags.exists ("xcode") && PlatformHelper.hostPlatform == Platform.MAC && command == "update") { - + ProcessHelper.runCommand ("", "open", [ targetDirectory + "/" + project.app.file + ".xcodeproj" ] ); - + } - + } - - + + /*private function updateLaunchImage () { - + var destination = buildDirectory + "/ios"; PathHelper.mkdir (destination); - + var has_launch_image = false; if (launchImages.length > 0) has_launch_image = true; - + for (launchImage in launchImages) { - + var splitPath = launchImage.name.split ("/"); var path = destination + "/" + splitPath[splitPath.length - 1]; FileHelper.copyFile (launchImage.name, path, context, false); - + } - + context.HAS_LAUNCH_IMAGE = has_launch_image; - + }*/ - - + + public override function watch ():Void { - + var dirs = WatchHelper.processHXML (project, getDisplayHXML ()); var command = WatchHelper.getCurrentCommand (); WatchHelper.watch (project, command, dirs); - + } - - + + @ignore public override function install ():Void {} @ignore public override function trace ():Void {} @ignore public override function uninstall ():Void {} - - + + } private typedef IconSize = { - + name:String, size:Int, - + } private typedef SplashSize = { - + name:String, w:Int, h:Int, - -} \ No newline at end of file + +} diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 52b4a65ca..8c365aa7f 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -298,7 +298,7 @@ class WindowsPlatform extends PlatformTarget { if (IconHelper.createWindowsIcon (icons, iconPath) && PlatformHelper.hostPlatform == Platform.WINDOWS) { - var templates = [ PathHelper.getHaxelib (new Haxelib ("lime")) + "/templates" ].concat (project.templatePaths); + var templates = [ PathHelper.getHaxelib (new Haxelib (#if lime "lime" #else "hxp" #end)) + "/templates" ].concat (project.templatePaths); ProcessHelper.runCommand ("", PathHelper.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ executablePath, iconPath, "1" ], true, true); } @@ -403,13 +403,31 @@ class WindowsPlatform extends PlatformTarget { var commands = []; - if (targetFlags.exists ("64")) { + if (!targetFlags.exists ("32") && PlatformHelper.hostArchitecture == X64) { - commands.push ([ "-Dwindow", "-DHXCPP_M64" ]); + if (targetFlags.exists ("winrt")) { + + commands.push ([ "-Dwinrt", "-DHXCPP_M64" ]); + + } else { + + commands.push ([ "-Dwindows", "-DHXCPP_M64" ]); + + } - } else { + } + + if (!targetFlags.exists ("64") && (command == "rebuild" || PlatformHelper.hostArchitecture == Architecture.X86)) { - commands.push ([ "-Dwindow", "-DHXCPP_M32" ]); + if (targetFlags.exists ("winrt")) { + + commands.push ([ "-Dwinrt", "-DHXCPP_M32" ]); + + } else { + + commands.push ([ "-Dwindows", "-DHXCPP_M32" ]); + + } } @@ -552,19 +570,16 @@ class WindowsPlatform extends PlatformTarget { if (targetType == "cpp" && project.targetFlags.exists ("static")) { - // TODO: Better way to detect the suffix HXCPP will use? + var programFiles = project.environment.get ("ProgramFiles(x86)"); + var hasVSCommunity = (programFiles != null && FileSystem.exists (PathHelper.combine (programFiles, "Microsoft Visual Studio/Installer/vswhere.exe"))); + var hxcppMSVC = project.environment.get ("HXCPP_MSVC"); + var vs140 = project.environment.get ("VS140COMNTOOLS"); var msvc19 = true; - var olderVersions = [ "120", "110", "100", "90", "80", "71", "70" ]; - for (olderVersion in olderVersions) { + if ((!hasVSCommunity && vs140 == null) || (hxcppMSVC != null && hxcppMSVC != vs140)) { - if (project.environment.exists ("VS" + olderVersion + "COMNTOOLS")) { - - msvc19 = false; - break; - - } + msvc19 = false; } @@ -867,4 +882,4 @@ class WindowsPlatform extends PlatformTarget { @ignore public override function uninstall ():Void {} -} \ No newline at end of file +} diff --git a/tools/tools.hxml b/tools/tools.hxml index 44c6c69ea..01977752a 100644 --- a/tools/tools.hxml +++ b/tools/tools.hxml @@ -3,6 +3,7 @@ -D lime-curl -D lime-cffi -D lime +-cp platforms -cp ../src -lib format -lib hxp