Skip to content

Commit

Permalink
Prioritize path.system over path when it makes sense
Browse files Browse the repository at this point in the history
If `path.system` is configured locally, and `path` is configured
globally, gems should be installed to `path.system`.
  • Loading branch information
deivid-rodriguez committed Sep 7, 2020
1 parent 1bfc7c0 commit babdec6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 15 additions & 7 deletions bundler/lib/bundler/settings.rb
Expand Up @@ -177,6 +177,16 @@ def locations(key)
locations
end

def first_location_for(key)
key = key_for(key)

return :temporary if @temporary.key?(key)
return :local if @local_config.key?(key)
return :env if ENV[key]
return :global if @global_config.key?(key)
return :default if DEFAULT_CONFIG.key?(key)
end

def pretty_values_for(exposed_key)
key = key_for(exposed_key)

Expand Down Expand Up @@ -204,12 +214,6 @@ def pretty_values_for(exposed_key)

# for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems
def path
key = key_for(:path)
path = ENV[key] || @global_config[key]
if path && !@temporary.key?(key) && !@local_config.key?(key)
return Path.new(path, false, false)
end

system_path = self["path.system"] || (self[:disable_shared_gems] == false)
Path.new(self[:path], system_path, Bundler.feature_flag.default_install_uses_path?)
end
Expand Down Expand Up @@ -249,7 +253,11 @@ def base_path_relative_to_pwd
end

def validate!
return unless explicit_path && system_path
first_path_location = Bundler.settings.first_location_for(:path)
return if first_path_location.nil?
first_system_path_location = Bundler.settings.first_location_for("path.system")
return if first_system_path_location.nil?
return unless first_path_location == first_system_path_location
path = Bundler.settings.pretty_values_for(:path)
path.unshift(nil, "path:") unless path.empty?
system_path = Bundler.settings.pretty_values_for("path.system")
Expand Down
8 changes: 8 additions & 0 deletions bundler/spec/install/path_spec.rb
Expand Up @@ -19,6 +19,14 @@
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "uses system gems with `path.system` configured with more priority than `path`" do
bundle "config --local path.system true"
bundle "config --global path vendor/bundle"
bundle :install
run "require 'rack'", :raise_on_error => false
expect(out).to include("FAIL")
end

it "handles paths with regex characters in them" do
dir = bundled_app("bun++dle")
dir.mkpath
Expand Down

0 comments on commit babdec6

Please sign in to comment.