From ab746d6e57c046a8bbc36f9c7cff317d30a008d2 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 97b6ea83b..4a38c5133 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -239,6 +239,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 4e8f7ddac34a2fb65380c9e5465368515b6c0bb8 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 537d7e3a2..3d92dbf88 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -29,7 +29,7 @@ class TaskManager include Rake::TaskManager end - RUBY = File.realpath(ENV["RUBY"] || Gem.ruby) + RUBY = (ENV["RUBY"] || Gem.ruby) def setup ARGV.clear @@ -122,5 +122,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 4a38c5133..d60f71262 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -181,7 +181,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 @@ -240,7 +240,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 @@ -256,7 +256,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 @@ -401,7 +401,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