Skip to content

Commit

Permalink
Remove unnecessary loop
Browse files Browse the repository at this point in the history
Rubygems installs a single executable. Make that explicit.
  • Loading branch information
deivid-rodriguez committed Nov 5, 2021
1 parent 2bd3f00 commit 2839d15
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions lib/rubygems/commands/setup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,48 +257,44 @@ def install_executables(bin_dir)
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
GOTO :EOF
: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
Expand Down

0 comments on commit 2839d15

Please sign in to comment.