From f3ad8a00e260184be1b63231e2f99a1ef73eba60 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Tue, 16 Jun 2020 20:31:15 -0500 Subject: [rubygems/rubygems] bundler/lib/bundler/installer.rb - fix Windows 'executable_stubs' Windows normal shell requires binstubs with *.cmd extensions https://github.com/rubygems/rubygems/commit/b46326eb1f --- lib/bundler/installer.rb | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 44ef396871..8be4bb1189 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -135,12 +135,17 @@ module Bundler next end - File.open(binstub_path, "w", 0o777 & ~File.umask) do |f| - if RUBY_VERSION >= "2.6" - f.puts ERB.new(template, :trim_mode => "-").result(binding) - else - f.puts ERB.new(template, nil, "-").result(binding) - end + mode = Bundler::WINDOWS ? "wb:UTF-8" : "w" + content = if RUBY_VERSION >= "2.6" + ERB.new(template, :trim_mode => "-").result(binding) + else + ERB.new(template, nil, "-").result(binding) + end + + File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask) + if Bundler::WINDOWS + prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" + File.write("#{binstub_path}.cmd", prefix + content, :mode => mode) end end @@ -175,12 +180,18 @@ module Bundler next if executable == "bundle" executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path) executable_path = executable_path - File.open "#{bin_path}/#{executable}", "w", 0o755 do |f| - if RUBY_VERSION >= "2.6" - f.puts ERB.new(template, :trim_mode => "-").result(binding) - else - f.puts ERB.new(template, nil, "-").result(binding) - end + + mode = Bundler::WINDOWS ? "wb:UTF-8" : "w" + content = if RUBY_VERSION >= "2.6" + ERB.new(template, :trim_mode => "-").result(binding) + else + ERB.new(template, nil, "-").result(binding) + end + + File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755) + if Bundler::WINDOWS + prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" + File.write("#{bin_path}/#{executable}.cmd", prefix + content, :mode => mode) end end end -- cgit v1.2.3