Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ public final class VFSUtils {
""";

private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
private static final boolean IS_MAC = System.getProperty("os.name").startsWith("Mac");

public static final String LAUNCHER_NAME = IS_WINDOWS ? "graalpy.exe" : "graalpy.sh";
public static final String LAUNCHER_NAME = IS_WINDOWS ? "graalpy.exe" : IS_MAC ? "graalpy" : "graalpy.sh";

private static final String GRAALPY_MAIN_CLASS = "com.oracle.graal.python.shell.GraalPythonMain";

Expand Down Expand Up @@ -848,9 +849,9 @@ private static Path ensureLauncher(Launcher launcherArgs, BuildToolLog log) thro
}
}

private static boolean checkWinLauncherJavaPath(Path venvCfg, Path java) {
private static boolean checkPyVenvCfgFile(Path pyVenvCfg, Path java) {
try {
for (String line : Files.readAllLines(venvCfg)) {
for (String line : Files.readAllLines(pyVenvCfg)) {
if (line.trim().startsWith("venvlauncher_command = " + java)) {
return true;
}
Expand All @@ -871,30 +872,17 @@ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) t
Path java = Paths.get(System.getProperty("java.home"), "bin", "java");
String classpath = String.join(File.pathSeparator, launcherArgs.computeClassPath());
String extraJavaOptions = String.join(" ", GraalPyRunner.getExtraJavaOptions());
if (!IS_WINDOWS) {
// we do not bother checking if it exists and has correct java home, since it is
// simple
// to regenerate the launcher
var script = formatMultiline("""
#!/usr/bin/env bash
%s --enable-native-access=ALL-UNNAMED %s -classpath %s %s --python.Executable="$0" "$@"
""", java, extraJavaOptions, String.join(File.pathSeparator, classpath), GRAALPY_MAIN_CLASS);
try {
Files.writeString(launcherArgs.launcherPath, script);
var perms = Files.getPosixFilePermissions(launcherArgs.launcherPath);
perms.addAll(List.of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE,
PosixFilePermission.OTHERS_EXECUTE));
Files.setPosixFilePermissions(launcherArgs.launcherPath, perms);
} catch (IOException e) {
throw new IOException(String.format("failed to create launcher %s", launcherArgs.launcherPath), e);
if (IS_MAC || IS_WINDOWS) {
if (Files.exists(launcherArgs.launcherPath)
&& checkPyVenvCfgFile(launcherArgs.launcherPath.getParent().resolve("pyvenv.cfg"), java)) {
return;
}
} else if (!Files.exists(launcherArgs.launcherPath)
|| !checkWinLauncherJavaPath(launcherArgs.launcherPath.getParent().resolve("pyenv.cfg"), java)) {
// on windows, generate a venv launcher that executes the java command
var launcherFolder = IS_WINDOWS ? "nt" : "macos";
var launcherName = IS_WINDOWS ? "graalpy.exe" : "graalpy";
var script = formatMultiline("""
import os, shutil, struct, venv
from pathlib import Path
vl = os.path.join(venv.__path__[0], 'scripts', 'nt', 'graalpy.exe')
vl = os.path.join(venv.__path__[0], 'scripts', '%s', '%s')
tl = os.path.join(r'%s')
os.makedirs(Path(tl).parent.absolute(), exist_ok=True)
shutil.copy(vl, tl)
Expand All @@ -903,7 +891,8 @@ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) t
with open(pyvenvcfg, 'w', encoding='utf-8') as f:
f.write('venvlauncher_command = ')
f.write(cmd)
""", launcherArgs.launcherPath, java, extraJavaOptions, classpath, GRAALPY_MAIN_CLASS);
""", launcherFolder, launcherName, launcherArgs.launcherPath, java, extraJavaOptions, classpath,
GRAALPY_MAIN_CLASS);
File tmp;
try {
tmp = File.createTempFile("create_launcher", ".py");
Expand All @@ -922,6 +911,23 @@ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
} catch (InterruptedException e) {
throw new IOException("failed to run Graalpy launcher", e);
}
} else {
// we do not bother checking if it exists and has correct java home, since it is
// simple
// to regenerate the launcher
var script = formatMultiline("""
#!/usr/bin/env bash
%s --enable-native-access=ALL-UNNAMED %s -classpath %s %s --python.Executable="$0" "$@"
""", java, extraJavaOptions, String.join(File.pathSeparator, classpath), GRAALPY_MAIN_CLASS);
try {
Files.writeString(launcherArgs.launcherPath, script);
var perms = Files.getPosixFilePermissions(launcherArgs.launcherPath);
perms.addAll(List.of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE,
PosixFilePermission.OTHERS_EXECUTE));
Files.setPosixFilePermissions(launcherArgs.launcherPath, perms);
} catch (IOException e) {
throw new IOException(String.format("failed to create launcher %s", launcherArgs.launcherPath), e);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<!-- NOTE: revision is special and one can change it from cmd line: `mvn -Drevision=... package` -->
<!-- See https://maven.apache.org/guides/mini/guide-maven-ci-friendly.html -->
<revision>26.0.0-SNAPSHOT</revision>
<revision>25.1.0-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.polyglot.version>${revision}</project.polyglot.version>
Expand Down
23 changes: 19 additions & 4 deletions scripts/maven-bundle-url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ project_root="$( cd -P "$( dirname "$source" )/.." && pwd )"

revision="$(mvn -f "${project_root}/pom.xml" help:evaluate -Dexpression=revision -q -DforceStdout)"
revision="${revision%-SNAPSHOT}" # remove -SNAPSHOT
revision_quoted_for_jq="${revision//./\\\\.}"

echo "Trying to find the release for revision: ${revision}"
curl -sSL "https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/releases" -o github_releases.json
Expand All @@ -23,12 +22,28 @@ echo "Downloaded releases JSON from GitHub, head:"
head -n 20 github_releases.json
echo "==========================================="

asset_url=$(cat github_releases.json \
| jq -r 'map(select(.tag_name | test("'${revision_quoted_for_jq}'"))) | max_by(.published_at) | .assets[] | select(.name | test("^maven-resource-.*\\.zip$")) | .browser_download_url')
# Find the newest maven-resource-bundle ZIP whose name contains the desired revision.
# Scan all releases and their assets, guard against nulls, and pick the latest by published_at.
asset_url=$(
jq -r --arg rev "$revision" '
[ .[] as $rel
| ($rel.assets // [])[]
| select(
(.name | startswith("maven-resource-bundle-")) and
(.name | contains($rev)) and
(.name | endswith(".zip"))
)
| {published_at: $rel.published_at, url: .browser_download_url}
]
| sort_by(.published_at)
| last?
| .url // empty
' github_releases.json
)

rm github_releases.json
if [[ -z "$asset_url" ]]; then
echo "Failed to find a maven-resource-bundle zip" >&2
echo "Failed to find a maven-resource-bundle zip for revision ${revision}" >&2
exit 1
fi
echo $asset_url