Skip to content

Commit 7d025e8

Browse files
committed
JT: Automatically download the correct JDK with mx fetch-jdk
1 parent 2038ab2 commit 7d025e8

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

tool/jt.rb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def find_java_home
530530
end
531531
else
532532
raise '$JAVA_HOME should be set in CI' if ci?
533-
install_jvmci('$JAVA_HOME is not set, downloading JDK8 with JVMCI')
533+
install_jvmci('$JAVA_HOME is not set, downloading JDK8 with JVMCI', (@mx_env || @ruby_name || '').include?('ee'))
534534
end
535535
end
536536
end
@@ -548,7 +548,7 @@ def mx(*args, java_home: find_java_home, **options)
548548
mx_args = args.dup
549549

550550
env = mx_args.first.is_a?(Hash) ? mx_args.shift : {}
551-
mx_args.unshift '--java-home', java_home unless java_home == :use_env_java_home
551+
mx_args.unshift '--java-home', java_home unless java_home == :use_env_java_home or java_home == :none
552552

553553
raw_sh(env, find_mx, *mx_args, **options)
554554
end
@@ -1928,38 +1928,35 @@ def profile(*args)
19281928
def install(name, *options)
19291929
case name
19301930
when 'jvmci'
1931-
puts install_jvmci('Downloading JDK8 with JVMCI')
1931+
puts install_jvmci('Downloading JDK8 with JVMCI', (@ruby_name || '').include?('ee'))
19321932
when 'eclipse'
19331933
puts install_eclipse
19341934
else
19351935
raise "Unknown how to install #{what}"
19361936
end
19371937
end
19381938

1939-
private def install_jvmci(download_message)
1940-
raise 'Installing JVMCI is only available on Linux and macOS currently' unless linux? || darwin?
1939+
private def install_jvmci(download_message, ee)
1940+
jdk_name = ee ? 'oraclejdk8' : 'openjdk8'
19411941

1942-
update, jvmci_version = jvmci_update_and_version
1943-
java_home = begin
1944-
dir_pattern = "#{CACHE_EXTRA_DIR}/openjdk1.8.0*#{jvmci_version}"
1945-
if Dir[dir_pattern].empty?
1946-
STDERR.puts download_message
1947-
jvmci_releases = 'https://github.com/graalvm/graal-jvmci-8/releases/download'
1948-
filename = "openjdk-8u#{update}-#{jvmci_version}-#{mx_os}-amd64.tar.gz"
1949-
chdir(CACHE_EXTRA_DIR) do
1950-
raw_sh 'curl', '-L', "#{jvmci_releases}/#{jvmci_version}/#{filename}", '-o', filename
1951-
raw_sh 'tar', 'xf', filename
1952-
end
1942+
_, jvmci_version = jvmci_update_and_version
1943+
java_home = "#{CACHE_EXTRA_DIR}/#{jdk_name}-#{jvmci_version}"
1944+
unless File.directory?(java_home)
1945+
STDERR.puts "#{download_message} (#{jdk_name})"
1946+
if ee
1947+
mx_env = 'jvm-ee'
1948+
options = { java_home: install_jvmci('Downloading OpenJDK8 JVMCI to bootstrap', false) }
1949+
else
1950+
mx_env = 'jvm'
1951+
options = { chdir: CACHE_EXTRA_DIR, java_home: :none } # chdir to not try to load a suite (which would need a JAVA_HOME)
19531952
end
1954-
dirs = Dir[dir_pattern]
1955-
abort "ambiguous JVMCI directories:\n#{dirs.join("\n")}" if dirs.length != 1
1956-
extracted = dirs.first
1957-
darwin? ? "#{extracted}/Contents/Home" : extracted
1953+
mx '--env', mx_env, '-y', 'fetch-jdk',
1954+
'--configuration', "#{TRUFFLERUBY_DIR}/common.json",
1955+
'--java-distribution', jdk_name,
1956+
'--to', CACHE_EXTRA_DIR,
1957+
**options
19581958
end
19591959

1960-
abort 'Could not find the extracted JDK' unless java_home
1961-
java_home = File.expand_path(java_home)
1962-
19631960
java = "#{java_home}/bin/java"
19641961
abort "#{java_home} does not exist" unless File.executable?(java)
19651962

@@ -2101,6 +2098,7 @@ def bootstrap_toolchain
21012098
else
21022099
'jvm'
21032100
end
2101+
@mx_env = env
21042102
raise 'Cannot use both --use and --env' if defined?(@ruby_name)
21052103

21062104
@ruby_name = if (i = options.index('--name') || options.index('-n'))
@@ -2114,12 +2112,13 @@ def bootstrap_toolchain
21142112
mx_base_args = ['-p', TRUFFLERUBY_DIR, '--env', env]
21152113

21162114
# Must clone enterprise before running `mx scheckimports` in `sforceimports?`
2117-
cloned = env.include?('ee') && clone_enterprise
2115+
ee = env.include?('ee')
2116+
cloned = clone_enterprise if ee
21182117
checkout_enterprise_revision(env) if cloned
21192118

21202119
if options.delete('--sforceimports') || sforceimports?(mx_base_args)
21212120
mx('-p', TRUFFLERUBY_DIR, 'sforceimports')
2122-
checkout_enterprise_revision(env) if env.include?('ee') && !cloned
2121+
checkout_enterprise_revision(env) if ee && !cloned
21232122
end
21242123

21252124
mx_options, mx_build_options = args_split(options)

0 commit comments

Comments
 (0)