Skip to content

Commit

Permalink
Add option to install binstubs for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekingMeaning committed Aug 15, 2020
1 parent 53a1673 commit 8b1f655
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bundler/lib/bundler/cli.rb
Expand Up @@ -380,6 +380,8 @@ def info(gem_name)
"Make binstubs that can work without the Bundler runtime"
method_option "all", :type => :boolean, :banner =>
"Install binstubs for all gems"
method_option "all-platforms", :type => :boolean, :default => false, :banner =>
"Install binstubs for all platforms"
def binstubs(*gems)
require_relative "cli/binstubs"
Binstubs.new(options, gems).run
Expand Down
8 changes: 6 additions & 2 deletions bundler/lib/bundler/cli/binstubs.rb
Expand Up @@ -16,7 +16,11 @@ def run
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
installer = Installer.new(Bundler.root, Bundler.definition)

installer_opts = { :force => options[:force], :binstubs_cmd => true }
installer_opts = {
:force => options[:force],
:binstubs_cmd => true,
:all_platforms => options["all-platforms"],
}

if options[:all]
raise InvalidOption, "Cannot specify --all with specific gems" unless gems.empty?
Expand All @@ -38,7 +42,7 @@ def run
if options[:standalone]
next Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") if gem_name == "bundler"
Bundler.settings.temporary(:path => (Bundler.settings[:path] || Bundler.root)) do
installer.generate_standalone_bundler_executable_stubs(spec)
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts)
end
else
installer.generate_bundler_executable_stubs(spec, installer_opts)
Expand Down
6 changes: 3 additions & 3 deletions bundler/lib/bundler/installer.rb
Expand Up @@ -143,7 +143,7 @@ def generate_bundler_executable_stubs(spec, options = {})
end

File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask)
if Bundler::WINDOWS
if Bundler::WINDOWS || options[:all_platforms]
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
File.write("#{binstub_path}.cmd", prefix + content, :mode => mode)
end
Expand All @@ -164,7 +164,7 @@ def generate_bundler_executable_stubs(spec, options = {})
end
end

def generate_standalone_bundler_executable_stubs(spec)
def generate_standalone_bundler_executable_stubs(spec, options = {})
# double-assignment to avoid warnings about variables that will be used by ERB
bin_path = Bundler.bin_path
unless path = Bundler.settings[:path]
Expand All @@ -189,7 +189,7 @@ def generate_standalone_bundler_executable_stubs(spec)
end

File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755)
if Bundler::WINDOWS
if Bundler::WINDOWS || options[:all_platforms]
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
File.write("#{bin_path}/#{executable}.cmd", prefix + content, :mode => mode)
end
Expand Down

0 comments on commit 8b1f655

Please sign in to comment.