Skip to content

Commit f31baa9

Browse files
committed
Use the common.json from graal to choose which jvmci version to use
* The JAVA_HOME needs to be compatible with what the Graal compiler needs. * Also improve the error message when JAVA_HOME is set but not matching.
1 parent 3bd771b commit f31baa9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tool/jt.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,16 @@ def ee_jdk?
180180
ee?
181181
end
182182

183+
def graal_common_json
184+
"#{GRAAL_DIR}/common.json"
185+
end
186+
183187
def jvmci_version
184188
@jvmci_version ||= begin
185-
ci = File.read("#{TRUFFLERUBY_DIR}/common.json")
189+
common_json = File.read(graal_common_json)
186190
edition = ee_jdk? ? 'ee' : 'ce'
187191
regex = /"labsjdk-#{edition}-#{@jdk_version}":\s*\{\s*"name":\s*"labsjdk"\s*,\s*"version":\s*"[^"]+-(jvmci-[^"]+)"\s*,/
188-
raise "JVMCI version not found for labsjdk-#{edition}-#{@jdk_version} in common.json" unless regex =~ ci
192+
raise "JVMCI version not found for labsjdk-#{edition}-#{@jdk_version} in #{graal_common_json}" unless regex =~ common_json
189193
$1
190194
end
191195
end
@@ -592,6 +596,7 @@ def find_java_home
592596
end
593597
end
594598
java_home ||= ENV['JAVA_HOME']
599+
fix = 'Run `unset JAVA_HOME` and retry to automatically download the correct JDK.'
595600

596601
if java_home
597602
java_home = File.realpath(java_home)
@@ -603,10 +608,10 @@ def find_java_home
603608
if java_version_output.include?(jvmci_version)
604609
:use_env_java_home
605610
elsif java_version_output.include?('jvmci')
606-
warn "warning: JAVA_HOME=#{java_home} is not the same JVMCI version as in common.json (#{jvmci_version})"
611+
warn "warning: JAVA_HOME=#{java_home} is not the same JVMCI version as in #{graal_common_json} (#{jvmci_version}).\n#{fix}"
607612
:use_env_java_home
608613
else
609-
raise "$JAVA_HOME does not seem to point to a JVMCI-enabled JDK (`#{java_home}/bin/java -version` does not contain 'jvmci')"
614+
raise "$JAVA_HOME does not seem to point to a JVMCI-enabled JDK (`#{java_home}/bin/java -version` does not contain 'jvmci').\n#{fix}"
610615
end
611616
else
612617
raise '$JAVA_HOME should be set in CI' if ci?
@@ -2329,7 +2334,7 @@ def graph(*args)
23292334
ruby2_keywords :cfg2asm if respond_to?(:ruby2_keywords, true)
23302335

23312336
def igv
2332-
compiler = File.expand_path '../graal/compiler', TRUFFLERUBY_DIR
2337+
compiler = "#{GRAAL_DIR}/compiler"
23332338
mx('igv', chdir: compiler)
23342339
end
23352340

@@ -2358,7 +2363,7 @@ def install(name, *options)
23582363
jdk_binaries = File.expand_path '../graal-enterprise/ci/jdk-binaries.json', TRUFFLERUBY_DIR
23592364
end
23602365
mx '-y', 'fetch-jdk',
2361-
'--configuration', "#{TRUFFLERUBY_DIR}/common.json",
2366+
'--configuration', graal_common_json,
23622367
*(['--jdk-binaries', jdk_binaries] if jdk_binaries),
23632368
'--java-distribution', jdk_name,
23642369
'--to', JDKS_CACHE_DIR,
@@ -2468,7 +2473,9 @@ def bootstrap_toolchain
24682473
end
24692474

24702475
private def sforceimports?(mx_base_args)
2471-
scheckimports_output = mx(*mx_base_args, 'scheckimports', '--ignore-uncommitted', '--warn-only', primary_suite: TRUFFLERUBY_DIR, capture: :both)
2476+
return true unless File.directory?(GRAAL_DIR)
2477+
2478+
scheckimports_output = mx(*mx_base_args, 'scheckimports', '--ignore-uncommitted', '--warn-only', java_home: :none, primary_suite: TRUFFLERUBY_DIR, capture: :both)
24722479

24732480
unless scheckimports_output.empty?
24742481
# Don't ask to update, just warn.
@@ -2537,14 +2544,14 @@ def bootstrap_toolchain
25372544
checkout_enterprise_revision(env) if cloned
25382545

25392546
if options.delete('--sforceimports') || sforceimports?(mx_base_args)
2540-
mx('sforceimports', primary_suite: TRUFFLERUBY_DIR)
2547+
mx('sforceimports', java_home: :none, primary_suite: TRUFFLERUBY_DIR)
25412548
if ee
25422549
checkout_enterprise_revision(env) if !cloned
25432550
# sforceimports for optional suites imported in vm-enterprise like substratevm-enterprise-gcs
25442551
vm_enterprise = File.expand_path '../graal-enterprise/vm-enterprise', TRUFFLERUBY_DIR
2545-
mx('--env', env_path(env), 'sforceimports', primary_suite: vm_enterprise)
2552+
mx('--env', env_path(env), 'sforceimports', java_home: :none, primary_suite: vm_enterprise)
25462553
# And still make sure we import the graal revision as in mx.truffleruby/suite.py
2547-
mx('sforceimports', primary_suite: TRUFFLERUBY_DIR)
2554+
mx('sforceimports', java_home: :none, primary_suite: TRUFFLERUBY_DIR)
25482555
end
25492556
end
25502557

0 commit comments

Comments
 (0)