From dc57b99bb8281f5cc746d9a41e4670c770df15cc Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Mon, 7 Aug 2017 13:34:45 +0100 Subject: [PATCH] Logic to automatically find Graal if it's built as a sibling --- doc/contributor/workflow.md | 6 ++++-- tool/jt.rb | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/contributor/workflow.md b/doc/contributor/workflow.md index 6b126e783411..21e3622df217 100644 --- a/doc/contributor/workflow.md +++ b/doc/contributor/workflow.md @@ -142,10 +142,12 @@ $ export GRAALVM_BIN=.../graalvm-0.nn/bin/java $ jt ruby --graal -e 'p Truffle.graal?' ``` -To run with Graal built from source, set `GRAAL_HOME`. +To run with Graal built from source, set `GRAAL_HOME`. Or it will be +automatically found if it is cloned into the same directory as `truffleruby`, it +is built, and you are not using a binary suite for Truffle. ```bash -$ export GRAAL_HOME=.../graal-core +$ export GRAAL_HOME=.../graal $ jt ruby --graal ... ``` diff --git a/tool/jt.rb b/tool/jt.rb index ce6efac93c6c..9c933e5eadc4 100755 --- a/tool/jt.rb +++ b/tool/jt.rb @@ -85,8 +85,12 @@ def self.find_graal_javacmd_and_options "--module-path=#{jvmci_graal_home}/../truffle/mxbuild/modules/com.oracle.truffle.truffle_api.jar:#{jvmci_graal_home}/mxbuild/modules/com.oracle.graal.graal_core.jar" ] options = ['--no-bootclasspath'] - elsif graal_home - graal_home = File.expand_path(graal_home, TRUFFLERUBY_DIR) + elsif graal_home || auto_graal_home = find_auto_graal_home + if graal_home + graal_home = File.expand_path(graal_home, TRUFFLERUBY_DIR) + else + graal_home = auto_graal_home + end output, _ = ShellUtils.mx('-v', '-p', graal_home, 'vm', '-version', :err => :out, capture: true) command_line = output.lines.select { |line| line.include? '-version' } if command_line.size == 1 @@ -105,6 +109,14 @@ def self.find_graal_javacmd_and_options end [javacmd, vm_args.map { |arg| "-J#{arg}" } + options] end + + def self.find_auto_graal_home + sibling_compiler = File.expand_path('../graal/compiler', TRUFFLERUBY_DIR) + return nil unless Dir.exist?(sibling_compiler) + return nil unless File.exist?("#{sibling_compiler}/mxbuild/dists/graal-compiler.jar") + return nil if Dir.exist?("#{TRUFFLERUBY_DIR}/mx.imports/binary/truffle") + sibling_compiler + end def self.which(binary) ENV["PATH"].split(File::PATH_SEPARATOR).each do |dir| @@ -381,7 +393,7 @@ def help jt rebuild clean, sforceimports, and build jt dis finds the bc file in the project, disassembles, and returns new filename jt run [options] args... run JRuby with args - --graal use Graal (set either GRAALVM_BIN or GRAAL_HOME) + --graal use Graal (set either GRAALVM_BIN, JVMCI_BIN or GRAAL_HOME, or have graal built as a sibling) --stress stress the compiler (compile immediately, foreground compilation, compilation exceptions are fatal) --js add Graal.js to the classpath (set GRAAL_JS_JAR) --asm show assembly (implies --graal) @@ -404,7 +416,7 @@ def help --syslog runs syslog tests --openssl runs openssl tests --aot use AOT TruffleRuby image (set AOT_BIN) - --graal use Graal (set either GRAALVM_BIN, JVMCI_BIN or GRAAL_HOME) + --graal use Graal (set either GRAALVM_BIN, JVMCI_BIN or GRAAL_HOME, or have graal built as a sibling) jt test specs run all specs jt test specs fast run all specs except sub-processes, GC, sleep, ... jt test spec/ruby/language run specs in this directory