Skip to content

Commit

Permalink
Merge pull request #3401 from rubygems/jeremyevans-definition-no_lock
Browse files Browse the repository at this point in the history
Add Bundler::Definition.no_lock accessor for skipping lock file creation/update
  • Loading branch information
hsbt authored and SeekingMeaning committed Aug 15, 2020
2 parents 5207d28 + bbc2128 commit 3b4e9f5
Show file tree
Hide file tree
Showing 5 changed files with 28 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
7 changes: 7 additions & 0 deletions bundler/lib/bundler/definition.rb
Expand Up @@ -7,6 +7,11 @@ module Bundler
class Definition
include GemHelpers

class << self
# Do not create or modify a lockfile (Makes #lock a noop)
attr_accessor :no_lock
end

attr_reader(
:dependencies,
:locked_deps,
Expand Down Expand Up @@ -331,6 +336,8 @@ def groups
end

def lock(file, preserve_unknown_sections = false)
return if Definition.no_lock

contents = to_lock

# Convert to \r\n if the existing lock has them
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
10 changes: 10 additions & 0 deletions bundler/spec/bundler/definition_spec.rb
Expand Up @@ -31,6 +31,16 @@
to raise_error(Bundler::TemporaryResourceError, /temporarily unavailable/)
end
end
context "when Bundler::Definition.no_lock is set to true" do
subject { Bundler::Definition.new(nil, [], Bundler::SourceList.new, []) }
before { Bundler::Definition.no_lock = true }
after { Bundler::Definition.no_lock = false }

it "does not create a lock file" do
subject.lock("Gemfile.lock")
expect(File.file?("Gemfile.lock")).to eq false
end
end
end

describe "detects changes" do
Expand Down

0 comments on commit 3b4e9f5

Please sign in to comment.