Skip to content

Commit c44a6de

Browse files
committed
[GR-25597] Forbid desynchronized repositories unless a flag / environment variable is supplied.
PullRequest: truffleruby/1930
2 parents f65ce6f + a83e217 commit c44a6de

File tree

2 files changed

+91
-26
lines changed

2 files changed

+91
-26
lines changed

doc/contributor/workflow.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,22 @@ TruffleRuby needs the `truffle` and `sulong` suites from the `graal` repository.
9191
When running `jt build`, you might see an early warning:
9292
```
9393
$ jt build
94-
$ mx --env jvm scheckimports --ignore-uncommitted --warn-only
95-
WARNING: imported version of sulong in truffleruby (89aaf87268) does not match parent (aa6d8e07a6)
96-
You might want to run "mx sforceimports" to use the imported version or update the import with "mx scheckimports"
94+
...
95+
NOTE: Set env variable JT_IMPORTS_DONT_ASK to always answer 'no' to this prompt.
96+
97+
WARNING: imported version of sulong in truffleruby (ae65c10142907329e03ad8e3fa17b88aca42058d) does not match parent (1bf42ddef0e4961cbb92ebc31019747fd1c15f1a)
98+
Do you want to checkout the supported version of graal as specified in truffleruby's suite.py? (runs `mx sforceimports`) [y/n]
99+
...
97100
```
98101

99102
This warning is important.
100-
If you did not create new commits in `graal`, you will typically need to run `jt mx sforceimports`
101-
so that a known compatible commit of `graal` is used (that commit is recorded in `mx.truffleruby/suite.py`).
102103

