scalameta / sbt-native-image

Plugin to generate native-image binaries with sbt
251 stars 22 forks source link

nativeImageRunAgent doesn't appear to properly parse arguments #22

Open hongee opened 3 years ago

hongee commented 3 years ago

Describe the bug

Running nativeImageRunAgent with a single argument results in an Invalid Input exception being thrown (for sbt 1.4.7)

sbt> nativeImageRunAgent foo
[error] stack trace is suppressed; run last nativeImageRunAgent for the full output
[error] (nativeImageRunAgent) Invalid programmatic input:
[error] Expected whitespace character
[error] foo
[error] ^

sbt> last nativeImageRunAgent
[error] java.lang.RuntimeException: Invalid programmatic input:
[error] Expected whitespace character
[error] foo
[error] ^
[error]         at scala.sys.package$.error(package.scala:30)
[error]         at sbt.Extracted.runInputTask(Extracted.scala:84)
[error]         at sbtnativeimage.NativeImagePlugin$.$anonfun$projectSettings$31(NativeImagePlugin.scala:213)
[error]         at sbtnativeimage.NativeImagePlugin$.$anonfun$projectSettings$31$adapted(NativeImagePlugin.scala:198)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]         at java.base/java.lang.Thread.run(Thread.java:834)
[error] (nativeImageRunAgent) Invalid programmatic input:
[error] Expected whitespace character
[error] foo
[error] ^

Doing nativeImageRunAgent " foo" works as a workaround. Not super familiar with scala parser combinators, but perhaps there's some regression with spaceDelimited - https://github.com/scalameta/sbt-native-image/blob/master/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala#L211. Happy to help look into this too!

In addition, while nativeImageRunAgent creates the configuration files (and maybe I'm doing something wrong) but it doesn't look like it automatically gets picked by the nativeImage build command. The GraalVM docs only mentions:

The generated configuration files can be supplied to the native-image tool by placing them in a META-INF/native-image/ directory on the class path, for example, in a JAR file used in the image build. This directory (or any of its subdirectories) is searched for files with the names jni-config.json, reflect-config.json, proxy-config.json and resource-config.json, which are then automatically included in the build. Not all of those files must be present. When multiple files with the same name are found, all of them are included.

and I'm not sure if it'll also pick up stuff in the target/native-image-configs folder by default. What I ended up doing was to pass that into nativeImageOptions (e.g. s"-H:ResourceConfigurationFiles=${target.value.absolutePath}/native-image-configs/resource-config.json",), but this seems like something the plugin can do.

Btw thank you so much for the amazing work on this plugin! Was so fiddly to get GraalVM & native-image configured and set up, and this plugin basically replaced all of that, and did everything seamlessly on my first attempt! 🔥

To Reproduce Steps to reproduce the behavior:

  1. Run command 'nativeImageRunAgent foo'

Expected behavior

Pass the arguments, without needing to wrap the arguments in a string prefixed with a space

Installation:

olafurpg commented 3 years ago

Thank you for reporting! It's good to know there is a workaround. cc/ @fehu is this something you could take a look at?

fehu commented 3 years ago

Sorry for the delay. I'll try to look into the problem next weak.