Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process custom image classpath after parsing options #3749

Closed

Conversation

galderz
Copy link
Contributor

@galderz galderz commented Sep 1, 2021

Closes #3742

  • Custom image classpath processing can be impacted by exclude-config.
  • Moved the code out of -jar parsing, to avoid the need for specific parameter order.
  • Without this change, --exclude-config needs to be passed before -jar for it to have an effect.
  • Added some verbose messages for easier debugging of native-image binary.

@galderz galderz force-pushed the t_excludeconfig_jar_order_3742 branch 2 times, most recently from 682856d to d026897 Compare September 2, 2021 09:02
* Custom image classpath processing can be impacted by exclude-config.
* Moved the code out of -jar parsing,
to avoid the need for specific parameter order.
* Without this change,
--exclude-config needs to be passed before -jar
for it to have an effect.
* Added verbose messages for easier debugging of native-image binary.
@galderz galderz force-pushed the t_excludeconfig_jar_order_3742 branch from d026897 to ac0f115 Compare September 2, 2021 10:47
@galderz
Copy link
Contributor Author

galderz commented Sep 2, 2021

The CI failure seems unrelated.

@munishchouhan
Copy link
Contributor

@galderz thanks for your contribution, I have assigned a reviewer to this PR

@olpaw
Copy link
Member

olpaw commented Sep 6, 2021

Hi @galderz ,

the fact that --exclude-config needs to be passed before -jar is not a bug. It's well documented behaviour:

The arguments passed to native-image are evaluated left-to-right. This also
extends to arguments that get passed indirectly via META-INF/native-image
based native image configuration. Suppose you have a JAR file that contains
native-image.properties with Args = -H:Optimize=0. Then by using the
-H:Optimize=2 option after -cp <jar-file> you can override the setting that
comes from the JAR file.

We cannot modify the behaviour for -jar since this would lead to surprising behaviour that conflicts with our left-to-right evaluation policy. Suppose you use -jar foo.jar with a foo.jar that has a META-INF/native-image/native-image.properties embedded that contains

Args = -O0 -H:Name=customImageName

Due to our left-to-right evaluation users are able to override the args coming from that native-image.properties file.
Using native-image -jar foo.jar -O1 -H:Name=lastArgumentWinsImageName works as expected.

Your change would break that behaviour.

Copy link
Member

@olpaw olpaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@munishchouhan
Copy link
Contributor

Closing this PR, If still there is any change is required, please raise a new PR

@galderz
Copy link
Contributor Author

galderz commented Sep 13, 2021

@olpaw Thanks for the clarification. Are there any tests that verify the behaviour you mention?

@olpaw
Copy link
Member

olpaw commented Sep 13, 2021

There are no explicit test of this. But our whole way of building images (especially with mx) relies on that.

If you run e.g. mx --extra-image-builder-argument=--verbose --env ce-complete build |& build.log you can observe many instances of build options being overruled by subsequent options (based on the behaviour described in https://www.graalvm.org/reference-manual/native-image/BuildConfiguration/#order-of-arguments-evaluation). Even the fact that --extra-image-builder-argument is useful at all relies on this behaviour.

Also the native-image.properties used around building truffle images relies heavily on this. I.e. overriding the default -Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime with -Dtruffle.TruffleRuntime=com.oracle.svm.truffle.api.SubstrateTruffleRuntime in lib/svm/macros/truffle/native-image.properties but being able to override that again on command line with placing -Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime (after the truffle options) for building interpreter-only images.

@sdeleuze
Copy link
Collaborator

sdeleuze commented Jan 6, 2022

@olpaw On Spring side, we need to use --exclude-config configured via native-image.properties in the classpath. Due to the ordering behavior, it seems it is not possible. Could you confirm?

If confirmed, I understand we can't change the global behavior of "ordering matters", but could we at least work on a fix for this specific issue to allow --exclude-config after -cp or -jar ?

Happy to create a dedicated issue if that makes sense.

cc @gradinac

@olpaw
Copy link
Member

olpaw commented Jan 10, 2022

@olpaw On Spring side, we need to use --exclude-config configured via native-image.properties in the classpath. Due to the ordering behavior, it seems it is not possible. Could you confirm?

@sdeleuze, how about creating a subdir that contains native-image.properties and is put on the classpath as the first entry. I.e.

mkdir -p config-only-cp-entry/META-INF/native-image`
echo '--exclude-config ....' >  config-only-cp-entry/META-INF/native-image/native-image.properties

then use

-cp config-only-cp-entry:<other-classpath-entries ...>

Since config-only-cp-entry is the first classpath entry it's native-image.properties will be processed before all others.

@olpaw
Copy link
Member

olpaw commented Jan 10, 2022

-cp config-only-cp-entry:<other-classpath-entries ...>

Possible also good to know that native-image (other than java) allows you to use -cp and -jar in the same command line invocation (or multiple -cp args in the same invocation). Because of that you could also use:

-cp config-only-cp-entry -cp <other-classpath-entries ...>

@olpaw
Copy link
Member

olpaw commented Jun 2, 2022

@sdeleuze did the approach I suggested in #3749 (comment) work for you?

@olpaw
Copy link
Member

olpaw commented Jun 2, 2022

@galderz we could make --exclude-config order independent if we disallow the option to be used anywhere else than command line (i.e. embedding --exclude-config in native-image.properties in META-INF/native-image would be prohibited).

Would this limitation be ok with you? cc @sdeleuze

@galderz
Copy link
Contributor Author

galderz commented Jun 6, 2022

@olpaw It's been a while since I worked on this, but the change here was no longer necessary once we understood the reason for the limitations. IIRC ordering parameters the expected way was enough.

@sdeleuze
Copy link
Collaborator

@olpaw I think for now the plan is to workaround that at Native Build Tools level, see graalvm/native-build-tools#185.

@olpaw
Copy link
Member

olpaw commented Jun 13, 2022

@sdeleuze FYI I fixed this on master last week (so it will be in 22.2). Now if you use --exclude-config ... on the native-image command line, it will affect all classpath & module-path entries used on the same command line independent from having specified --exclude-config ... before or after -cp/p arguments. See 006c61d

@sdeleuze
Copy link
Collaborator

@olpaw Awesome thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--exclude-config not working when provided after -jar
5 participants