aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler
diff options
context:
space:
mode:
authorMSP-Greg <Greg.mpls@gmail.com>2020-06-16 20:31:15 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-07-15 16:05:12 +0900
commitf3ad8a00e260184be1b63231e2f99a1ef73eba60 (patch)
treea29f3d1e933db4513d9d856cda1330675ebe1950 /lib/bundler
parent48ba9b6106949f042b12a85c851b785f1e430eca (diff)
downloadruby-f3ad8a00e260184be1b63231e2f99a1ef73eba60.tar.gz
[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
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/installer.rb35
1 files changed, 23 insertions, 12 deletions
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