From 03c21c49bc13852ad9582bc3fe8e75e099ccd434 Mon Sep 17 00:00:00 2001 From: Seeker Date: Wed, 4 Nov 2020 07:27:56 -0800 Subject: [PATCH] Add option to install binstubs for all platforms --- bundler/lib/bundler/cli.rb | 2 ++ bundler/lib/bundler/cli/binstubs.rb | 8 ++++++-- bundler/lib/bundler/installer.rb | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bundler/lib/bundler/cli.rb b/bundler/lib/bundler/cli.rb index 4f5f372a4a98..c0e3802bc9aa 100644 --- a/bundler/lib/bundler/cli.rb +++ b/bundler/lib/bundler/cli.rb @@ -381,6 +381,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 diff --git a/bundler/lib/bundler/cli/binstubs.rb b/bundler/lib/bundler/cli/binstubs.rb index 266396eedc67..639c01ff394b 100644 --- a/bundler/lib/bundler/cli/binstubs.rb +++ b/bundler/lib/bundler/cli/binstubs.rb @@ -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? @@ -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) diff --git a/bundler/lib/bundler/installer.rb b/bundler/lib/bundler/installer.rb index 023c85bcdc8e..048b0786a7ff 100644 --- a/bundler/lib/bundler/installer.rb +++ b/bundler/lib/bundler/installer.rb @@ -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 @@ -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] @@ -190,7 +190,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