Implement lime setup hl in a hopefully better way.

This commit is contained in:
Apprentice-Alchemist
2022-03-12 21:37:23 +01:00
parent 18f680e247
commit cb3b0240de
5 changed files with 126 additions and 66 deletions

View File

@@ -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"));
}
}

View File

@@ -1,5 +1,6 @@
package; package;
import lime.tools.HashlinkHelper;
import hxp.Haxelib; import hxp.Haxelib;
import hxp.HXML; import hxp.HXML;
import hxp.Path; import hxp.Path;
@@ -220,19 +221,7 @@ class LinuxPlatform extends PlatformTarget
if (noOutput) return; if (noOutput) return;
// System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl", HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath);
// 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);
}
}
} }
else if (targetType == "nodejs") else if (targetType == "nodejs")
{ {

View File

@@ -1,5 +1,6 @@
package; package;
import lime.tools.HashlinkHelper;
import hxp.Haxelib; import hxp.Haxelib;
import hxp.HXML; import hxp.HXML;
import hxp.Log; import hxp.Log;
@@ -205,19 +206,21 @@ class MacPlatform extends PlatformTarget
if (noOutput) return; if (noOutput) return;
// System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl", HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath);
// Path.combine(executableDirectory, project.app.file + ".hl"));
System.recursiveCopyTemplate(project.templatePaths, "bin/hl/mac", executableDirectory); // // System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".hl",
// let's not keep around hxcpp's hash files // // Path.combine(executableDirectory, project.app.file + ".hl"));
for (file in System.readDirectory(applicationDirectory)) // System.recursiveCopyTemplate(project.templatePaths, "bin/hl/mac", executableDirectory);
{ // // let's not keep around hxcpp's hash files
if (Path.extension(file) == "hash") // for (file in System.readDirectory(applicationDirectory))
{ // {
System.deleteFile(file); // 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); // }
// System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(executableDirectory, "hlboot.dat"));
// System.renameFile(Path.combine(executableDirectory, "hl"), executablePath);
} }
else if (targetType == "java") else if (targetType == "java")
{ {

View File

@@ -1,5 +1,6 @@
package; package;
import lime.tools.HashlinkHelper;
import hxp.Haxelib; import hxp.Haxelib;
import hxp.HXML; import hxp.HXML;
import hxp.Log; import hxp.Log;
@@ -341,10 +342,12 @@ class WindowsPlatform extends PlatformTarget
if (noOutput) return; if (noOutput) return;
HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath);
// System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, project.app.file + ".hl")); // System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, project.app.file + ".hl"));
System.recursiveCopyTemplate(project.templatePaths, "bin/hl/windows", applicationDirectory); // System.recursiveCopyTemplate(project.templatePaths, "bin/hl/windows", applicationDirectory);
System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat")); // System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat"));
System.renameFile(Path.combine(applicationDirectory, "hl.exe"), executablePath); // System.renameFile(Path.combine(applicationDirectory, "hl.exe"), executablePath);
// let's not keep around hxcpp's hash files // let's not keep around hxcpp's hash files
for (file in System.readDirectory(applicationDirectory)) for (file in System.readDirectory(applicationDirectory))
{ {

View File

@@ -1185,47 +1185,55 @@ class PlatformSetup
public static function setupHL():Void 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) if (System.hostPlatform == MAC)
{ {
Log.println("To use the hashlink debugger on macOS, the hl executable needs to be signed."); 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 (ConfigHelper.getConfigValue("HL_PATH") != null)
if (answer == YES || answer == ALWAYS)
{ {
final openSSLConf = System.getTemporaryFile("cnf"); Log.println("When building HL from source, make sure to have run `make codesign_osx` before installing.");
final key = System.getTemporaryFile("pem"); }
final cert = System.getTemporaryFile("cer"); else
final limePath = Haxelib.getPath(new Haxelib("lime")); {
final hlPath = limePath + "/templates/bin/hl/mac/hl"; var answer = CLIHelper.ask("Would you like to do this now? (Requires sudo.)");
final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath +
"/project/lib/hashlink/other/osx/entitlements.xml") : (limePath if (answer == YES || answer == ALWAYS)
+ "/templates/bin/hl/entitlements.xml"); {
System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true); final openSSLConf = System.getTemporaryFile("cnf");
sys.io.File.saveContent(openSSLConf, [ final key = System.getTemporaryFile("pem");
"[req]", final cert = System.getTemporaryFile("cer");
"distinguished_name=codesign_dn", final limePath = Haxelib.getPath(new Haxelib("lime"));
"[codesign_dn]", final hlPath = limePath + "/templates/bin/hl/mac/hl";
"commonName=hl-cert", final entitlementsPath = sys.FileSystem.exists(limePath + "/project") ? (limePath +
"[v3_req]", "/project/lib/hashlink/other/osx/entitlements.xml") : (limePath
"keyUsage=critical,digitalSignature", + "/templates/bin/hl/entitlements.xml");
"extendedKeyUsage=critical,codeSigning", System.runCommand("", "sudo", ["security", "delete-identity", "-c", "hl-cert"], true, false, true);
].join("\n")); sys.io.File.saveContent(openSSLConf, [
System.runCommand("", "openssl", [ "[req]",
"req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out", cert, "distinguished_name=codesign_dn",
"-extensions", "v3_req", "-config", openSSLConf "[codesign_dn]",
], true, false, true); "commonName=hl-cert",
System.runCommand("", "sudo", [ "[v3_req]",
"security", "keyUsage=critical,digitalSignature",
"add-trusted-cert", "extendedKeyUsage=critical,codeSigning",
"-d", ].join("\n"));
"-k /Library/Keychains/System.keychain", System.runCommand("", "openssl", [
cert "req", "-x509", "-newkey", "rsa:4096", "-keyout", key, "-nodes", "-days", "365", "-subj", "/CN=hl-cert", "-outform", "der", "-out",
], true, false, true); cert, "-extensions", "v3_req", "-config", openSSLConf
System.runCommand("", "sudo", ["security", "import", key, "-k", "/Library/Keychains/System.keychain", "-A"], true, false, true); ], true, false, true);
System.runCommand("", "codesign", ["--entitlements", entitlementsPath, "-fs", "hl-cert", hlPath], true, false, true); System.runCommand("", "sudo", [
for (f in [key, cert, openSSLConf]) "security",
sys.FileSystem.deleteFile(f); "add-trusted-cert",
Log.println("\nIf you update lime, yo will have to run this again to sign the new hl executable"); "-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");
}
} }
} }
} }