Std.parseFloat fix on Haxe interp

This commit is contained in:
Joshua Granick
2018-07-24 16:50:38 -07:00
parent 7ffd8f1bcf
commit 6c2ef7905c
3 changed files with 465 additions and 450 deletions

View File

@@ -20,168 +20,173 @@ import sys.FileSystem;
class EmscriptenPlatform extends PlatformTarget { class EmscriptenPlatform extends PlatformTarget {
private var outputFile:String; private var outputFile:String;
public function new (command:String, _project:HXProject, targetFlags:Map<String, String>) { public function new (command:String, _project:HXProject, targetFlags:Map<String, String>) {
super (command, _project, targetFlags); super (command, _project, targetFlags);
targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("emscripten.output-directory", "emscripten")); targetDirectory = PathHelper.combine (project.app.path, project.config.getString ("emscripten.output-directory", "emscripten"));
outputFile = targetDirectory + "/bin/" + project.app.file + ".js"; outputFile = targetDirectory + "/bin/" + project.app.file + ".js";
} }
public override function build ():Void { public override function build ():Void {
var sdkPath = null; var sdkPath = null;
if (project.defines.exists ("EMSCRIPTEN_SDK")) { if (project.defines.exists ("EMSCRIPTEN_SDK")) {
sdkPath = project.defines.get ("EMSCRIPTEN_SDK"); sdkPath = project.defines.get ("EMSCRIPTEN_SDK");
} else if (project.environment.exists ("EMSCRIPTEN_SDK")) { } else if (project.environment.exists ("EMSCRIPTEN_SDK")) {
sdkPath = project.environment.get ("EMSCRIPTEN_SDK"); sdkPath = project.environment.get ("EMSCRIPTEN_SDK");
} }
if (sdkPath == null) { if (sdkPath == null) {
LogHelper.error ("You must define EMSCRIPTEN_SDK with the path to your Emscripten SDK"); LogHelper.error ("You must define EMSCRIPTEN_SDK with the path to your Emscripten SDK");
} }
var hxml = targetDirectory + "/haxe/" + buildType + ".hxml"; var hxml = targetDirectory + "/haxe/" + buildType + ".hxml";
var args = [ hxml, "-D", "emscripten", "-D", "webgl", "-D", "static_link"]; var args = [ hxml, "-D", "emscripten", "-D", "webgl", "-D", "static_link"];
if (LogHelper.verbose) { if (LogHelper.verbose) {
args.push ("-D"); args.push ("-D");
args.push ("verbose"); args.push ("verbose");
} }
ProcessHelper.runCommand ("", "haxe", args); ProcessHelper.runCommand ("", "haxe", args);
if (noOutput) return; if (noOutput) return;
CPPHelper.compile (project, targetDirectory + "/obj", [ "-Demscripten", "-Dwebgl", "-Dstatic_link" ]); CPPHelper.compile (project, targetDirectory + "/obj", [ "-Demscripten", "-Dwebgl", "-Dstatic_link" ]);
project.path (sdkPath); project.path (sdkPath);
ProcessHelper.runCommand ("", "emcc", [ targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o" ], true, false, true); ProcessHelper.runCommand ("", "emcc", [ targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o" ], true, false, true);
args = [ "Main.o" ]; args = [ "Main.o" ];
for (ndll in project.ndlls) { for (ndll in project.ndlls) {
var path = PathHelper.getLibraryPath (ndll, "Emscripten", "lib", ".a", project.debug); var path = PathHelper.getLibraryPath (ndll, "Emscripten", "lib", ".a", project.debug);
args.push (path); args.push (path);
} }
var json = Json.parse (File.getContent (PathHelper.getHaxelib (new Haxelib ("hxcpp"), true) + "/haxelib.json")); var json = Json.parse (File.getContent (PathHelper.getHaxelib (new Haxelib ("hxcpp"), true) + "/haxelib.json"));
var prefix = ""; var prefix = "";
if (Std.parseFloat (json.version) > 3.1) { var version = Std.string (json.version);
var versionSplit = version.split (".");
while (versionSplit.length > 2) versionSplit.pop ();
if (Std.parseFloat (versionSplit.join (".")) > 3.1) {
prefix = "lib"; prefix = "lib";
} }
args = args.concat ([ prefix + "ApplicationMain" + (project.debug ? "-debug" : "") + ".a", "-o", "ApplicationMain.o" ]); args = args.concat ([ prefix + "ApplicationMain" + (project.debug ? "-debug" : "") + ".a", "-o", "ApplicationMain.o" ]);
ProcessHelper.runCommand (targetDirectory + "/obj", "emcc", args, true, false, true); ProcessHelper.runCommand (targetDirectory + "/obj", "emcc", args, true, false, true);
args = [ "ApplicationMain.o" ]; args = [ "ApplicationMain.o" ];
if (project.targetFlags.exists ("webassembly") || project.targetFlags.exists ("wasm")) { if (project.targetFlags.exists ("webassembly") || project.targetFlags.exists ("wasm")) {
args.push ("-s"); args.push ("-s");
args.push ("WASM=1"); args.push ("WASM=1");
} else { } else {
args.push ("-s"); args.push ("-s");
args.push ("ASM_JS=1"); args.push ("ASM_JS=1");
} }
args.push ("-s"); args.push ("-s");
args.push ("NO_EXIT_RUNTIME=1"); args.push ("NO_EXIT_RUNTIME=1");
args.push ("-s"); args.push ("-s");
args.push ("USE_SDL=2"); args.push ("USE_SDL=2");
for (dependency in project.dependencies) { for (dependency in project.dependencies) {
if (dependency.name != "") { if (dependency.name != "") {
args.push ("-l" + dependency.name); args.push ("-l" + dependency.name);
} }
} }
if (project.targetFlags.exists ("final")) { if (project.targetFlags.exists ("final")) {
args.push ("-s"); args.push ("-s");
args.push ("DISABLE_EXCEPTION_CATCHING=0"); args.push ("DISABLE_EXCEPTION_CATCHING=0");
args.push ("-O3"); args.push ("-O3");
} else if (!project.debug) { } else if (!project.debug) {
args.push ("-s"); args.push ("-s");
args.push ("DISABLE_EXCEPTION_CATCHING=0"); args.push ("DISABLE_EXCEPTION_CATCHING=0");
//args.push ("-s"); //args.push ("-s");
//args.push ("OUTLINING_LIMIT=70000"); //args.push ("OUTLINING_LIMIT=70000");
args.push ("-O2"); args.push ("-O2");
} else { } else {
args.push ("-s"); args.push ("-s");
args.push ("DISABLE_EXCEPTION_CATCHING=2"); args.push ("DISABLE_EXCEPTION_CATCHING=2");
args.push ("-s"); args.push ("-s");
args.push ("ASSERTIONS=1"); args.push ("ASSERTIONS=1");
args.push ("-O1"); args.push ("-O1");
} }
args.push ("-s"); args.push ("-s");
args.push ("ALLOW_MEMORY_GROWTH=1"); args.push ("ALLOW_MEMORY_GROWTH=1");
if (project.targetFlags.exists ("minify")) { if (project.targetFlags.exists ("minify")) {
// 02 enables minification // 02 enables minification
//args.push ("--minify"); //args.push ("--minify");
//args.push ("1"); //args.push ("1");
//args.push ("--closure"); //args.push ("--closure");
//args.push ("1"); //args.push ("1");
} }
//args.push ("--memory-init-file"); //args.push ("--memory-init-file");
//args.push ("1"); //args.push ("1");
//args.push ("--jcache"); //args.push ("--jcache");
//args.push ("-g"); //args.push ("-g");
if (FileSystem.exists (targetDirectory + "/obj/assets")) { if (FileSystem.exists (targetDirectory + "/obj/assets")) {
args.push ("--preload-file"); args.push ("--preload-file");
args.push ("assets"); args.push ("assets");
} }
if (LogHelper.verbose) { if (LogHelper.verbose) {
args.push ("-v"); args.push ("-v");
} }
//if (project.targetFlags.exists ("compress")) { //if (project.targetFlags.exists ("compress")) {
// //
//args.push ("--compression"); //args.push ("--compression");
@@ -191,119 +196,119 @@ class EmscriptenPlatform extends PlatformTarget {
//args.push ("../bin/index.html"); //args.push ("../bin/index.html");
// //
//} else { //} else {
args.push ("-o"); args.push ("-o");
args.push ("../bin/" + project.app.file + ".js"); args.push ("../bin/" + project.app.file + ".js");
//} //}
//args.push ("../bin/index.html"); //args.push ("../bin/index.html");
ProcessHelper.runCommand (targetDirectory + "/obj", "emcc", args, true, false, true); ProcessHelper.runCommand (targetDirectory + "/obj", "emcc", args, true, false, true);
if (project.targetFlags.exists ("minify")) { if (project.targetFlags.exists ("minify")) {
HTML5Helper.minify (project, targetDirectory + "/bin/" + project.app.file + ".js"); HTML5Helper.minify (project, targetDirectory + "/bin/" + project.app.file + ".js");
} }
if (project.targetFlags.exists ("compress")) { if (project.targetFlags.exists ("compress")) {
if (FileSystem.exists (targetDirectory + "/bin/" + project.app.file + ".data")) { if (FileSystem.exists (targetDirectory + "/bin/" + project.app.file + ".data")) {
//var byteArray = ByteArray.readFile (targetDirectory + "/bin/" + project.app.file + ".data"); //var byteArray = ByteArray.readFile (targetDirectory + "/bin/" + project.app.file + ".data");
//byteArray.compress (CompressionAlgorithm.GZIP); //byteArray.compress (CompressionAlgorithm.GZIP);
//File.saveBytes (targetDirectory + "/bin/" + project.app.file + ".data.compress", byteArray); //File.saveBytes (targetDirectory + "/bin/" + project.app.file + ".data.compress", byteArray);
} }
//var byteArray = ByteArray.readFile (targetDirectory + "/bin/" + project.app.file + ".js"); //var byteArray = ByteArray.readFile (targetDirectory + "/bin/" + project.app.file + ".js");
//byteArray.compress (CompressionAlgorithm.GZIP); //byteArray.compress (CompressionAlgorithm.GZIP);
//File.saveBytes (targetDirectory + "/bin/" + project.app.file + ".js.compress", byteArray); //File.saveBytes (targetDirectory + "/bin/" + project.app.file + ".js.compress", byteArray);
} else { } else {
File.saveContent (targetDirectory + "/bin/.htaccess", "SetOutputFilter DEFLATE"); File.saveContent (targetDirectory + "/bin/.htaccess", "SetOutputFilter DEFLATE");
} }
} }
public override function clean ():Void { public override function clean ():Void {
if (FileSystem.exists (targetDirectory)) { if (FileSystem.exists (targetDirectory)) {
PathHelper.removeDirectory (targetDirectory); PathHelper.removeDirectory (targetDirectory);
} }
} }
public override function deploy ():Void { public override function deploy ():Void {
DeploymentHelper.deploy (project, targetFlags, targetDirectory, "Emscripten"); DeploymentHelper.deploy (project, targetFlags, targetDirectory, "Emscripten");
} }
public override function display ():Void { public override function display ():Void {
var hxml = PathHelper.findTemplate (project.templatePaths, "emscripten/hxml/" + buildType + ".hxml"); var hxml = PathHelper.findTemplate (project.templatePaths, "emscripten/hxml/" + buildType + ".hxml");
var context = project.templateContext; var context = project.templateContext;
context.OUTPUT_DIR = targetDirectory; context.OUTPUT_DIR = targetDirectory;
context.OUTPUT_FILE = outputFile; context.OUTPUT_FILE = outputFile;
var template = new Template (File.getContent (hxml)); var template = new Template (File.getContent (hxml));
Sys.println (template.execute (context)); Sys.println (template.execute (context));
Sys.println ("-D display"); Sys.println ("-D display");
} }
public override function rebuild ():Void { public override function rebuild ():Void {
CPPHelper.rebuild (project, [[ "-Demscripten", "-Dstatic_link" ]]); CPPHelper.rebuild (project, [[ "-Demscripten", "-Dstatic_link" ]]);
} }
public override function run ():Void { public override function run ():Void {
HTML5Helper.launch (project, targetDirectory + "/bin"); HTML5Helper.launch (project, targetDirectory + "/bin");
} }
public override function update ():Void { public override function update ():Void {
// project = project.clone (); // project = project.clone ();
for (asset in project.assets) { for (asset in project.assets) {
if (asset.embed && asset.sourcePath == "") { if (asset.embed && asset.sourcePath == "") {
var path = PathHelper.combine (targetDirectory + "/obj/tmp", asset.targetPath); var path = PathHelper.combine (targetDirectory + "/obj/tmp", asset.targetPath);
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
FileHelper.copyAsset (asset, path); FileHelper.copyAsset (asset, path);
asset.sourcePath = path; asset.sourcePath = path;
} }
} }
for (asset in project.assets) { for (asset in project.assets) {
asset.resourceName = "assets/" + asset.resourceName; asset.resourceName = "assets/" + asset.resourceName;
} }
var destination = targetDirectory + "/bin/"; var destination = targetDirectory + "/bin/";
PathHelper.mkdir (destination); PathHelper.mkdir (destination);
//for (asset in project.assets) { //for (asset in project.assets) {
// //
//if (asset.type == AssetType.FONT) { //if (asset.type == AssetType.FONT) {
@@ -313,62 +318,62 @@ class EmscriptenPlatform extends PlatformTarget {
//} //}
// //
//} //}
if (project.targetFlags.exists ("xml")) { if (project.targetFlags.exists ("xml")) {
project.haxeflags.push ("-xml " + targetDirectory + "/types.xml"); project.haxeflags.push ("-xml " + targetDirectory + "/types.xml");
} }
var context = project.templateContext; var context = project.templateContext;
context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6); context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6);
context.OUTPUT_DIR = targetDirectory; context.OUTPUT_DIR = targetDirectory;
context.OUTPUT_FILE = outputFile; context.OUTPUT_FILE = outputFile;
context.CPP_DIR = targetDirectory + "/obj"; context.CPP_DIR = targetDirectory + "/obj";
context.USE_COMPRESSION = project.targetFlags.exists ("compress"); context.USE_COMPRESSION = project.targetFlags.exists ("compress");
for (asset in project.assets) { for (asset in project.assets) {
var path = PathHelper.combine (targetDirectory + "/obj/assets", asset.targetPath); var path = PathHelper.combine (targetDirectory + "/obj/assets", asset.targetPath);
if (asset.type != AssetType.TEMPLATE) { if (asset.type != AssetType.TEMPLATE) {
//if (asset.type != AssetType.FONT) { //if (asset.type != AssetType.FONT) {
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
FileHelper.copyAssetIfNewer (asset, path); FileHelper.copyAssetIfNewer (asset, path);
//} //}
} }
} }
FileHelper.recursiveSmartCopyTemplate (project, "emscripten/template", destination, context); FileHelper.recursiveSmartCopyTemplate (project, "emscripten/template", destination, context);
FileHelper.recursiveSmartCopyTemplate (project, "haxe", targetDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "haxe", targetDirectory + "/haxe", context);
FileHelper.recursiveSmartCopyTemplate (project, "emscripten/hxml", targetDirectory + "/haxe", context); FileHelper.recursiveSmartCopyTemplate (project, "emscripten/hxml", targetDirectory + "/haxe", context);
FileHelper.recursiveSmartCopyTemplate (project, "emscripten/cpp", targetDirectory + "/obj", context); FileHelper.recursiveSmartCopyTemplate (project, "emscripten/cpp", targetDirectory + "/obj", context);
for (asset in project.assets) { for (asset in project.assets) {
var path = PathHelper.combine (destination, asset.targetPath); var path = PathHelper.combine (destination, asset.targetPath);
if (asset.type == AssetType.TEMPLATE) { if (asset.type == AssetType.TEMPLATE) {
PathHelper.mkdir (Path.directory (path)); PathHelper.mkdir (Path.directory (path));
FileHelper.copyAsset (asset, path, context); FileHelper.copyAsset (asset, path, context);
} }
} }
} }
@ignore public override function install ():Void {} @ignore public override function install ():Void {}
@ignore public override function trace ():Void {} @ignore public override function trace ():Void {}
@ignore public override function uninstall ():Void {} @ignore public override function uninstall ():Void {}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -215,7 +215,12 @@ class TVOSPlatform extends PlatformTarget {
var json = Json.parse (File.getContent (PathHelper.getHaxelib (new Haxelib ("hxcpp"), true) + "/haxelib.json")); var json = Json.parse (File.getContent (PathHelper.getHaxelib (new Haxelib ("hxcpp"), true) + "/haxelib.json"));
if (Std.parseFloat (json.version) > 3.1) { var version = Std.string (json.version);
var versionSplit = version.split (".");
while (versionSplit.length > 2) versionSplit.pop ();
if (Std.parseFloat (versionSplit.join (".")) > 3.1) {
context.CPP_LIBPREFIX = "lib"; context.CPP_LIBPREFIX = "lib";