Skip to content

Commit

Permalink
Merge pull request #3886 from SeekingMeaning/all-platform-binstubs
Browse files Browse the repository at this point in the history
Add `--all-platforms` flag to `bundle binstubs` to generate binstubs for all platforms
  • Loading branch information
deivid-rodriguez committed Nov 12, 2020
2 parents 824f272 + 7d9725f commit ba09c54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bundler/lib/bundler/cli.rb
Expand Up @@ -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
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 @@ -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
Expand Down
20 changes: 20 additions & 0 deletions bundler/spec/commands/binstubs_spec.rb
Expand Up @@ -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)}"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ba09c54

Please sign in to comment.