Skip to content

Commit 55f2917

Browse files
soda92matzbot
authored andcommitted
[rubygems/rubygems] allow bat files to be created alongside with script files on Windows
ruby/rubygems@ed5b847f03
1 parent e18fb12 commit 55f2917

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spec/bundler/support/helpers.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,20 @@ def global_config(config = nil)
235235
end
236236

237237
def create_file(path, contents = "")
238+
contents = strip_whitespace(contents)
238239
path = Pathname.new(path).expand_path(bundled_app) unless path.is_a?(Pathname)
239240
path.dirname.mkpath
240-
File.open(path.to_s, "w") do |f|
241-
f.puts strip_whitespace(contents)
241+
path.write(contents)
242+
243+
# if the file is a script, create respective bat file on Windows
244+
if contents.start_with?("#!")
245+
path.chmod(0o755)
246+
if Gem.win_platform?
247+
path.sub_ext(".bat").write <<~SCRIPT
248+
@ECHO OFF
249+
@"ruby.exe" "%~dpn0" %*
250+
SCRIPT
251+
end
242252
end
243253
end
244254

0 commit comments

Comments
 (0)