ruby-changes:69604
From: David <ko1@a...>
Date: Fri, 5 Nov 2021 23:21:09 +0900 (JST)
Subject: [ruby-changes:69604] 5b941ec90d (master): [rubygems/rubygems] Remove unnecessary loop
https://git.ruby-lang.org/ruby.git/commit/?id=5b941ec90d From 5b941ec90dd76ddb78a3c9e5179f3eee801b4036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Thu, 4 Nov 2021 20:31:06 +0100 Subject: [rubygems/rubygems] Remove unnecessary loop Rubygems installs a single executable. Make that explicit. https://github.com/rubygems/rubygems/commit/2839d15521 --- lib/rubygems/commands/setup_command.rb | 50 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index edc4008cb82..dd4771b7b95 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -257,35 +257,32 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L257 say "Installing #{tool} executable" if @verbose Dir.chdir path do - bin_files = Dir['*'] + bin_file = "gem" - bin_files -= %w[update_rubygems] + dest_file = target_bin_path(bin_dir, bin_file) + bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" - bin_files.each do |bin_file| - dest_file = target_bin_path(bin_dir, bin_file) - bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" + begin + bin = File.readlines bin_file + bin[0] = shebang - begin - bin = File.readlines bin_file - bin[0] = shebang - - File.open bin_tmp_file, 'w' do |fp| - fp.puts bin.join - end - - install bin_tmp_file, dest_file, :mode => prog_mode - bin_file_names << dest_file - ensure - rm bin_tmp_file + File.open bin_tmp_file, 'w' do |fp| + fp.puts bin.join end - next unless Gem.win_platform? + install bin_tmp_file, dest_file, :mode => prog_mode + bin_file_names << dest_file + ensure + rm bin_tmp_file + end + + next unless Gem.win_platform? - begin - bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat" + begin + bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat" - File.open bin_cmd_file, 'w' do |file| - file.puts <<-TEXT + File.open bin_cmd_file, 'w' do |file| + file.puts <<-TEXT @ECHO OFF IF NOT "%~f0" == "~f0" GOTO :WinNT @"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9 @@ -293,12 +290,11 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L290 :WinNT @"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %* TEXT - end - - install bin_cmd_file, "#{dest_file}.bat", :mode => prog_mode - ensure - rm bin_cmd_file end + + install bin_cmd_file, "#{dest_file}.bat", :mode => prog_mode + ensure + rm bin_cmd_file end end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/