From 012e31c5694fe6c0c7007b4e989732f583b3348d Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 2 Oct 2024 12:44:22 +0800 Subject: [PATCH 1/5] Add support for signing binaries Signed-off-by: Jade Turner --- .../wpi/first/nativeutils/WPINativeUtils.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java index 6b03879..0d03fab 100644 --- a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java +++ b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java @@ -2,6 +2,8 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.nativeplatform.tasks.AbstractLinkTask; +import org.gradle.nativeplatform.tasks.LinkExecutable; public class WPINativeUtils implements Plugin { @Override @@ -13,5 +15,21 @@ public void apply(Project project) { nativeExt.addWpiExtension(); project.getPluginManager().apply(RpathRules.class); - } + + if (project.hasProperty("developerID")) { + project.getTasks().withType(AbstractLinkTask.class).forEach((task) -> { + // Don't sign any executables because codesign complains + // about relative rpath. + if (!(task instanceof LinkExecutable)) { + // Get path to binary. + String path = task.getLinkedFile().getAsFile().get().getAbsolutePath(); + ProcessBuilder builder = new ProcessBuilder(); + var codesigncommand = String.format("codesign --force --strict --timestamp --options=runtime " + + "--version -s %s %s", project.findProperty("developerID"), path); + builder.command("sh", "-c", codesigncommand); + builder.directory(project.getRootDir()); + } + }); + } + } } From 06da326c12d768ae2ffcfc4ef0f18bf3dbda048c Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 2 Oct 2024 13:20:19 +0800 Subject: [PATCH 2/5] only enable on mac Signed-off-by: Jade Turner --- .../wpi/first/nativeutils/WPINativeUtils.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java index 0d03fab..1281396 100644 --- a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java +++ b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java @@ -16,20 +16,22 @@ public void apply(Project project) { project.getPluginManager().apply(RpathRules.class); - if (project.hasProperty("developerID")) { - project.getTasks().withType(AbstractLinkTask.class).forEach((task) -> { - // Don't sign any executables because codesign complains - // about relative rpath. - if (!(task instanceof LinkExecutable)) { - // Get path to binary. - String path = task.getLinkedFile().getAsFile().get().getAbsolutePath(); - ProcessBuilder builder = new ProcessBuilder(); - var codesigncommand = String.format("codesign --force --strict --timestamp --options=runtime " - + "--version -s %s %s", project.findProperty("developerID"), path); - builder.command("sh", "-c", codesigncommand); - builder.directory(project.getRootDir()); - } - }); + if (System.getProperty("os.name").startsWith("Mac")) { + if (project.hasProperty("developerID")) { + project.getTasks().withType(AbstractLinkTask.class).forEach((task) -> { + // Don't sign any executables because codesign complains + // about relative rpath. + if (!(task instanceof LinkExecutable)) { + // Get path to binary. + String path = task.getLinkedFile().getAsFile().get().getAbsolutePath(); + ProcessBuilder builder = new ProcessBuilder(); + var codesigncommand = String.format("codesign --force --strict --timestamp --options=runtime " + + "--version -s %s %s", project.findProperty("developerID"), path); + builder.command("sh", "-c", codesigncommand); + builder.directory(project.getRootDir()); + } + }); + } } } } From 6c9885fd43c22c7362036abca0e951b9c6bc52b5 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 2 Oct 2024 13:28:34 +0800 Subject: [PATCH 3/5] option magic Signed-off-by: Jade Turner --- .../wpi/first/nativeutils/WPINativeUtils.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java index 1281396..b5e01cd 100644 --- a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java +++ b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java @@ -2,10 +2,22 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.tasks.options.Option; import org.gradle.nativeplatform.tasks.AbstractLinkTask; import org.gradle.nativeplatform.tasks.LinkExecutable; public class WPINativeUtils implements Plugin { + private String developerID = null; + + @Option(option = "sign", description = "Sign with developer ID (MacOS only)") + public void sign(String developerID) { + if (!System.getProperty("os.name").startsWith("Mac")) { + throw new RuntimeException("Can't sign binaries on non mac platforms"); + } + + this.developerID = developerID; + } + @Override public void apply(Project project) { project.getPluginManager().apply(NativeUtils.class); @@ -17,7 +29,7 @@ public void apply(Project project) { project.getPluginManager().apply(RpathRules.class); if (System.getProperty("os.name").startsWith("Mac")) { - if (project.hasProperty("developerID")) { + if (developerID != null) { project.getTasks().withType(AbstractLinkTask.class).forEach((task) -> { // Don't sign any executables because codesign complains // about relative rpath. @@ -26,7 +38,7 @@ public void apply(Project project) { String path = task.getLinkedFile().getAsFile().get().getAbsolutePath(); ProcessBuilder builder = new ProcessBuilder(); var codesigncommand = String.format("codesign --force --strict --timestamp --options=runtime " - + "--version -s %s %s", project.findProperty("developerID"), path); + + "--version -s %s %s", developerID, path); builder.command("sh", "-c", codesigncommand); builder.directory(project.getRootDir()); } From 2c2de9cb149e0bd339d69a9ac0c4093455afe95d Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Wed, 2 Oct 2024 15:12:01 +0800 Subject: [PATCH 4/5] actually start Signed-off-by: Jade Turner --- .../java/edu/wpi/first/nativeutils/WPINativeUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java index b5e01cd..a3d5dea 100644 --- a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java +++ b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java @@ -1,5 +1,7 @@ package edu.wpi.first.nativeutils; +import java.io.IOException; + import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.tasks.options.Option; @@ -41,6 +43,12 @@ public void apply(Project project) { + "--version -s %s %s", developerID, path); builder.command("sh", "-c", codesigncommand); builder.directory(project.getRootDir()); + + try { + builder.start(); + } catch (IOException e) { + throw new RuntimeException(e); + } } }); } From 204a01e9db26f38c0df58a733ed432ece2a83628 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Fri, 8 Nov 2024 14:15:15 +0800 Subject: [PATCH 5/5] bump version Signed-off-by: Jade Turner --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4d0ab0b..d154101 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ java { allprojects { group = "edu.wpi.first" - version = "2025.5.0" + version = "2025.6.0" if (project.hasProperty('publishVersion')) { version = project.publishVersion