@@ -160,7 +160,7 @@ def get_truffle_version(from: :suite)
160
160
raise unless /"name": "sulong",.+?"version": "(\h {40})"/m =~ suite
161
161
$1
162
162
when :repository
163
- raw_sh ( 'git' , 'rev-parse' , 'HEAD' , capture : :out , no_print_cmd : true , chdir : GRAAL_DIR ) . chomp
163
+ sh ( 'git' , 'rev-parse' , 'HEAD' , capture : :out , no_print_cmd : true , chdir : GRAAL_DIR ) . chomp
164
164
else
165
165
raise ArgumentError , from : from
166
166
end
@@ -332,9 +332,8 @@ def find_or_clone_repo(url, commit=nil)
332
332
name = File . basename url , '.git'
333
333
path = File . expand_path ( "../#{ name } " , TRUFFLERUBY_DIR )
334
334
unless Dir . exist? path
335
- target = "../#{ name } "
336
- sh 'git' , 'clone' , url , target
337
- sh 'git' , 'checkout' , commit , chdir : target if commit
335
+ git_clone url , path
336
+ sh 'git' , 'checkout' , commit , chdir : path if commit
338
337
end
339
338
path
340
339
end
@@ -386,7 +385,7 @@ def diff(expected, actual)
386
385
`diff -u #{ expected } #{ actual } `
387
386
end
388
387
389
- def raw_sh_failed_status
388
+ def sh_failed_status
390
389
`false`
391
390
$?
392
391
end
@@ -404,7 +403,7 @@ def terminate_process(pid, timeout = 10)
404
403
STDERR . puts "Process #{ pid } terminated"
405
404
end
406
405
407
- def raw_sh_with_timeout ( timeout , pid )
406
+ def sh_with_timeout ( timeout , pid )
408
407
if !timeout
409
408
yield
410
409
else
@@ -423,14 +422,14 @@ def raw_sh_with_timeout(timeout, pid)
423
422
end
424
423
end
425
424
426
- def raw_sh_track_subprocess ( pid )
425
+ def sh_track_subprocess ( pid )
427
426
SUBPROCESSES << pid
428
427
yield
429
428
ensure
430
429
SUBPROCESSES . delete ( pid )
431
430
end
432
431
433
- def raw_sh ( *args )
432
+ def sh ( *args )
434
433
options = args . last . is_a? ( Hash ) ? args . last : { }
435
434
continue_on_failure = options . delete :continue_on_failure
436
435
use_exec = options . delete :use_exec
@@ -459,17 +458,17 @@ def raw_sh(*args)
459
458
pid = Process . spawn ( *args )
460
459
rescue Errno ::ENOENT => no_such_executable
461
460
STDERR . puts bold no_such_executable
462
- status = raw_sh_failed_status
461
+ status = sh_failed_status
463
462
else
464
- raw_sh_track_subprocess ( pid ) do
463
+ sh_track_subprocess ( pid ) do
465
464
pipe_w . close if capture
466
465
467
- result = raw_sh_with_timeout ( timeout , pid ) do
466
+ result = sh_with_timeout ( timeout , pid ) do
468
467
out = pipe_r . read if capture
469
468
_ , status = Process . waitpid2 ( pid )
470
469
end
471
470
if result == :timeout
472
- status = raw_sh_failed_status
471
+ status = sh_failed_status
473
472
end
474
473
end
475
474
end
@@ -546,15 +545,8 @@ def replace_env_vars(string, env = ENV)
546
545
end
547
546
end
548
547
549
- def sh ( *args )
550
- chdir ( TRUFFLERUBY_DIR ) do
551
- raw_sh ( *args )
552
- end
553
- end
554
-
555
548
def app_open ( file )
556
549
cmd = darwin? ? 'open' : 'xdg-open'
557
-
558
550
sh cmd , file
559
551
end
560
552
@@ -570,6 +562,12 @@ def chdir(dir, &block)
570
562
end
571
563
end
572
564
565
+ def in_truffleruby_repo_root!
566
+ unless File . realpath ( Dir . pwd ) == TRUFFLERUBY_DIR
567
+ raise 'This command should be called at the root of the truffleruby repository'
568
+ end
569
+ end
570
+
573
571
def find_java_home
574
572
@java_home ||= begin
575
573
mx_env = File . expand_path ( '~/.mx/env' )
@@ -617,7 +615,7 @@ def mx(*args, java_home: find_java_home, **options)
617
615
mx_args . unshift '--java-home' , java_home
618
616
end
619
617
620
- raw_sh ( env , find_mx , *mx_args , **options )
618
+ sh ( env , find_mx , *mx_args , **options )
621
619
end
622
620
623
621
def mx_os
@@ -643,7 +641,7 @@ def git_clone(url, path)
643
641
# Unset $JAVA_HOME, mx sclone should not use it, and $JAVA_HOME might be set to the standalone home in graalvm tests
644
642
mx ( 'sclone' , '--kind' , 'git' , url , path , java_home : :none )
645
643
else
646
- raw_sh 'git' , 'clone' , url , path
644
+ sh 'git' , 'clone' , url , path
647
645
end
648
646
end
649
647
@@ -718,9 +716,9 @@ def github(dir = TRUFFLERUBY_DIR)
718
716
def remote_urls ( dir = TRUFFLERUBY_DIR )
719
717
@remote_urls ||= Hash . new
720
718
@remote_urls [ dir ] ||= begin
721
- out = raw_sh 'git' , '-C' , dir , 'remote' , capture : :out , no_print_cmd : true
719
+ out = sh 'git' , '-C' , dir , 'remote' , capture : :out , no_print_cmd : true
722
720
out . split . map do |remote |
723
- url = raw_sh 'git' , '-C' , dir , 'config' , '--get' , "remote.#{ remote } .url" , capture : :out , no_print_cmd : true
721
+ url = sh 'git' , '-C' , dir , 'config' , '--get' , "remote.#{ remote } .url" , capture : :out , no_print_cmd : true
724
722
[ remote , url . chomp ]
725
723
end
726
724
end
@@ -885,11 +883,12 @@ def launcher
885
883
end
886
884
887
885
def build ( *options )
886
+ in_truffleruby_repo_root!
888
887
project = options . shift
889
888
case project
890
889
when 'parser'
891
890
jay = "#{ TRUFFLERUBY_DIR } /tool/jay"
892
- raw_sh 'make' , chdir : jay
891
+ sh 'make' , chdir : jay
893
892
ENV [ 'PATH' ] = "#{ jay } :#{ ENV [ 'PATH' ] } "
894
893
sh 'bash' , 'tool/generate_parser'
895
894
yytables = 'src/main/java/org/truffleruby/parser/parser/YyTables.java'
@@ -904,6 +903,7 @@ def build(*options)
904
903
end
905
904
906
905
def clean ( *options )
906
+ in_truffleruby_repo_root!
907
907
project = options . shift
908
908
case project
909
909
when 'cexts'
@@ -929,7 +929,7 @@ def env
929
929
env_vars . each do |e |
930
930
puts format "%#{ column_size } s: %s" , e , ENV [ e ] . inspect
931
931
end
932
- shell = -> command { raw_sh ( *command . split , continue_on_failure : true ) }
932
+ shell = -> command { sh ( *command . split , continue_on_failure : true ) }
933
933
shell [ 'ruby -v' ]
934
934
shell [ 'uname -a' ]
935
935
shell [ 'cc -v' ]
@@ -1053,7 +1053,7 @@ def rebuild(*options)
1053
1053
1054
1054
vm_args , ruby_args , options = ruby_options ( options , args )
1055
1055
1056
- raw_sh env_vars , ruby_launcher , *( vm_args if truffleruby? ) , *ruby_args , options
1056
+ sh env_vars , ruby_launcher , *( vm_args if truffleruby? ) , *ruby_args , options
1057
1057
end
1058
1058
1059
1059
def ruby ( *args )
@@ -1098,7 +1098,7 @@ def cextc(cext_dir)
1098
1098
chdir ( ext_dir ) do
1099
1099
run_ruby ( env , '-rmkmf' , "#{ ext_dir } /extconf.rb" ) # -rmkmf is required for C ext tests
1100
1100
if File . exist? ( 'Makefile' )
1101
- raw_sh ( 'make' )
1101
+ sh ( 'make' )
1102
1102
FileUtils ::Verbose . cp ( "#{ name } .#{ DLEXT } " , target ) if target
1103
1103
else
1104
1104
STDERR . puts "Makefile not found in #{ ext_dir } , skipping make."
@@ -1287,6 +1287,7 @@ def test(*args)
1287
1287
end
1288
1288
1289
1289
def retag ( *args )
1290
+ in_truffleruby_repo_root!
1290
1291
require_ruby_launcher!
1291
1292
options , test_files = args . partition { |a | a . start_with? ( '-' ) }
1292
1293
@@ -1354,6 +1355,7 @@ def retag(*args)
1354
1355
end
1355
1356
1356
1357
private def run_single_cexts_test ( test_name )
1358
+ in_truffleruby_repo_root!
1357
1359
time_test ( "jt test cexts #{ test_name } " ) do
1358
1360
case test_name
1359
1361
when 'tools'
@@ -1633,16 +1635,16 @@ def gem_test_pack
1633
1635
# Unset variable set by the pre-commit hook which confuses git
1634
1636
env = { 'GIT_DIR' => nil , 'GIT_INDEX_FILE' => nil }
1635
1637
1636
- current = raw_sh ( env , 'git' , '-C' , gem_test_pack , 'rev-parse' , 'HEAD' , capture : :out , no_print_cmd : true ) . chomp
1638
+ current = sh ( env , 'git' , '-C' , gem_test_pack , 'rev-parse' , 'HEAD' , capture : :out , no_print_cmd : true ) . chomp
1637
1639
unless current == TRUFFLERUBY_GEM_TEST_PACK_VERSION
1638
1640
if ENV [ 'GEM_TEST_PACK_WIP' ] == 'true'
1639
1641
STDERR . puts 'WARNING: the gem test pack commit is different than TRUFFLERUBY_GEM_TEST_PACK_VERSION in jt.rb'
1640
1642
else
1641
- has_commit = raw_sh env , 'git' , '-C' , gem_test_pack , 'cat-file' , '-e' , TRUFFLERUBY_GEM_TEST_PACK_VERSION , continue_on_failure : true
1643
+ has_commit = sh env , 'git' , '-C' , gem_test_pack , 'cat-file' , '-e' , TRUFFLERUBY_GEM_TEST_PACK_VERSION , continue_on_failure : true
1642
1644
unless has_commit
1643
- raw_sh env , 'git' , '-C' , gem_test_pack , 'fetch' , Remotes . bitbucket ( gem_test_pack ) , continue_on_failure : true
1645
+ sh env , 'git' , '-C' , gem_test_pack , 'fetch' , Remotes . bitbucket ( gem_test_pack ) , continue_on_failure : true
1644
1646
end
1645
- raw_sh env , 'git' , '-C' , gem_test_pack , 'checkout' , '-q' , TRUFFLERUBY_GEM_TEST_PACK_VERSION
1647
+ sh env , 'git' , '-C' , gem_test_pack , 'checkout' , '-q' , TRUFFLERUBY_GEM_TEST_PACK_VERSION
1646
1648
end
1647
1649
end
1648
1650
@@ -1827,11 +1829,11 @@ def metrics(command, *args)
1827
1829
log '.' , "sampling\n "
1828
1830
1829
1831
max_rss_in_mb = if linux?
1830
- out = raw_sh ( '/usr/bin/time' , '-v' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1832
+ out = sh ( '/usr/bin/time' , '-v' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1831
1833
out =~ /Maximum resident set size \( kbytes\) : (?<max_rss_in_kb>\d +)/m
1832
1834
Integer ( $~[ :max_rss_in_kb ] ) / 1024.0
1833
1835
elsif darwin?
1834
- out = raw_sh ( '/usr/bin/time' , '-l' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1836
+ out = sh ( '/usr/bin/time' , '-l' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1835
1837
out =~ /(?<max_rss_in_bytes>\d +)\s +maximum resident set size/m
1836
1838
Integer ( $~[ :max_rss_in_bytes ] ) / 1024.0 / 1024.0
1837
1839
else
@@ -1869,7 +1871,7 @@ def metrics(command, *args)
1869
1871
1870
1872
use_json = args . delete '--json'
1871
1873
1872
- out = raw_sh ( 'perf' , 'stat' , '-e' , 'instructions' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1874
+ out = sh ( 'perf' , 'stat' , '-e' , 'instructions' , '--' , ruby_launcher , *args , capture : :both , no_print_cmd : true )
1873
1875
1874
1876
out =~ /(?<instruction_count>[\d ,]+)\s +instructions/m
1875
1877
instruction_count = $~[ :instruction_count ] . gsub ( ',' , '' )
@@ -2270,13 +2272,13 @@ def install(name, *options)
2270
2272
2271
2273
chdir ( CACHE_EXTRA_DIR ) do
2272
2274
unless File . exist? ( eclipse_tar )
2273
- raw_sh 'curl' , '-L' , eclipse_url , '-o' , eclipse_tar
2275
+ sh 'curl' , '-L' , eclipse_url , '-o' , eclipse_tar
2274
2276
end
2275
2277
unless File . exist? ( eclipse_name )
2276
2278
computed = Digest ::SHA256 . file ( eclipse_tar ) . hexdigest
2277
2279
if computed == sha256
2278
2280
Dir . mkdir eclipse_name
2279
- raw_sh 'tar' , 'xf' , eclipse_tar , '-C' , eclipse_name
2281
+ sh 'tar' , 'xf' , eclipse_tar , '-C' , eclipse_name
2280
2282
else
2281
2283
raise "Incorrect sha256 for #{ eclipse_tar } : #{ computed } instead of expected #{ sha256 } "
2282
2284
end
@@ -2905,6 +2907,7 @@ def format_specializations_check
2905
2907
end
2906
2908
2907
2909
def lint ( *args )
2910
+ in_truffleruby_repo_root!
2908
2911
fast = args . first == 'fast'
2909
2912
args . shift if fast
2910
2913
@@ -3016,7 +3019,7 @@ def docker(*args)
3016
3019
end
3017
3020
3018
3021
def visualvm
3019
- raw_sh "#{ graalvm_home } /bin/jvisualvm"
3022
+ sh "#{ graalvm_home } /bin/jvisualvm"
3020
3023
end
3021
3024
end
3022
3025
0 commit comments