Skip to content

Commit 01c3616

Browse files
steve-sansalond
authored andcommitted
[GR-62456] Backport to 24.2: GraalPy Maven plugin incorrectly prints warning about default resources directory.
PullRequest: graalpython/3698
2 parents 3004cf3 + 3b46423 commit 01c3616

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def check_gradle_generated_app(self, community):
133133
cmd = gradlew_cmd + ["build"]
134134
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir, logger=log)
135135
util.check_ouput("BUILD SUCCESS", out, logger=log)
136+
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, logger=log)
137+
util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem", out, logger=log)
136138
self.check_filelist(target_dir, log)
137139

138140
cmd = gradlew_cmd + ["nativeCompile"]
@@ -413,7 +415,7 @@ def check_gradle_python_resources_dir_and_external_dir_error(self):
413415
gradle_cmd = util.get_gradle_wrapper(target_dir, self.env)
414416
cmd = gradle_cmd + ["graalPyResources"]
415417
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
416-
util.check_ouput("Cannot set both 'externalDirectory' and 'resourcesDirectory' at the same time", out)
418+
util.check_ouput("Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time", out)
417419
assert return_code != 0, out
418420

419421

@@ -478,6 +480,8 @@ def check_gradle_namespaced_vfs(self):
478480

479481
app1_gradle_cmd = util.get_gradle_wrapper(app1_dir, self.env)
480482
out, return_code = util.run_cmd(app1_gradle_cmd + ['publishToMavenLocal'], self.env, cwd=app1_dir)
483+
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=False)
484+
util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem", out, contains=False)
481485
assert return_code == 0, out
482486

483487
app2_gradle_cmd = util.get_gradle_wrapper(app2_dir, self.env)

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def check_generated_app(self, use_default_vfs_path, use_utils_pkg=False):
115115
cmd = mvnw_cmd + ["package", "-Pnative", "-DmainClass=it.pkg.GraalPy"]
116116
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
117117
util.check_ouput("BUILD SUCCESS", out)
118+
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=use_default_vfs_path)
119+
util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem.", out, contains=use_default_vfs_path)
118120

119121
# check fileslist.txt
120122
fl_path = os.path.join(target_dir, "target", "classes", vfs_prefix, "fileslist.txt")

graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void execute() throws MojoExecutionException {
145145
}
146146

