Skip to content

Commit

Permalink
[GR-15451] [GR-16989] Provide a way to include dependent languages ho…
Browse files Browse the repository at this point in the history
…mes in a standalone.

PullRequest: graal/4282
  • Loading branch information
eregon committed Sep 24, 2019
2 parents 56e35c2 + 89cefd8 commit 84b6c4e
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 213 deletions.
2 changes: 1 addition & 1 deletion compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@
"org.graalvm.compiler.truffle.compiler.substitutions.TruffleInvocationPluginProvider",
"org.graalvm.compiler.truffle.runtime.LoopNodeFactory",
"org.graalvm.compiler.truffle.runtime.TruffleTypes",
"com.oracle.truffle.api.impl.HomeFinder",
"org.graalvm.home.HomeFinder",
],
"requiresConcealed" : {
"jdk.internal.vm.ci" : "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
} else if (holderQualified.equals("org.graalvm.compiler.hotspot.JVMCIVersionCheck") && caller.getName().equals("main")) {
// The main method in JVMCIVersionCheck is only called from the shell
return;
} else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.polyglot")) {
// Truffle and Polyglot do not depend on JVMCI so cannot use
} else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.polyglot") || packageName.startsWith("org.graalvm.home")) {
// Truffle and SDK do not depend on JVMCI so they cannot use
// Services.getSavedProperties()
return;
} else if (packageName.startsWith("com.oracle.svm")) {
Expand Down
20 changes: 17 additions & 3 deletions sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import os
import shutil

from os.path import join, exists, isfile, isdir, basename
from os.path import join, exists, isfile, isdir, dirname, basename, relpath
from zipfile import ZipFile, ZIP_DEFLATED

from mx_gate import Task
Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(self, destination, jar_distributions, main_class, build_args, is_ma
:param str main_class
:param bool is_main_launcher
:param bool default_symlinks
:param bool is_sdk_launcher
:param bool is_sdk_launcher: Whether it uses org.graalvm.launcher.Launcher
:param str custom_bash_launcher: Uses custom bash launcher, unless compiled as native image
"""
super(LauncherConfig, self).__init__(destination, jar_distributions, build_args, **kwargs)
Expand All @@ -165,6 +165,14 @@ def __init__(self, destination, jar_distributions, main_class, build_args, is_ma
self.custom_bash_launcher = custom_bash_launcher
self.extra_jvm_args = [] if extra_jvm_args is None else extra_jvm_args

self.relative_home_paths = {}

def add_relative_home_path(self, language, path):
if language in self.relative_home_paths and self.relative_home_paths[language] != path:
raise Exception('the relative home path of {} is already set to {} and cannot also be set to {} for {}'.format(
language, self.relative_home_paths[language], path, self.destination))
self.relative_home_paths[language] = path


class LanguageLauncherConfig(LauncherConfig):
def __init__(self, destination, jar_distributions, main_class, build_args, language,
Expand All @@ -176,6 +184,9 @@ def __init__(self, destination, jar_distributions, main_class, build_args, langu
is_sdk_launcher=is_sdk_launcher, is_polyglot=False, **kwargs)
self.language = language

# Ensure the language launcher can always find the language home
self.add_relative_home_path(language, relpath('.', dirname(destination)))


class LibraryConfig(AbstractNativeImageConfig):
def __init__(self, destination, jar_distributions, build_args, jvm_library=False, **kwargs):
Expand Down Expand Up @@ -291,17 +302,20 @@ def direct_dependencies(self):

class GraalVmTruffleComponent(GraalVmComponent):
def __init__(self, suite, name, short_name, license_files, third_party_license_files, truffle_jars,
include_in_polyglot=True, standalone_dir_name=None, **kwargs):
include_in_polyglot=True, standalone_dir_name=None, standalone_dependencies=None, **kwargs):
"""
:param list[str] truffle_jars: JAR distributions that should be on the classpath for the language implementation.
:param bool include_in_polyglot: whether this component is included in `--language:all` or `--tool:all` and should be part of polyglot images.
:param str standalone_dir_name: name for the standalone archive and directory inside
:param dict[str, (str, list[str])] standalone_dependencies: dict of dependent components to include in the standalone in the form {component name: (relative path, excluded_paths)}.
"""
super(GraalVmTruffleComponent, self).__init__(suite, name, short_name, license_files, third_party_license_files,
jar_distributions=truffle_jars, **kwargs)
self.include_in_polyglot = include_in_polyglot
self.standalone_dir_name = standalone_dir_name or '{}-<version>-<graalvm_os>-<arch>'.format(self.dir_name)
self.standalone_dependencies = standalone_dependencies or {}
assert isinstance(self.include_in_polyglot, bool)
assert isinstance(self.standalone_dependencies, dict)


class GraalVmLanguage(GraalVmTruffleComponent):
Expand Down
12 changes: 12 additions & 0 deletions sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@
"javaCompliance" : "8+",
"workingSets" : "API,SDK,Test",
},
"org.graalvm.home" : {
"subDir" : "src",
"sourceDirs" : ["src"],
"dependencies" : [
"org.graalvm.nativeimage",
],
"checkstyle" : "org.graalvm.word",
"javaCompliance" : "8+",
"workingSets" : "API,SDK",
},
},
"licenses" : {
"UPL" : {
Expand All @@ -206,6 +216,7 @@
"org.graalvm.polyglot",
"org.graalvm.nativeimage",
"org.graalvm.collections",
"org.graalvm.home",
],
"distDependencies" : [],
"javadocType": "api",
Expand All @@ -214,6 +225,7 @@
"requires" : ["java.logging"],
"exports" : [
"org.graalvm.collections",
"org.graalvm.home",
"org.graalvm.nativeimage.hosted",
"org.graalvm.nativeimage.c.function",
"org.graalvm.nativeimage.c.struct",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.graalvm.home.impl.DefaultHomeFinder
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,56 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.oracle.truffle.api.impl;
package org.graalvm.home;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleOptions;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.ServiceLoader;

public abstract class HomeFinder {

private static HomeFinder nativeImageHomeFinder; // effectively final after native image
// compilation
import org.graalvm.home.impl.DefaultHomeFinder;
import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;

public abstract class HomeFinder {
/**
* @return the GraalVM home folder if inside GraalVM or {@code null} otherwise.
*/
public abstract Path getHomeFolder();

/**
* @return the GraalVM version or {@code "snapshot"} if unknown.
*/
public abstract String getVersion();

public abstract Map<String, Path> getLanguageHomes();

public abstract Map<String, Path> getToolHomes();

public static HomeFinder getInstance() {
if (TruffleOptions.AOT) {
return nativeImageHomeFinder;
}
return Truffle.getRuntime().getCapability(HomeFinder.class);
}

/**
* Looks up the {@link HomeFinder} instance.
*
* NOTE: this method is called reflectively by downstream projects.
*
* @return the HomeFinder instance by using a ServiceLoader.
* @throws IllegalStateException if no implementation could be found.
*/
@SuppressWarnings("unused")
private static void initializeNativeImageState() {
assert TruffleOptions.AOT : "Only supported during image generation";
nativeImageHomeFinder = Truffle.getRuntime().getCapability(HomeFinder.class);
public static HomeFinder getInstance() {
if (ImageInfo.inImageCode()) {
return ImageSingletons.lookup(HomeFinder.class);
} else {
final ServiceLoader<HomeFinder> serviceLoader = ServiceLoader.load(HomeFinder.class);
final Iterator<HomeFinder> iterator = serviceLoader.iterator();
try {
return iterator.next();
} catch (NoSuchElementException e) {
throw new IllegalStateException("No implementation of " + HomeFinder.class.getName() + " could be found");
}
}
}
}

/**
* Cleans the {@link HomeFinder} instance.
*
* NOTE: this method is called reflectively by downstream projects.
*
*/
@SuppressWarnings("unused")
private static void resetNativeImageState() {
assert TruffleOptions.AOT : "Only supported during image generation";
nativeImageHomeFinder = null;
class HomeFinderFeature implements Feature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
ImageSingletons.add(HomeFinder.class, new DefaultHomeFinder());
}
}
Loading

0 comments on commit 84b6c4e

Please sign in to comment.