Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fef68d2
Root is already a Pathname
deivid-rodriguez Sep 24, 2018
1c54562
Small DRY up
deivid-rodriguez Sep 24, 2018
edfbbff
DRY up settings instantiation
deivid-rodriguez Sep 25, 2018
35f7b7b
Remove unneeded mock
deivid-rodriguez Feb 16, 2020
492507b
Settings root is already a Pathname
deivid-rodriguez Feb 16, 2020
bc20481
bundle_dir is already a Pathname
deivid-rodriguez Sep 25, 2018
8736266
Extract some common logic to a method
deivid-rodriguez Aug 3, 2021
f203480
No need for explicit modules here
deivid-rodriguez Aug 11, 2021
4fd033c
Consistent usage of `Pathname`'s
deivid-rodriguez Aug 11, 2021
c446d9d
Current working directory is already expanded
deivid-rodriguez Aug 11, 2021
fdfb34d
Simplify `default_lockfile` logic
deivid-rodriguez Aug 12, 2021
7352c00
Delay cache access in `LockfileParser`
deivid-rodriguez Aug 12, 2021
ced824c
Remove committed `.bundle/config`
deivid-rodriguez Aug 12, 2021
7cc0e73
Remove case that doesn't happen in real life
deivid-rodriguez Aug 16, 2021
d49e6a1
Use `Pathname`'s consistently
deivid-rodriguez Aug 16, 2021
16a940d
New criteria to find configuration folder
deivid-rodriguez Sep 25, 2018
59a599e
Simplify settings instantiation
deivid-rodriguez Aug 11, 2021
1236fb1
Resolve gemfile from config in the general case
deivid-rodriguez Sep 25, 2018
8ad15de
This should be a temporary setting
deivid-rodriguez Aug 12, 2021
7e5e2c4
Add a comment to clarify some hacky code
deivid-rodriguez Aug 12, 2021
9f2de1b
Remove unnecessary RUBYOPT
deivid-rodriguez Aug 13, 2021
644c405
All supported RubyGems versions have this defined
deivid-rodriguez Feb 2, 2022
23010a1
Workaround bundler issue
deivid-rodriguez Feb 4, 2022
9eca72f
Revert "Workaround bundler issue"
deivid-rodriguez Feb 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .bundle/config

This file was deleted.

8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "rake/testtask"