147147
if (resourceDirectory == null) {
148-
if (externalDirectory != null) {
148+
if (externalDirectory == null) {
149149
getLog().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
150150
"This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
151151
"Consider adding <resourceDirectory>GRAALPY-VFS/${project.groupId}/${project.artifactId}</resourceDirectory> to your pom.xml, " +
@@ -162,7 +162,7 @@ public void execute() throws MojoExecutionException {
162162
getLog().warn("The GraalPy plugin <pythonHome> configuration setting was deprecated and has no effect anymore.\n" +
163163
"For execution in jvm mode, the python language home is always available.\n" +
164164
"When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
165-
"For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources documentation.");
165+
"For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
166166
}
167167

168168
manageVenv();

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ private GraalPyResources() {
198198
* location</li>
199199
* <li><code>/org.graalvm.python.vfs/src</code> - is set as the python sources location</li>
200200
* </ul>
201-
* </p>
201+
* <p>
202+
* When the virtual filesystem is located in other than the default resource directory,
203+
* {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
204+
* use {@link #contextBuilder(VirtualFileSystem)} and
205+
* {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
206+
* {@link VirtualFileSystem}.
202207
*
203208
* @return a new {@link Context} instance
204209
* @since 24.2.0
@@ -233,6 +238,12 @@ public static Context createContext() {
233238
* }
234239
* }
235240
* </pre>
241+
* <p>
242+
* When the virtual filesystem is located in other than the default resource directory,
243+
* {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
244+
* use {@link #contextBuilder(VirtualFileSystem)} and
245+
* {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
246+
* {@link VirtualFileSystem}.
236247
*
237248
* @see <a href=
238249
* "https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java">PythonOptions</a>
@@ -308,13 +319,14 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
308319

309320
/**
310321
* Creates a GraalPy context preconfigured with GraalPy and polyglot Context configuration
311-
* options for use with resources located in a real filesystem.
322+
* options for use with resources located in an external directory in real filesystem.
312323
* <p>
313324
* Following resource paths are preconfigured:
314325
* <ul>
315-
* <li><code>${resourcesDirectory}/venv</code> - is set as the python virtual environment
326+
* <li><code>${externalResourcesDirectory}/venv</code> - is set as the python virtual
327+
* environment location</li>
328+
* <li><code>${externalResourcesDirectory}/src</code> - is set as the python sources
316329
* location</li>
317-
* <li><code>${resourcesDirectory}/src</code> - is set as the python sources location</li>
318330
* </ul>
319331
* </p>
320332
* <p>
@@ -343,19 +355,20 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
343355
* </ul>
344356
* </p>
345357
*
346-
* @param resourcesDirectory the root directory with GraalPy specific embedding resources
358+
* @param externalResourcesDirectory the root directory with GraalPy specific embedding
359+
* resources
347360
* @return a new {@link org.graalvm.polyglot.Context.Builder} instance
348361
* @since 24.2.0
349362
*/
350-
public static Context.Builder contextBuilder(Path resourcesDirectory) {
363+
public static Context.Builder contextBuilder(Path externalResourcesDirectory) {
351364
String execPath;
352365
if (VirtualFileSystemImpl.isWindows()) {
353-
execPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("Scripts").resolve("python.exe").toAbsolutePath().toString();
366+
execPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("Scripts").resolve("python.exe").toAbsolutePath().toString();
354367
} else {
355-
execPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("bin").resolve("python").toAbsolutePath().toString();
368+
execPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_VENV).resolve("bin").resolve("python").toAbsolutePath().toString();
356369
}
357370

358-
String srcPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
371+
String srcPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
359372
return createContextBuilder().
360373
// allow all IO access
361374
allowIO(IOAccess.ALL).
@@ -437,8 +450,9 @@ public static Path getNativeExecutablePath() {
437450
* The structure of the created resource directory will stay the same like the embedded Python
438451
* resources structure:
439452
* <ul>
440-
* <li><code>${resourcesDirectory}/venv</code> - the python virtual environment location</li>
441-
* <li><code>${resourcesDirectory}/src</code> - the python sources location</li>
453+
* <li><code>${externalResourcesDirectory}/venv</code> - the python virtual environment
454+
* location</li>
455+
* <li><code>${externalResourcesDirectory}/src</code> - the python sources location</li>
442456
* </ul>
443457
* </p>
444458
* </p>
@@ -456,17 +470,17 @@ public static Path getNativeExecutablePath() {
456470
* </p>
457471
*
458472
* @param vfs the {@link VirtualFileSystem} from which resources are to be extracted
459-
* @param resourcesDirectory the target directory to extract the resources to
473+
* @param externalResourcesDirectory the target directory to extract the resources to
460474
* @throws IOException if resources isn't a directory
461475
* @see #contextBuilder(Path)
462476
* @see VirtualFileSystem.Builder#resourceLoadingClass(Class)
463477
*
464478
* @since 24.2.0
465479
*/
466-
public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path resourcesDirectory) throws IOException {
467-
if (Files.exists(resourcesDirectory) && !Files.isDirectory(resourcesDirectory)) {
468-
throw new IOException(String.format("%s has to be a directory", resourcesDirectory.toString()));
480+
public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path externalResourcesDirectory) throws IOException {
481+
if (Files.exists(externalResourcesDirectory) && !Files.isDirectory(externalResourcesDirectory)) {
482+
throw new IOException(String.format("%s has to be a directory", externalResourcesDirectory.toString()));
469483
}
470-
vfs.impl.extractResources(resourcesDirectory);
484+
vfs.impl.extractResources(externalResourcesDirectory);
471485
}
472486
}

graalpython/org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public void apply(Project project) {
117117

118118
if (extension.getPythonResourcesDirectory().isPresent() && extension.getExternalDirectory().isPresent()) {
119119
throw new GradleException(
120-
"Cannot set both 'externalDirectory' and 'resourcesDirectory' at the same time. " +
120+
"Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time. " +
121121
"New property 'externalDirectory' is a replacement for deprecated 'pythonResourcesDirectory'. " +
122122
"If you want to deploy the virtual environment into physical filesystem, use 'externalDirectory'. " +
123123
"The deployment of the external directory alongside the application is not handled by the GraalPy Maven plugin in such case." +
124-
"If you wish to bundle the virtual filesystem in Java resources, use 'resourcesDirectory'. " +
124+
"If you wish to bundle the virtual filesystem in Java resources, use 'resourceDirectory'. " +
125125
"For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ");
126126
}
127127

@@ -132,9 +132,9 @@ public void apply(Project project) {
132132
// Run the vfsFilesListTask conditionally only if 'externalDirectory' is not set
133133
if (!extension.getPythonResourcesDirectory().isPresent() && !extension.getExternalDirectory().isPresent()) {
134134
if (!extension.getResourceDirectory().isPresent()) {
135-
proj.getLogger().info(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
135+
proj.getLogger().warn(String.format("Virtual filesystem is deployed to default resources directory '%s'. " +
136136
"This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem. " +
137-
"Consider adding `resourcesDirectory = \"GRAALPY-VFS/${groupId}/${artifactId}\"` to your build.gradle script " +
137+
"Consider adding `resourceDirectory = \"GRAALPY-VFS/${groupId}/${artifactId}\"` to your build.gradle script " +
138138
"(replace the placeholders with values specific to your project), " +
139139
"moving any existing sources from '%s' to '%s', and using VirtualFileSystem$Builder#resourceDirectory." +
140140
"For more details, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools. ",
@@ -192,7 +192,7 @@ private TaskProvider<ResourcesTask> registerResourcesTask(Project project, Confi
192192
t.getLogger().warn("The GraalPy plugin pythonHome configuration setting was deprecated and has no effect anymore.\n" +
193193
"For execution in jvm mode, the python language home is always available.\n" +
194194
"When building a native executable using GraalVM Native Image, then the full python language home is by default embedded into the native executable.\n" +
195-
"For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources documentation.");
195+
"For more details, please refer to the documentation of GraalVM Native Image options IncludeLanguageResources and CopyLanguageResources.");
196196
}
197197
t.getPackages().set(extension.getPackages());
198198

0 commit comments

Comments
 (0)