From cf2e6ffc4a45e92565c3bbdd80ec20a17a4041c3 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 29 Mar 2024 13:57:01 +0900 Subject: [PATCH 1/2] Show `chdir` option as a command Currently, it is not possible to tell from the output message whether that option is specified for `sh`. --- lib/rake/file_utils.rb | 11 ++++++++--- test/test_rake_file_utils.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/rake/file_utils.rb b/lib/rake/file_utils.rb index 1510d95c3..c52091715 100644 --- a/lib/rake/file_utils.rb +++ b/lib/rake/file_utils.rb @@ -48,7 +48,7 @@ def sh(*cmd, &block) verbose = options.delete :verbose noop = options.delete(:noop) || Rake::FileUtilsExt.nowrite_flag - Rake.rake_output_message sh_show_command cmd if verbose + Rake.rake_output_message sh_show_command(cmd, options) if verbose unless noop res = (Hash === cmd.last) ? system(*cmd) : system(*cmd, options) @@ -68,7 +68,7 @@ def create_shell_runner(cmd) # :nodoc: end private :create_shell_runner - def sh_show_command(cmd) # :nodoc: + def sh_show_command(cmd, options = nil) # :nodoc: cmd = cmd.dup if Hash === cmd.first @@ -77,7 +77,12 @@ def sh_show_command(cmd) # :nodoc: cmd[0] = env end - cmd.join " " + cmd = cmd.join " " + if options and chdir = options[:chdir] + "(cd #{chdir} && #{cmd})" + else + cmd + end end private :sh_show_command diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb index 3af5e96f1..df831944c 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -240,6 +240,20 @@ def test_sh_noop assert true, "should not fail" end + def test_sh_chdir + omit "JRuby does not support spawn options" if jruby? + + Dir.mkdir "chdir_test" + out, err = capture_output do + verbose(true) { + sh "echo ok", chdir: "chdir_test", verbose: true, noop: true + } + end + + assert_equal "(cd chdir_test && echo ok)\n", err + assert_empty out + end + def test_sh_bad_option # Skip on JRuby because option checking is performed by spawn via system # now. From 376c766ed08ae6c4b33024c7a52943fac414f253 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 29 Mar 2024 14:49:24 +0900 Subject: [PATCH 2/2] `system` with keyword argument works in recent JRuby --- test/helper.rb | 6 +++++- test/test_rake_file_utils.rb | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 7ef6e6958..619bf42c7 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -27,7 +27,7 @@ class TaskManager include Rake::TaskManager end - RUBY = File.realpath(ENV["RUBY"] || Gem.ruby) + RUBY = (ENV["RUBY"] || Gem.ruby) def setup ARGV.clear @@ -124,5 +124,9 @@ def jruby9? jruby? && (JRUBY_VERSION >= "9.0.0.0") end + def jruby90? + jruby? && JRUBY_VERSION.start_with?("9.0.") + end + include RakefileDefinitions end diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb index df831944c..36500be8b 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -182,7 +182,7 @@ def test_sh_with_multiple_arguments end def test_sh_with_spawn_options - omit "JRuby does not support spawn options" if jruby? + omit "JRuby does not support spawn options" if jruby90? echocommand @@ -241,7 +241,7 @@ def test_sh_noop end def test_sh_chdir - omit "JRuby does not support spawn options" if jruby? + omit "JRuby does not support spawn options" if jruby90? Dir.mkdir "chdir_test" out, err = capture_output do @@ -257,7 +257,7 @@ def test_sh_chdir def test_sh_bad_option # Skip on JRuby because option checking is performed by spawn via system # now. - omit "JRuby does not support spawn options" if jruby? + omit "JRuby does not support spawn options" if jruby90? shellcommand @@ -402,7 +402,7 @@ def assert_echoes_fully end def test_ruby_with_multiple_arguments - omit if jruby9? # https://github.com/jruby/jruby/issues/3653 + omit if jruby90? # https://github.com/jruby/jruby/issues/3653 check_no_expansion