Skip to content

Commit

Permalink
Introduce trufflesqueak-polyglot-get
Browse files Browse the repository at this point in the history
Fixes #176
  • Loading branch information
fniephaus committed Feb 16, 2024
1 parent db1e480 commit 6f38434
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ jobs:
if: ${{ runner.os == 'Windows' }}
- name: Run SystemReporter on TruffleSqueak standalone
run: 'trufflesqueak --code "(String streamContents: [:s | SystemReporter basicNew reportImage: s; reportVM: s; reportVMParameters: s]) withUnixLineEndings" images/test-64bit.image'
- name: Run trufflesqueak-polyglot-get on TruffleSqueak JVM standalone
run: |
trufflesqueak-polyglot-get -v 23.1.0 -a js
trufflesqueak --code "Polyglot eval: 'js' string: 'new Object({hello: \"world\"})'" images/test-64bit.image
if: ${{ matrix.type == 'jvm' }}
- name: Upload TruffleSqueak standalone
uses: actions/upload-artifact@v4
with:
Expand Down
5 changes: 2 additions & 3 deletions mx.trufflesqueak/mx_trufflesqueak.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,13 @@ def patched_native_image(self, build_args, output_file, out=None, err=None, find
library_configs=[
mx_sdk.LanguageLibraryConfig(
language=LANGUAGE_ID,
jar_distributions=['trufflesqueak:TRUFFLESQUEAK_LAUNCHER'],
launchers=['bin/<exe:trufflesqueak>', 'bin/<exe:trufflesqueak-polyglot-get>'],
jar_distributions=['trufflesqueak:TRUFFLESQUEAK_LAUNCHER', 'sdk:MAVEN_DOWNLOADER'],
main_class='%s.launcher.TruffleSqueakLauncher' % PACKAGE_NAME,
build_args=[
'-H:+DumpThreadStacksOnSignal',
'-H:+DetectUserDirectoriesInImageHeap',
],
destination='lib/<lib:%svm>' % LANGUAGE_ID,
launchers=['bin/<exe:trufflesqueak>'],
default_vm_args=[
'--vm.Xms512M',
'--vm.Xss16M',
Expand Down
2 changes: 2 additions & 0 deletions mx.trufflesqueak/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"dependencies": [
"TRUFFLESQUEAK_SHARED",
"sdk:LAUNCHER_COMMON",
"sdk:MAVEN_DOWNLOADER",
],
"requires": [
"java.desktop",
Expand Down Expand Up @@ -352,6 +353,7 @@
"distDependencies": [
"TRUFFLESQUEAK_SHARED",
"sdk:LAUNCHER_COMMON",
"sdk:MAVEN_DOWNLOADER",
],
"maven": {
"groupId": "de.hpi.swa.trufflesqueak",
Expand Down
2 changes: 1 addition & 1 deletion mx.trufflesqueak/trufflesqueak-jvm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
COMPONENTS=TruffleSqueak,suite:tools,GraalVM compiler,SubstrateVM,LibGraal
DEFAULT_DYNAMIC_IMPORTS=/compiler,/substratevm,/tools,/vm
INSTALLABLES=TruffleSqueak
NATIVE_IMAGES=lib:jvmcicompiler
NATIVE_IMAGES=lib:jvmcicompiler,trufflesqueak-polyglot-get
BUILD_TARGETS=GRAALVM,GRAALVM_STANDALONES
GRAALVM_SKIP_ARCHIVE=true
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;

import org.graalvm.launcher.AbstractLanguageLauncher;
import org.graalvm.maven.downloader.Main;
import org.graalvm.options.OptionCategory;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
Expand All @@ -32,6 +33,8 @@ public final class TruffleSqueakLauncher extends AbstractLanguageLauncher {
private static final String ENGINE_MODE_OPTION = "engine.Mode";
private static final String ENGINE_MODE_LATENCY = "latency";

private static final String[] EMPTY_STRING_ARRAY = new String[0];

private boolean headless;
private boolean printImagePath;
private boolean quiet;
Expand All @@ -47,6 +50,15 @@ public static void main(final String[] arguments) throws RuntimeException {

@Override
protected List<String> preprocessArguments(final List<String> arguments, final Map<String, String> polyglotOptions) {
final String launcherName = System.getProperty("org.graalvm.launcher.executablename", "trufflesqueak");
if (launcherName.endsWith("trufflesqueak-polyglot-get")) {
if (isAOT()) {
throw abort("trufflesqueak-polyglot-get is not available in a native standalone. Please try again with a JVM standalone of TruffleSqueak.");
} else {
polyglotGet(arguments);
}
}

final List<String> unrecognized = new ArrayList<>();
for (int i = 0; i < arguments.size(); i++) {
final String arg = arguments.get(i);
Expand Down Expand Up @@ -165,7 +177,7 @@ protected String getMainClass() {

@Override
protected String[] getDefaultLanguages() {
return new String[0]; // Allow all languages (same effect of `--polyglot`)
return EMPTY_STRING_ARRAY; // Allow all languages (same effect of `--polyglot`)
}

@Override
Expand Down Expand Up @@ -198,4 +210,34 @@ private static String getRuntimeName() {
return engine.getImplementationName();
}
}

/* Maven Downloader support */

private static void polyglotGet(final List<String> arguments) {
final String smalltalkHome = getPropertyOrFail("org.graalvm.language.smalltalk.home");
final String outputDir = smalltalkHome + File.separator + "modules";
final List<String> args = new ArrayList<>();
args.add("-o");
args.add(outputDir);
args.add("-v");
args.add(getPropertyOrFail("org.graalvm.version"));
if (arguments.size() == 1 && !arguments.get(0).startsWith("-")) {
args.add("-a");
}
args.addAll(arguments);
try {
Main.main(args.toArray(EMPTY_STRING_ARRAY));
} catch (Exception e) {
throw new Error(e);
}
System.exit(0);
}

private static String getPropertyOrFail(final String property) {
final String value = System.getProperty(property);
if (value == null) {
throw new UnsupportedOperationException("Expected system property '" + property + "' to be set");
}
return value;
}
}

0 comments on commit 6f38434

Please sign in to comment.