diff --git a/src/lime/tools/HashlinkHelper.hx b/src/lime/tools/HashlinkHelper.hx new file mode 100644 index 0000000000..a1496f1cbc --- /dev/null +++ b/src/lime/tools/HashlinkHelper.hx @@ -0,0 +1,57 @@ +package lime.tools; + +import lime.tools.ConfigHelper; +import lime.tools.HXProject; +import lime.tools.Platform; +import hxp.Path; +import hxp.System; + +class HashlinkHelper +{ + public static function copyHashlink(project:HXProject, targetDirectory:String, applicationDirectory:String, executablePath:String) + { + final platform = project.target; + + final hlPath = ConfigHelper.getConfigValue("HL_PATH"); + if (hlPath == null) + { + System.recursiveCopyTemplate(project.templatePaths, 'bin/hl/$platform', applicationDirectory); + } + else + { + System.copyFile(Path.combine(hlPath, "hl" + (platform == WINDOWS ? ".exe" : "")), executablePath); + if (platform == WINDOWS) + { + System.copyFile(Path.combine(hlPath, "libhl.dll"), Path.combine(applicationDirectory, "libhl.dll")); + System.copyFile(Path.combine(hlPath, "msvcr120.dll"), Path.combine(applicationDirectory, "msvcr120.dll")); + } + else if (platform == MAC || platform == IOS) + { + System.copyFile(Path.combine(hlPath, "libhl.dylib"), Path.combine(applicationDirectory, "libhl.dylib")); + } + else + { + System.copyFile(Path.combine(hlPath, "libhl.so"), Path.combine(applicationDirectory, "libhl.so")); + } + + for (file in System.readDirectory(hlPath) + .filter(f -> Path.extension(f) == "hdll" + && Path.withoutDirectory(f) != "sdl.hdll" + && Path.withoutDirectory(f) != "openal.hdll")) + { + System.copyFile(file, Path.combine(applicationDirectory, Path.withoutDirectory(file))); + } + } + + // make sure no hxcpp hash files remain + + for (file in System.readDirectory(applicationDirectory)) + { + if (Path.extension(file) == "hash") + { + System.deleteFile(file); + } + } + System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat")); + } +} diff --git a/tools/platforms/LinuxPlatform.hx b/tools/platforms/LinuxPlatform.hx index 0b70dd69ee..41c828258a 100644 --- a/tools/platforms/LinuxPlatform.hx +++ b/tools/platforms/LinuxPlatform.hx @@ -1,5 +1,6 @@ package; +import lime.tools.HashlinkHelper; import hxp.Haxelib; import hxp.HXML; import hxp.Path; @@ -137,19 +138,7 @@ class LinuxPlatform extends PlatformTarget if (noOutput) return; - // System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl", - // Path.combine(applicationDirectory, project.app.file + ".hl")); - System.recursiveCopyTemplate(project.templatePaths, "bin/hl/linux", applicationDirectory); - System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat")); - System.renameFile(Path.combine(applicationDirectory, "hl"), executablePath); - // let's not keep around hxcpp's hash files - for (file in System.readDirectory(applicationDirectory)) - { - if (Path.extension(file) == "hash") - { - System.deleteFile(file); - } - } + HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath); } else if (targetType == "nodejs") { diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 969d553602..9d290fd791 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -1,5 +1,6 @@ package; +import lime.tools.HashlinkHelper; import hxp.Haxelib; import hxp.HXML; import hxp.Log; @@ -122,19 +123,21 @@ class MacPlatform extends PlatformTarget if (noOutput) return; - // System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl", - // Path.combine(executableDirectory, project.app.file + ".hl")); - System.recursiveCopyTemplate(project.templatePaths, "bin/hl/mac", executableDirectory); - // let's not keep around hxcpp's hash files - for (file in System.readDirectory(applicationDirectory)) - { - if (Path.extension(file) == "hash") - { - System.deleteFile(file); - } - } - System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(executableDirectory, "hlboot.dat")); - System.renameFile(Path.combine(executableDirectory, "hl"), executablePath); + HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath); + + // // System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl", + // // Path.combine(executableDirectory, project.app.file + ".hl")); + // System.recursiveCopyTemplate(project.templatePaths, "bin/hl/mac", executableDirectory); + // // let's not keep around hxcpp's hash files + // for (file in System.readDirectory(applicationDirectory)) + // { + // if (Path.extension(file) == "hash") + // { + // System.deleteFile(file); + // } + // } + // System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(executableDirectory, "hlboot.dat")); + // System.renameFile(Path.combine(executableDirectory, "hl"), executablePath); } else if (targetType == "java") { diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index ff9f039e68..b6fa44b2cf 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -1,5 +1,6 @@ package; +import lime.tools.HashlinkHelper; import hxp.Haxelib; import hxp.HXML; import hxp.Log; @@ -249,10 +250,12 @@ class WindowsPlatform extends PlatformTarget if (noOutput) return; + HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath); + // System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, project.app.file + ".hl")); - System.recursiveCopyTemplate(project.templatePaths, "bin/hl/windows", applicationDirectory); - System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat")); - System.renameFile(Path.combine(applicationDirectory, "hl.exe"), executablePath); + // System.recursiveCopyTemplate(project.templatePaths, "bin/hl/windows", applicationDirectory); + // System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat")); + // System.renameFile(Path.combine(applicationDirectory, "hl.exe"), executablePath); // let's not keep around hxcpp's hash files for (file in System.readDirectory(applicationDirectory)) { diff --git a/tools/utils/PlatformSetup.hx b/tools/utils/PlatformSetup.hx index c982d76e12..2d65c61485 100644 --- a/tools/utils/PlatformSetup.hx +++ b/tools/utils/PlatformSetup.hx @@ -1185,47 +1185,55 @@ class PlatformSetup public static function setupHL():Void { + getDefineValue("HL_PATH", "Path to a custom version of Hashlink. Leave empty to use lime's default version."); if (System.hostPlatform == MAC) { Log.println("To use the hashlink debugger on macOS, the hl executable needs to be signed."); - var answer = CLIHelper.ask("Would you like to do this now? (Requires sudo.)"); - - if (answer == YES || answer == ALWAYS) + if (ConfigHelper.getConfigValue("HL_PATH") != null) + { + Log.println("When building HL from source, make sure to have run `make codesign_osx` before installing."); + } + else { - final openSSLConf = System.getTemporaryFile("cnf"); - final key = System.getTemporaryFile("pem"); - final cert = System.getTemporaryFile("cer"); - final limePath = Haxelib.getPath(new Haxelib("lime")); - final hlPath = limePath + "/templates/bin/hl/mac/hl"; - final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath + - "/project/lib/hashlink/other/osx/entitlements.xml") : (limePath - + "/templates/bin/hl/entitlements.xml"); - System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true); - sys.io.File.saveContent(openSSLConf, [ - "[req]", - "distinguished_name=codesign_dn", - "[codesign_dn]", - "commonName=hl-cert", - "[v3_req]", - "keyUsage=critical,digitalSignature", - "extendedKeyUsage=critical,codeSigning", - ].join("\n")); - System.runCommand("", "openssl", [ - "req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out", cert, - "-extensions", "v3_req", "-config", openSSLConf - ], true, false, true); - System.runCommand("", "sudo", [ - "security", - "add-trusted-cert", - "-d", - "-k /Library/Keychains/System.keychain", - cert - ], true, false, true); - System.runCommand("", "sudo", ["security", "import", key, "-k", "/Library/Keychains/System.keychain", "-A"], true, false, true); - System.runCommand("", "codesign", ["--entitlements", entitlementsPath, "-fs", "hl-cert", hlPath], true, false, true); - for (f in [key, cert, openSSLConf]) - sys.FileSystem.deleteFile(f); - Log.println("\nIf you update lime, yo will have to run this again to sign the new hl executable"); + var answer = CLIHelper.ask("Would you like to do this now? (Requires sudo.)"); + + if (answer == YES || answer == ALWAYS) + { + final openSSLConf = System.getTemporaryFile("cnf"); + final key = System.getTemporaryFile("pem"); + final cert = System.getTemporaryFile("cer"); + final limePath = Haxelib.getPath(new Haxelib("lime")); + final hlPath = limePath + "/templates/bin/hl/mac/hl"; + final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath + + "/project/lib/hashlink/other/osx/entitlements.xml") : (limePath + + "/templates/bin/hl/entitlements.xml"); + System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true); + sys.io.File.saveContent(openSSLConf, [ + "[req]", + "distinguished_name=codesign_dn", + "[codesign_dn]", + "commonName=hl-cert", + "[v3_req]", + "keyUsage=critical,digitalSignature", + "extendedKeyUsage=critical,codeSigning", + ].join("\n")); + System.runCommand("", "openssl", [ + "req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out", + cert, "-extensions", "v3_req", "-config", openSSLConf + ], true, false, true); + System.runCommand("", "sudo", [ + "security", + "add-trusted-cert", + "-d", + "-k /Library/Keychains/System.keychain", + cert + ], true, false, true); + System.runCommand("", "sudo", ["security", "import", key, "-k", "/Library/Keychains/System.keychain", "-A"], true, false, true); + System.runCommand("", "codesign", ["--entitlements", entitlementsPath, "-fs", "hl-cert", hlPath], true, false, true); + for (f in [key, cert, openSSLConf]) + sys.FileSystem.deleteFile(f); + Log.println("\nIf you update lime, yo will have to run this again to sign the new hl executable"); + } } } }