Skip to content

Commit

Permalink
Implement lime setup hl in a hopefully better way.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apprentice-Alchemist committed Mar 12, 2022
1 parent 032e98e commit 6e0e771
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 66 deletions.
57 changes: 57 additions & 0 deletions src/lime/tools/HashlinkHelper.hx
Original file line number Diff line number Diff line change
@@ -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"));
}
}
15 changes: 2 additions & 13 deletions tools/platforms/LinuxPlatform.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import lime.tools.HashlinkHelper;
import hxp.Haxelib;
import hxp.HXML;
import hxp.Path;
Expand Down Expand Up @@ -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")
{
Expand Down
29 changes: 16 additions & 13 deletions tools/platforms/MacPlatform.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import lime.tools.HashlinkHelper;
import hxp.Haxelib;
import hxp.HXML;
import hxp.Log;
Expand Down Expand Up @@ -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")
{
Expand Down
9 changes: 6 additions & 3 deletions tools/platforms/WindowsPlatform.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import lime.tools.HashlinkHelper;
import hxp.Haxelib;
import hxp.HXML;
import hxp.Log;
Expand Down Expand Up @@ -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))
{
Expand Down
82 changes: 45 additions & 37 deletions tools/utils/PlatformSetup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down

0 comments on commit 6e0e771

Please sign in to comment.