desc "Setup Rubygems dev environment"
task :setup do
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "install", "--gemfile=bundler/tool/bundler/dev_gems.rb"
sh({ "BUNDLE_PATH__SYSTEM" => "true" }, "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "install", "--gemfile=bundler/tool/bundler/dev_gems.rb")
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--gemfile=bundler/tool/bundler/release_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--gemfile=bundler/tool/bundler/test_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--gemfile=bundler/tool/bundler/rubocop_gems.rb"
Expand All @@ -19,7 +19,7 @@ end

desc "Update Rubygems dev environment"
task :update do
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--gemfile=bundler/tool/bundler/dev_gems.rb"
sh({ "BUNDLE_PATH__SYSTEM" => "true" }, "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--gemfile=bundler/tool/bundler/dev_gems.rb")
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--update", "--gemfile=bundler/tool/bundler/release_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--update", "--gemfile=bundler/tool/bundler/test_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "lock", "--update", "--gemfile=bundler/tool/bundler/rubocop_gems.rb"
Expand All @@ -32,7 +32,7 @@ end

desc "Update the locked bundler version in dev environment"
task :update_locked_bundler do |_, args|
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--bundler", "--gemfile=bundler/tool/bundler/dev_gems.rb"
sh({ "BUNDLE_PATH__SYSTEM" => "true" }, "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--bundler", "--gemfile=bundler/tool/bundler/dev_gems.rb")
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--bundler", "--gemfile=bundler/tool/bundler/release_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--bundler", "--gemfile=bundler/tool/bundler/test_gems.rb"
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", "--bundler", "--gemfile=bundler/tool/bundler/rubocop_gems.rb"
Expand All @@ -45,7 +45,7 @@ end

desc "Update specific development dependencies"
task :update_dev_dep do |_, args|
sh "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", *args, "--gemfile=bundler/tool/bundler/dev_gems.rb"
sh({ "BUNDLE_PATH__SYSTEM" => "true" }, "ruby", "-I", "lib", "bundler/spec/support/bundle.rb", "update", *args, "--gemfile=bundler/tool/bundler/dev_gems.rb")
end

desc "Setup git hooks"
Expand Down
59 changes: 36 additions & 23 deletions bundler/lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,11 @@ def ruby_scope
def user_home
@user_home ||= begin
home = Bundler.rubygems.user_home
bundle_home = home ? File.join(home, ".bundle") : nil
bundle_home = home.join(".bundle")

warning = if home.nil?
"Your home directory is not set."
elsif !File.directory?(home)
warning = if !home.directory?
"`#{home}` is not a directory."
elsif !File.writable?(home) && (!File.directory?(bundle_home) || !File.writable?(bundle_home))
elsif !home.writable? && (!bundle_home.directory? || !bundle_home.writable?)
"`#{home}` is not writable."
end

Expand All @@ -243,7 +241,7 @@ def user_home
Bundler.ui.warn "Bundler will use `#{user_home}' as your home directory temporarily.\n"
user_home
else
Pathname.new(home)
home
end
end
end
Expand Down Expand Up @@ -283,27 +281,19 @@ def specs_path
end

def root
@root ||= begin
SharedHelpers.root
rescue GemfileNotFound
bundle_dir = default_bundle_dir
raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
Pathname.new(File.expand_path("..", bundle_dir))
end
@root ||= resolve_root
end

def app_config_path
if app_config = ENV["BUNDLE_APP_CONFIG"]
app_config_pathname = Pathname.new(app_config)

if app_config_pathname.absolute?
app_config_pathname
else
app_config_pathname.expand_path(root)
return app_config_pathname
end
else
root.join(".bundle")
end

app_config_root.join(app_config || ".bundle")
end

def app_cache(custom_path = nil)
Expand All @@ -330,8 +320,6 @@ def rm_rf(path)

def settings
@settings ||= Settings.new(app_config_path)
rescue GemfileNotFound
@settings = Settings.new(Pathname.new(".bundle").expand_path)
end

# @return [Hash] Environment present before Bundler was activated
Expand Down Expand Up @@ -456,8 +444,14 @@ def default_lockfile
SharedHelpers.default_lockfile
end

def default_bundle_dir
SharedHelpers.default_bundle_dir
def default_bundle_dir(base = Pathname.pwd)
bundle_dir = SharedHelpers.find_directory(".bundle", :base => base)
return nil unless bundle_dir

global_bundle_dir = Bundler.rubygems.user_home.join(".bundle")
return nil if bundle_dir == global_bundle_dir

bundle_dir
end

def system_bindir
Expand Down Expand Up @@ -611,7 +605,8 @@ def reset!
reset_rubygems!
end

def reset_settings_and_root!
def reset_settings_and_root!(base)
@app_config_root = resolve_config_root(base)
@settings = nil
@root = nil
end
Expand All @@ -625,6 +620,7 @@ def reset_paths!
@definition = nil
@load = nil
@locked_gems = nil
@app_config_root = nil
@root = nil
@settings = nil
@setup = nil
Expand Down Expand Up @@ -699,5 +695,22 @@ def with_env(env)
ensure
ENV.replace(backup)
end

def app_config_root
@app_config_root ||= resolve_config_root
end

def resolve_config_root(base = Pathname.pwd)
bundle_dir = default_bundle_dir(base) || SharedHelpers.find_gemfile_if_empty(ENV["BUNDLE_GEMFILE"])

bundle_dir ? bundle_dir.parent : base
end

def resolve_root
bundle_dir = SharedHelpers.find_gemfile || default_bundle_dir
raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir

bundle_dir.parent
end
end
end
16 changes: 13 additions & 3 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,20 @@ def self.aliases_for(command_name)
def initialize(*args)
super

custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
# At this point, settings have been already resolved, unfortunately,
# because some CLI help messages, flag aliases or even whole commands need
# to be defined according to some settings being activated or not. So once
# we know the `--gemfile` has been passed, we need to force a reload of
# everything. This logic seems buggy, since the settings we have used
# before this point might not be correct, but so far it has worked fine.
# The ideal solution would be to add some features to thor so that stuff
# can be defined via procs and lazily loaded, and thus we can be sure we
# haven't yet loaded settings at all at this point.
custom_gemfile = options[:gemfile]
if custom_gemfile && !custom_gemfile.empty?
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", File.expand_path(custom_gemfile)
Bundler.reset_settings_and_root!
expanded_custom_gemfile = Pathname.new(custom_gemfile).expand_path
Bundler.reset_settings_and_root!(expanded_custom_gemfile.parent)
Bundler.settings.temporary(:gemfile => expanded_custom_gemfile)
end

Bundler.self_manager.restart_with_locked_bundler_if_needed
Expand Down
4 changes: 1 addition & 3 deletions bundler/lib/bundler/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ def connection
con.cert_store = bundler_cert_store
end

ssl_client_cert = Bundler.settings[:ssl_client_cert] ||
(Gem.configuration.ssl_client_cert if
Gem.configuration.respond_to?(:ssl_client_cert))
ssl_client_cert = Bundler.settings[:ssl_client_cert] || Gem.configuration.ssl_client_cert
if ssl_client_cert
pem = File.read(ssl_client_cert)
con.cert = OpenSSL::X509::Certificate.new(pem)
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def gemfile(install = false, options = {}, &gemfile)
bundler_module = class << Bundler; self; end
bundler_module.send(:remove_method, :root)
def Bundler.root
Bundler::SharedHelpers.pwd.expand_path
Bundler::SharedHelpers.pwd
end
old_gemfile = ENV["BUNDLE_GEMFILE"]
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def gem_bindir
end

def user_home
Gem.user_home
Pathname.new(Gem.user_home)
end

def gem_path
Expand Down
10 changes: 4 additions & 6 deletions bundler/lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Settings
"BUNDLE_TIMEOUT" => 10,
}.freeze

def initialize(root = nil)
def initialize(root)
@root = root
@local_config = load_config(local_config_file)
@env_config = ENV.to_h.select {|key, _value| key =~ /\ABUNDLE_.+/ }
Expand Down Expand Up @@ -116,8 +116,6 @@ def set_command_option_if_given(key, value)
end

def set_local(key, value)
local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")

set_key(key, value, @local_config, local_config_file)
end

Expand Down Expand Up @@ -441,13 +439,13 @@ def global_config_file
Pathname.new(ENV["BUNDLE_USER_CONFIG"])
elsif ENV["BUNDLE_USER_HOME"] && !ENV["BUNDLE_USER_HOME"].empty?
Pathname.new(ENV["BUNDLE_USER_HOME"]).join("config")
elsif Bundler.rubygems.user_home && !Bundler.rubygems.user_home.empty?
Pathname.new(Bundler.rubygems.user_home).join(".bundle/config")
else
Bundler.rubygems.user_home.join(".bundle/config")
end
end

def local_config_file
Pathname.new(@root).join("config") if @root
@root.join("config")
end

def load_config(config_file)
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/settings/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.validate!(key, value, settings)
root = begin
Bundler.root
rescue GemfileNotFound
Pathname.pwd.expand_path
Pathname.pwd
end

path = begin
Expand Down
Loading