aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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