This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-nbpackage.git
The following commit(s) were added to refs/heads/master by this push:
new 7fc49b0 Provide arch option for macOS launcher, or attempt to parse
from runtime filename when present.
new 8e0f109 Merge pull request #32 from neilcsmith-net/macos-arch
7fc49b0 is described below
commit 7fc49b0531df8604e08b7e0eda04da6cf7fa914d
Author: Neil C Smith <[email protected]>
AuthorDate: Fri Jun 30 17:35:25 2023 +0100
Provide arch option for macOS launcher, or attempt to parse from runtime
filename when present.
---
.../netbeans/nbpackage/macos/AppBundleTask.java | 73 +++++++++++++++++-----
.../org/apache/netbeans/nbpackage/macos/MacOS.java | 8 +++
.../netbeans/nbpackage/macos/PkgPackager.java | 1 +
.../netbeans/nbpackage/macos/Messages.properties | 2 +
.../nbpackage/macos/Package.swift.template | 4 +-
5 files changed, 71 insertions(+), 17 deletions(-)
diff --git
a/src/main/java/org/apache/netbeans/nbpackage/macos/AppBundleTask.java
b/src/main/java/org/apache/netbeans/nbpackage/macos/AppBundleTask.java
index 560a5b6..ef79f6c 100644
--- a/src/main/java/org/apache/netbeans/nbpackage/macos/AppBundleTask.java
+++ b/src/main/java/org/apache/netbeans/nbpackage/macos/AppBundleTask.java
@@ -26,6 +26,7 @@ import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.netbeans.nbpackage.AbstractPackagerTask;
@@ -44,6 +45,9 @@ class AppBundleTask extends AbstractPackagerTask {
private static final String JAR_BIN_FILENAME = "jarBinaries";
private static final String ENTITLEMENTS_FILENAME = "sandbox.plist";
private static final String LAUNCHER_SRC_DIRNAME = "macos-launcher-src";
+ private static final String ARCH_X86_64 = "x86_64";
+ private static final String ARCH_ARM64 = "arm64";
+ private static final String ARCH_UNIVERSAL = "universal";
private String bundleName;
@@ -55,9 +59,9 @@ class AppBundleTask extends AbstractPackagerTask {
protected void checkPackageRequirements() throws Exception {
String[] cmds;
if (context().getValue(MacOS.CODESIGN_ID).isEmpty()) {
- cmds = new String[] {"swift"};
+ cmds = new String[]{"swift"};
} else {
- cmds = new String[] {"swift", "codesign"};
+ cmds = new String[]{"swift", "codesign"};
}
validateTools(cmds);
}
@@ -94,7 +98,8 @@ class AppBundleTask extends AbstractPackagerTask {
.findFirst()
.map(path -> path.getFileName().toString())
.orElseThrow();
- Path launcher = compileLauncher(image.resolve(LAUNCHER_SRC_DIRNAME));
+ String arch = findArch();
+ Path launcher = compileLauncher(image.resolve(LAUNCHER_SRC_DIRNAME),
arch);
Files.copy(launcher, bundle.resolve("Contents")
.resolve("MacOS").resolve(execName),
StandardCopyOption.COPY_ATTRIBUTES);
@@ -172,7 +177,7 @@ class AppBundleTask extends AbstractPackagerTask {
}
private Path findLauncher(Path binDir) throws IOException {
- try ( var files = Files.list(binDir)) {
+ try (var files = Files.list(binDir)) {
return files.filter(f ->
!f.getFileName().toString().endsWith(".exe"))
.findFirst().orElseThrow(IOException::new);
}
@@ -226,8 +231,8 @@ class AppBundleTask extends AbstractPackagerTask {
private void setupSigningConfiguration(Path image, Path bundle) throws
IOException {
Files.writeString(image.resolve(ENTITLEMENTS_FILENAME),
- MacOS.ENTITLEMENTS_TEMPLATE.load(context())
- , StandardOpenOption.CREATE_NEW);
+ MacOS.ENTITLEMENTS_TEMPLATE.load(context()),
+ StandardOpenOption.CREATE_NEW);
var nativeBinaries = FileUtils.find(bundle,
context().getValue(MacOS.SIGNING_FILES).orElseThrow());
Files.writeString(image.resolve(NATIVE_BIN_FILENAME),
@@ -246,17 +251,55 @@ class AppBundleTask extends AbstractPackagerTask {
StandardOpenOption.CREATE_NEW);
}
- private Path compileLauncher(Path launcherProject) throws IOException,
InterruptedException {
- var pb = new ProcessBuilder("swift", "build",
- "--configuration", "release",
- "--arch", "x86_64");
+ private Path compileLauncher(Path launcherProject, String arch) throws
IOException, InterruptedException {
+ final ProcessBuilder pb;
+ switch (arch) {
+ case ARCH_X86_64:
+ pb = new ProcessBuilder("swift", "build",
+ "--configuration", "release",
+ "--arch", "x86_64");
+ break;
+ case ARCH_ARM64:
+ pb = new ProcessBuilder("swift", "build",
+ "--configuration", "release",
+ "--arch", "arm64");
+ break;
+ default:
+ pb = new ProcessBuilder("swift", "build",
+ "--configuration", "release",
+ "--arch", "arm64",
+ "--arch", "x86_64");
+ }
pb.directory(launcherProject.toFile());
context().exec(pb);
- Path launcher = launcherProject.resolve(".build/release/AppLauncher");
- if (!Files.exists(launcher)) {
- throw new IOException(launcher.toString());
+ var output = FileUtils.find(launcherProject.resolve(".build"),
"**/{R,r}elease/AppLauncher");
+ if (output.isEmpty()) {
+ throw new IOException(launcherProject.toString());
+ }
+ return output.get(0);
+ }
+
+ private String findArch() {
+ var arch =
context().getValue(MacOS.ARCH).orElse("").toLowerCase(Locale.ROOT);
+ if (arch.isBlank()) {
+ var runtimeName = context().getValue(NBPackage.PACKAGE_RUNTIME)
+ .map(path ->
path.getFileName().toString().toLowerCase(Locale.ROOT))
+ .orElse("");
+ if (runtimeName.isBlank()) {
+ return ARCH_UNIVERSAL;
+ }
+ if (runtimeName.contains(ARCH_X86_64) ||
runtimeName.contains("x64")) {
+ return ARCH_X86_64;
+ }
+ if (runtimeName.contains(ARCH_ARM64) ||
runtimeName.contains("aarch64")) {
+ return ARCH_ARM64;
+ }
+ } else if (ARCH_ARM64.equals(arch) || ARCH_X86_64.equals(arch)
+ || ARCH_UNIVERSAL.equals(arch)) {
+ return arch;
}
- return launcher;
+
context().warningHandler().accept(MacOS.MESSAGES.getString("message.unknownarch"));
+ return ARCH_UNIVERSAL;
}
private void signBinariesInJARs(Path image, Path entitlements, String id)
@@ -282,7 +325,7 @@ class AppBundleTask extends AbstractPackagerTask {
}
private void signNativeBinaries(Path image, Path entitlements, String id)
- throws IOException {
+ throws IOException {
Path nativeFiles = image.resolve(NATIVE_BIN_FILENAME);
if (!Files.exists(nativeFiles)) {
return;
diff --git a/src/main/java/org/apache/netbeans/nbpackage/macos/MacOS.java
b/src/main/java/org/apache/netbeans/nbpackage/macos/MacOS.java
index 5adecee..285fdf2 100644
--- a/src/main/java/org/apache/netbeans/nbpackage/macos/MacOS.java
+++ b/src/main/java/org/apache/netbeans/nbpackage/macos/MacOS.java
@@ -61,6 +61,14 @@ class MacOS {
static final Template INFO_TEMPLATE
= Template.of(INFO_TEMPLATE_PATH, "Info.plist.template",
() ->
MacOS.class.getResourceAsStream("Info.plist.template"));
+ /**
+ * Target system architecture to use for building launcher, etc. Currently
+ * supported values are aarch64, x86_64 and universal. Default attempts to
+ * parse from runtime file, if present, or universal.
+ */
+ static final Option<String> ARCH
+ = Option.ofString("package.macos.arch",
+ MESSAGES.getString("option.arch.help"));
/**
* Optional launcher (main.swift) template path.
diff --git a/src/main/java/org/apache/netbeans/nbpackage/macos/PkgPackager.java
b/src/main/java/org/apache/netbeans/nbpackage/macos/PkgPackager.java
index 2fe4ae7..bd9c8bb 100644
--- a/src/main/java/org/apache/netbeans/nbpackage/macos/PkgPackager.java
+++ b/src/main/java/org/apache/netbeans/nbpackage/macos/PkgPackager.java
@@ -34,6 +34,7 @@ public class PkgPackager implements Packager {
MacOS.BUNDLE_ID,
MacOS.ICON_PATH,
MacOS.INFO_TEMPLATE_PATH,
+ MacOS.ARCH,
MacOS.LAUNCHER_TEMPLATE_PATH,
MacOS.ENTITLEMENTS_TEMPLATE_PATH,
MacOS.SIGNING_FILES,
diff --git
a/src/main/resources/org/apache/netbeans/nbpackage/macos/Messages.properties
b/src/main/resources/org/apache/netbeans/nbpackage/macos/Messages.properties
index f28f798..12c3a15 100644
--- a/src/main/resources/org/apache/netbeans/nbpackage/macos/Messages.properties
+++ b/src/main/resources/org/apache/netbeans/nbpackage/macos/Messages.properties
@@ -18,6 +18,7 @@
# Option file help comments
option.bundle_id.help=Value for CFBundleIdentifier.
option.icon.help=Path to icon file (*.icns). Defaults to Apache NetBeans logo.
+option.arch.help=Optional target system architecture (arm64, x86_64 or
universal). Defaults to parsing runtime or universal.
option.info_template.help=Optional path to Info.plist template.
option.launcher_template.help=Optional path to launcher (main.swift) template.
option.entitlements_template.help=Optional path to codesign entitlements
template.
@@ -31,3 +32,4 @@ message.validatingtools=Validating required tools - {0}
message.missingtool=Cannot find required tool - {0}
message.nocodesignid=No codesign ID has been configured. App bundle will be
unsigned.
message.nopkgbuildid=No pkgbuild ID has been configured. Installer will be
unsigned.
+message.unknownarch=Architecture is not recognised, defaulting to universal.
diff --git
a/src/main/resources/org/apache/netbeans/nbpackage/macos/Package.swift.template
b/src/main/resources/org/apache/netbeans/nbpackage/macos/Package.swift.template
index 0e9b7f1..8e92253 100644
---
a/src/main/resources/org/apache/netbeans/nbpackage/macos/Package.swift.template
+++
b/src/main/resources/org/apache/netbeans/nbpackage/macos/Package.swift.template
@@ -1,4 +1,4 @@
-// swift-tools-version:5.1
+// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to
build this package.
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -24,7 +24,7 @@ import PackageDescription
let package = Package(
name: "AppLauncher",
platforms: [
- .macOS(.v10_13)
+ .macOS(.v11)
],
dependencies: [],
targets: [
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists