From abad8d1e7b3655e2e875e5d221d1561957e3a79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 12 Nov 2020 18:24:19 +0100 Subject: [PATCH] Merge pull request #3886 from SeekingMeaning/all-platform-binstubs Add `--all-platforms` flag to `bundle binstubs` to generate binstubs for all platforms (cherry picked from commit ba09c54ae588468b49b8c5511781c18ff4ef8b06) --- bundler/lib/bundler/cli.rb | 2 ++ bundler/lib/bundler/cli/binstubs.rb | 8 ++++++-- bundler/lib/bundler/installer.rb | 6 +++--- bundler/spec/commands/binstubs_spec.rb | 20 ++++++++++++++++++++ 4 files changed, 31 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 diff --git a/bundler/spec/commands/binstubs_spec.rb b/bundler/spec/commands/binstubs_spec.rb index e0296b2002a6..3b177b32ea7b 100644 --- a/bundler/spec/commands/binstubs_spec.rb +++ b/bundler/spec/commands/binstubs_spec.rb @@ -51,6 +51,18 @@ expect(bundled_app("bin/rake")).to exist end + it "allows installing binstubs for all platforms" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + bundle "binstubs rack --all-platforms" + + expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/rackup.cmd")).to exist + end + it "displays an error when used without any gem" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -356,6 +368,14 @@ expect(bundled_app("foo/rackup")).to exist end end + + context "when specified --all-platforms option" do + it "generates standalone binstubs for all platforms" do + bundle "binstubs rack --standalone --all-platforms" + expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/rackup.cmd")).to exist + end + end end context "when the bin already exists" do