103-
This is not done automatically, because sometimes you might want to have changes in `graal`,
104-
and because developers of the Truffle or Sulong team typically want to use a different commit of `graal` to test their changes.
104+
- If you did not create new commits in `graal`, this means the graal import was bumped in `suite.py` and you need
105+
to answer `y` to this prompt, which will be equivalent to running `jt mx sforceimports` before proceeding.
106+
- If you did create new `graal` commits, you should answer `n` or set `JT_IMPORTS_DONT_ASK` (to any value) to
107+
automatically do so.
108+
- If you want to set the `suite.py` import to that checked out in `graal` (unlikely), you should run
109+
jt mx scheckimports` beforehand.
105110

106111
### Building C Extensions more quickly
107112

tool/jt.rb

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
# Forward signals to sub-processes, so they get notified when sending a signal to jt
102102
[:SIGINT, :SIGTERM].each do |signal|
103103
trap(signal) do
104+
# Enables command line signals (e.g. Ctrl+C) when waiting for input if there are no subprocesses.
105+
raise Interrupt if SUBPROCESSES.empty?
106+
104107
SUBPROCESSES.each do |pid|
105108
Utilities.send_signal(signal, pid)
106109
end
@@ -577,14 +580,38 @@ def args_split(args)
577580
return [args, []] unless delimiter_index
578581
[args[0...delimiter_index], args[(delimiter_index + 1)..-1]]
579582
end
583+
584+
def with_color(color_code, &block)
585+
print color_code if STDOUT.tty?
586+
begin
587+
result = yield block
588+
ensure
589+
print TERM_COLOR_DEFAULT if STDOUT.tty?
590+
end
591+
result
592+
end
593+
594+
def boxed(&block)
595+
puts ''
596+
puts '============================================================'
597+
puts ''
598+
result = yield block
599+
puts ''
600+
puts '============================================================'
601+
puts ''
602+
result
603+
end
604+
605+
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
606+
TERM_COLOR_RED = "\e[31m"
607+
TERM_COLOR_DEFAULT = "\e[39m"
580608
end
581609

582610
module Commands
583611
include Utilities
584612

585613
def help
586-
# <<~ cannot be used since idea thinks TR is 2.1 and displays it as error
587-
puts <<-TXT.gsub(/^ {6}/, '')
614+
puts <<~TXT
588615
Usage: jt [options] COMMAND [command-options]
589616
Where options are:
590617
--build Runs `jt build` before the command
@@ -609,7 +636,7 @@ def help
609636
GraalVM with JVM and Truffleruby only available in mxbuild/truffleruby-jvm,
610637
the Ruby is symlinked into rbenv or chruby if available
611638
options:
612-
--sforceimports run sforceimports before building (default: false)
639+
--sforceimports run `mx sforceimports` before building (default: false)
613640
--env|-e mx env file used to build the GraalVM, default is "jvm"
614641
--name|-n NAME specify the name of the build "mxbuild/truffleruby-NAME",
615642
it is also linked in your ruby manager (if found) under the same name,
@@ -1196,18 +1223,18 @@ def retag(*args)
11961223
expected_file = "#{dir}/expected.txt"
11971224
expected = File.read(expected_file)
11981225
unless actual == expected
1199-
abort <<-EOS
1200-
C extension #{dir} didn't work as expected
1226+
abort <<~EOS
1227+
C extension #{dir} didn't work as expected
12011228
1202-
Actual:
1203-
#{actual}
1229+
Actual:
1230+
#{actual}
12041231
1205-
Expected:
1206-
#{expected}
1232+
Expected:
1233+
#{expected}
12071234
1208-
Diff:
1209-
#{diff(expected_file, output_file)}
1210-
EOS
1235+
Diff:
1236+
#{diff(expected_file, output_file)}
1237+
EOS
12111238
end
12121239
ensure
12131240
File.delete output_file if File.exist? output_file
@@ -1978,6 +2005,41 @@ def bootstrap_toolchain
19782005
destination
19792006
end
19802007

2008+
private def sforceimports? (mx_base_args)
2009+
scheckimports_output = mx(*mx_base_args, 'scheckimports', '--ignore-uncommitted', '--warn-only', capture: :both)
2010+
2011+
unless scheckimports_output.empty?
2012+
# Don't ask to update, just warn.
2013+
if ENV['JT_IMPORTS_DONT_ASK'] || !STDIN.tty?
2014+
with_color(TERM_COLOR_RED) do
2015+
boxed do
2016+
puts scheckimports_output
2017+
puts <<~MESSAGE
2018+
You might want to:
2019+
* use the version of graal in suite.py, then use "jt build --sforceimports", useful when building TruffleRuby and not changing graal at the same time (most common)
2020+
* update the graal version in suite.py, then use "mx scheckimports", useful when explicitly updating the default graal version of TruffleRuby (rare)
2021+
* test TruffleRuby with a different graal version with your own changes in graal, then you can ignore this warning
2022+
MESSAGE
2023+
end
2024+
end
2025+
false
2026+
else
2027+
# Ask to update imports.
2028+
with_color(TERM_COLOR_RED) do
2029+
puts "\nNOTE: Set env variable JT_IMPORTS_DONT_ASK to always answer 'no' to this prompt.\n\n"
2030+
puts scheckimports_output
2031+
input = ''
2032+
until %w(y n).include? input
2033+
print 'Do you want to checkout the supported version of graal as specified in truffleruby\'s suite.py? (runs `mx sforceimports`) [y/n] '
2034+
input = STDIN.gets.chomp
2035+
end
2036+
puts ''
2037+
input == 'y'
2038+
end
2039+
end
2040+
end
2041+
end
2042+
19812043
private def build_graalvm(*options)
19822044
raise 'use --env jvm-ce instead' if options.delete('--graal')
19832045
raise 'use --env native instead' if options.delete('--native')
@@ -2003,19 +2065,17 @@ def bootstrap_toolchain
20032065
end
20042066

20052067
name = "truffleruby-#{@ruby_name}"
2068+
mx_base_args = ['-p', TRUFFLERUBY_DIR, '--env', env]
20062069

2070+
# Must clone enterprise before running `mx scheckimports` in `sforceimports?`
20072071
cloned = env.include?('ee') && clone_enterprise
2072+
checkout_enterprise_revision(env) if cloned
20082073

2009-
if options.delete('--sforceimports')
2074+
if options.delete('--sforceimports') || sforceimports?(mx_base_args)
20102075
mx('-p', TRUFFLERUBY_DIR, 'sforceimports')
2011-
checkout_enterprise_revision(env) if env.include?('ee')
2012-
else
2013-
checkout_enterprise_revision(env) if cloned
2076+
checkout_enterprise_revision(env) if env.include?('ee') && !cloned
20142077
end
20152078

2016-
mx_base_args = ['-p', TRUFFLERUBY_DIR, '--env', env]
2017-
mx(*mx_base_args, 'scheckimports', '--ignore-uncommitted', '--warn-only')
2018-
20192079
mx_options, mx_build_options = args_split(options)
20202080
mx_args = mx_base_args + mx_options
20212081

0 commit comments

Comments
 (0)