Skip to content

Commit

Permalink
[GR-27583] Make native-image-maven-plugin call native-image executabl…
Browse files Browse the repository at this point in the history
…e directly.

PullRequest: graal/7671
  • Loading branch information
olpaw committed Nov 20, 2020
2 parents c64176f + 7b5859e commit 88f1b55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ def is_musl_supported():


class GraalVMConfig(object):
def __init__(self, primary_suite_dir, dynamicimports=None, disable_libpolyglot=False, force_bash_launchers=None, skip_libraries=None, exclude_components=None):
def __init__(self, primary_suite_dir, dynamicimports=None, disable_libpolyglot=False, force_bash_launchers=None, skip_libraries=None,
exclude_components=None, native_images=None):
self._primary_suite_dir = primary_suite_dir
self.dynamicimports = dynamicimports or []
self.disable_libpolyglot = disable_libpolyglot
self.force_bash_launchers = force_bash_launchers or []
self.skip_libraries = skip_libraries or []
self.exclude_components = exclude_components or []
self.native_images = native_images or []
for x, _ in mx.get_dynamic_imports():
self.dynamicimports.append(x)

Expand All @@ -171,12 +173,14 @@ def mx_args(self):
args += ['--skip-libraries=' + ','.join(self.skip_libraries)]
if self.exclude_components:
args += ['--exclude-components=' + ','.join(self.exclude_components)]
if self.native_images:
args += ['--native-images=' + ','.join(self.native_images)]
return args

def _tuple(self):
_force_bash_launchers = tuple(self.force_bash_launchers) if isinstance(self.force_bash_launchers, list) else self.force_bash_launchers
_skip_libraries = tuple(self.skip_libraries) if isinstance(self.skip_libraries, list) else self.skip_libraries
return tuple(self.dynamicimports), self.disable_libpolyglot, _force_bash_launchers, _skip_libraries, tuple(self.exclude_components)
return tuple(self.dynamicimports), self.disable_libpolyglot, _force_bash_launchers, _skip_libraries, tuple(self.exclude_components), tuple(self.native_images)

def __hash__(self):
return hash(self._tuple())
Expand Down Expand Up @@ -1612,8 +1616,8 @@ def maven_plugin_test(args):
maven_opts.append('-XX:+EnableJVMCI')
maven_opts.append('--add-exports=java.base/jdk.internal.module=ALL-UNNAMED')
env['MAVEN_OPTS'] = ' '.join(maven_opts)
config = graalvm_config()
with native_image_context(IMAGE_ASSERTION_FLAGS, config=config):
config = GraalVMConfig(primary_suite_dir=svm_suite().dir, native_images=['native-image'])
with native_image_context(IMAGE_ASSERTION_FLAGS, config=config, build_if_missing=True):
env['JAVA_HOME'] = _vm_home(config)
mx.run_maven(['-e', 'package'], cwd=proj_dir, env=env)
mx.run([join(proj_dir, 'target', 'com.oracle.substratevm.nativeimagemojotest')])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ public void execute() throws MojoExecutionException {
addClasspath(project.getArtifact());
String classpathStr = classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator));

Path nativeImageExecutable = getMojoJavaHome().resolve("bin").resolve("native-image" + (isWindows() ? ".cmd" : ""));
Path nativeImageExecutableRelPath = Paths.get("lib", "svm", "bin", "native-image" + (isWindows() ? ".exe" : ""));
Path nativeImageExecutable = getMojoJavaHome().resolve(nativeImageExecutableRelPath);
if (!Files.isExecutable(nativeImageExecutable)) {
throw new MojoExecutionException("Could not find executable native-image in " + nativeImageExecutable);
nativeImageExecutable = getMojoJavaHome().resolve("jre").resolve(nativeImageExecutableRelPath);
if (!Files.isExecutable(nativeImageExecutable)) {
throw new MojoExecutionException("Could not find executable native-image in " + nativeImageExecutable);
}
}

String nativeImageExecutableVersion = "Unknown";
Expand Down

0 comments on commit 88f1b55

Please sign in to comment.