From 342cedbcfa759cc48efc67dd3367b94d6777d4c3 Mon Sep 17 00:00:00 2001 From: Lee Read Date: Sat, 13 May 2023 17:22:18 -0400 Subject: [PATCH] Support babashka.process reload for exec fn (#1558) * Support babashka.process reload for exec fn Exposed GraalVM `ProcessProperties/exec` signature used by babashka.process/exec. Add new `graal?` feature (on by default) to allow folks to build/use babashka without this specific Graal API. On my linux dev box bb executable increased by 8kb. Closes #1557 * Respond to PR review feedback 1. Allow all Graal ProcessProperties/exec signatures 2. Instead of a feature flag, simply check if Graal ProcessProperties class is available before including ProcessProperties/exec. I did not see the value of adding a has-graal-process-properties fn, so left that part out. Lemme know if you want/need that. * Respond to PR review feedback Because resolves can bloat GraalVM native-image size, we like to keep the together and obvious instead of buried and non-obvious. --- CHANGELOG.md | 1 + src/babashka/impl/classes.clj | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12a4feed..b473068a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ in the CfP! ## Unreleased - [#1524](https://github.com/babashka/babashka/issues/1524): Remove dynamic builds for linux-aarch64 ([@lispyclouds](https://github.com/lispyclouds)) +- [#1577](https://github.com/babashka/babashka/issues/1557): Add support for `babashka.process/exec` after namespace reload of `babashka.process` ([@lread](https://github.com/lread)) ## 1.3.179 (2023-04-26) diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index 81d11dfb..a951f4eb 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -15,6 +15,9 @@ (def has-domain-sockets? (resolve 'java.net.UnixDomainSocketAddress)) +(def has-graal-process-properties? + (resolve 'org.graalvm.nativeimage.ProcessProperties)) + (def base-custom-map `{clojure.lang.LineNumberingPushbackReader {:allPublicConstructors true :allPublicMethods true} @@ -182,7 +185,11 @@ `java.util.ResourceBundle {:methods [{:name "getBundle" :parameterTypes ["java.lang.String","java.util.Locale", - "java.lang.ClassLoader"]}]}))) + "java.lang.ClassLoader"]}]}) + + has-graal-process-properties? + (assoc `org.graalvm.nativeimage.ProcessProperties + {:methods [{:name "exec"}]}))) (def java-net-http-classes "These classes must be initialized at run time since GraalVM 22.1"