Skip to content

Commit 9324f40

Browse files
authored
Fix compile task out of date when runtime args change (#372)
* Fix compile task out of date when runtime args change The `NativeImageOptions` domain object is used in the DSL to configure both compile and runtime arguments for native images: the compile options are used to invoke `native-image` and build a binary, while the runtime args are used to pass extra arguments when executing the native image. The full `NativeImageOptions` domain object was passed to the native image compilation task as a `@Nested` input, which meant in practice that if the _runtime_ arguments changed, then we would rebuild the image although it isn't necessary. This commit fixes the problem in a binary compatible way, by introducing a couple of interfaces: one for the compile options, the other for the runtime options. It makes the "options" internal on the compile task, and uses a delegated view of compile options for input snapshotting. Fixes #371 * Remove pre-Gradle 7 tests With the removal of the Java 11 variant of GraalVM, we're not in capacity of testing this on pre-Gradle 7 since the spec won't let us specify that we need a GraalVM vendor.
1 parent 4f8e4dc commit 9324f40

File tree

8 files changed

+479
-187
lines changed

8 files changed

+479
-187
lines changed

.github/workflows/test-native-gradle-plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
gradle-version: ["current", "6.7.1"]
56+
gradle-version: ["current", "7.1"]
5757
# Following versions are disabled temporarily in order to speed up PR testing
5858
# "7.3.3", "7.2", "7.1", "6.8.3"
5959
graalvm-version: [ latest ] # dev

build-logic/gradle-functional-testing/src/main/groovy/org.graalvm.build.functional-testing.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def graalVm = javaToolchains.launcherFor {
8282
def fullFunctionalTest = tasks.register("fullFunctionalTest")
8383

8484
['functionalTest', 'configCacheFunctionalTest'].each { baseName ->
85-
["current", "7.3.3", "7.2", "7.1", "6.8.3", "6.7.1"].each { gradleVersion ->
85+
["current", "7.3.3", "7.2", "7.1"].each { gradleVersion ->
8686
String taskName = gradleVersion == 'current' ? baseName : "gradle${gradleVersion}${baseName.capitalize()}"
8787
// Add a task to run the functional tests
8888
def testTask = tasks.register(taskName, Test) {
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.buildtools.gradle.dsl;
42+
43+
import org.graalvm.buildtools.gradle.dsl.agent.DeprecatedAgentOptions;
44+
import org.gradle.api.file.ConfigurableFileCollection;
45+
import org.gradle.api.provider.ListProperty;
46+
import org.gradle.api.provider.MapProperty;
47+
import org.gradle.api.provider.Property;
48+
import org.gradle.api.tasks.Classpath;
49+
import org.gradle.api.tasks.Input;
50+
import org.gradle.api.tasks.InputFiles;
51+
import org.gradle.api.tasks.Nested;
52+
import org.gradle.api.tasks.Optional;
53+
import org.gradle.jvm.toolchain.JavaLauncher;
54+
55+
import java.util.List;
56+
57+
/**
58+
* Configuration options for compiling a native binary.
59+
*/
60+
public interface NativeImageCompileOptions {
61+
/**
62+
* Returns the fully qualified name of the Main class to be executed.
63+
* <p>
64+
* This does not need to be set if using an <a href="https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html">Executable Jar</a> with a {@code Main-Class} attribute.
65+
* </p>
66+
*
67+
* @return mainClass The main class.
68+
*/
69+
@Input
70+
@Optional
71+
Property<String> getMainClass();
72+
73+
/**
74+
* Returns the arguments for the native-image invocation.
75+
*
76+
* @return Arguments for the native-image invocation.
77+
*/
78+
@Input
79+
ListProperty<String> getBuildArgs();
80+
81+
/**
82+
* Returns the system properties which will be used by the native-image builder process.
83+
*
84+
* @return The system properties. Returns an empty map when there are no system properties.
85+
*/
86+
@Input
87+
MapProperty<String, Object> getSystemProperties();
88+
89+
/**
90+
* Returns the environment variables which will be used by the native-image builder process.
91+
* @return the environment variables. Returns an empty map when there are no environment variables.
92+
*
93+
* @since 0.9.14
94+
*/
95+
@Input
96+
MapProperty<String, Object> getEnvironmentVariables();
97+
98+
/**
99+
* Returns the classpath for the native-image building.
100+
*
101+
* @return classpath The classpath for the native-image building.
102+
*/
103+
@InputFiles
104+
@Classpath
105+
ConfigurableFileCollection getClasspath();
106+
107+
/**
108+
* Returns the extra arguments to use when launching the JVM for the native-image building process.
109+
* Does not include system properties and the minimum/maximum heap size.
110+
*
111+
* @return The arguments. Returns an empty list if there are no arguments.
112+
*/
113+
@Input
114+
ListProperty<String> getJvmArgs();
115+
116+
/**
117+
* Gets the value which toggles native-image debug symbol output.
118+
*
119+
* @return Is debug enabled
120+
*/
121+
@Input
122+
Property<Boolean> getDebug();
123+
124+
/**
125+
* @return Whether to enable fallbacks (defaults to false).
126+
*/
127+
@Input
128+
Property<Boolean> getFallback();
129+
130+
/**
131+
* Gets the value which toggles native-image verbose output.
132+
*
133+
* @return Is verbose output
134+
*/
135+
@Input
136+
Property<Boolean> getVerbose();
137+
138+
/**
139+
* Gets the value which determines if shared library is being built.
140+
*
141+
* @return The value which determines if shared library is being built.
142+
*/
143+
@Input
144+
Property<Boolean> getSharedLibrary();
145+
146+
/**
147+
* Gets the value which determines if image is being built in quick build mode.
148+
*
149+
* @return The value which determines if image is being built in quick build mode.
150+
*/
151+
@Input
152+
Property<Boolean> getQuickBuild();
153+
154+
/**
155+
* Gets the value which determines if image is being built with rich output.
156+
*
157+
* @return The value which determines if image is being built with rich output.
158+
*/
159+
@Input
160+
Property<Boolean> getRichOutput();
161+
162+
/**
163+
* Returns the MapProperty that contains information about configuration that should be excluded
164+
* during image building. It consists of a dependency coordinates and a list of
165+
* regular expressions that match resources that should be excluded as a value.
166+
*
167+
* @return a map of filters for configuration exclusion
168+
*/
169+
@Input
170+
MapProperty<Object, List<String>> getExcludeConfig();
171+
172+
@Nested
173+
NativeResourcesOptions getResources();
174+
175+
/**
176+
* Returns the list of configuration file directories (e.g. resource-config.json, ...) which need
177+
* to be passed to native-image.
178+
*
179+
* @return a collection of directories
180+
*/
181+
@InputFiles
182+
ConfigurableFileCollection getConfigurationFileDirectories();
183+
184+
@Input
185+
ListProperty<String> getExcludeConfigArgs();
186+
187+
/**
188+
* Gets the name of the native executable to be generated.
189+
*
190+
* @return The image name property.
191+
*/
192+
@Input
193+
Property<String> getImageName();
194+
195+
/**
196+
* Returns the toolchain used to invoke native-image. Currently pointing
197+
* to a Java launcher due to Gradle limitations.
198+
*
199+
* @return the detected java launcher
200+
*/
201+
@Nested
202+
@Optional
203+
Property<JavaLauncher> getJavaLauncher();
204+
205+
/**
206+
* If set to true, this will build a fat jar of the image classpath
207+
* instead of passing each jar individually to the classpath. This
208+
* option can be used in case the classpath is too long and that
209+
* invoking native image fails, which can happen on Windows.
210+
*
211+
* @return true if a fatjar should be used. Defaults to true for Windows, and false otherwise.
212+
*/
213+
@Input
214+
Property<Boolean> getUseFatJar();
215+
216+
@Nested
217+
DeprecatedAgentOptions getAgent();
218+
}

0 commit comments

Comments
 (0)