diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-09-08 12:44:09 -0700 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-09-08 12:44:09 -0700 |
commit | 12d5fb573384fde3c935f0c5c4f9217a5463004c (patch) | |
tree | 5642ca87f7ad30d2ea8bf99acb29340347da83aa | |
parent | 7fb9fa70915dc687f5e0f5c65f26538dd77760da (diff) | |
download | bundler-12d5fb573384fde3c935f0c5c4f9217a5463004c.tar.gz |
Expand path relative to pwd in the settings validator
-rw-r--r-- | lib/bundler/cli/check.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/common.rb | 20 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 12 | ||||
-rw-r--r-- | lib/bundler/cli/package.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings/validator.rb | 23 | ||||
-rw-r--r-- | spec/install/gems/standalone_spec.rb | 46 | ||||
-rw-r--r-- | spec/install/path_spec.rb | 16 |
7 files changed, 71 insertions, 50 deletions
diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 607a5351d9..e572787dc4 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -9,7 +9,7 @@ module Bundler end def run - CLI::Common.set_path options[:path], :if_given + Bundler.settings.set_command_option_if_given :path, options[:path] begin definition = Bundler.definition diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index bfd653e821..9d40ee9dfd 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -98,25 +98,5 @@ module Bundler clean &&= !Bundler.use_system_gems? clean end - - def self.set_path(path, if_given = false) - if path.nil? - Bundler.settings.set_command_option :path, nil unless if_given - return - end - - path = Pathname.new(path) - if path.relative? && Bundler.feature_flag.path_relative_to_cwd? - path = path.expand_path - root = Bundler.root - path = begin - path.relative_path_from(root) - rescue ArgumentError - path - end - end - - Bundler.settings.set_command_option :path, path.to_s - end end end diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 10f3a98002..d878081df7 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -167,10 +167,14 @@ module Bundler end def normalize_settings - CLI::Common.set_path nil if options[:system] - CLI::Common.set_path "vendor/bundle" if options[:deployment] - CLI::Common.set_path options["path"], :if_given - CLI::Common.set_path "bundle" if options["standalone"] && Bundler.settings[:path].nil? + Bundler.settings.set_command_option :path, nil if options[:system] + Bundler.settings.temporary(:path_relative_to_cwd => false) do + Bundler.settings.set_command_option :path, "vendor/bundle" if options[:deployment] + end + Bundler.settings.set_command_option_if_given :path, options[:path] + Bundler.settings.temporary(:path_relative_to_cwd => false) do + Bundler.settings.set_command_option :path, "bundle" if options["standalone"] && Bundler.settings[:path].nil? + end bin_option = options["binstubs"] bin_option = nil if bin_option && bin_option.empty? diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb index 8aef0265e3..2dcd0e1e29 100644 --- a/lib/bundler/cli/package.rb +++ b/lib/bundler/cli/package.rb @@ -10,7 +10,7 @@ module Bundler def run Bundler.ui.level = "error" if options[:quiet] - CLI::Common.set_path options[:path], :if_given + Bundler.settings.set_command_option_if_given :path, options[:path] Bundler.settings.set_command_option_if_given :cache_all_platforms, options["all-platforms"] Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] diff --git a/lib/bundler/settings/validator.rb b/lib/bundler/settings/validator.rb index 9aa1627fb2..0a57ea7f03 100644 --- a/lib/bundler/settings/validator.rb +++ b/lib/bundler/settings/validator.rb @@ -74,6 +74,29 @@ module Bundler fail!(key, value, "`#{other_key}` is current set to #{other_setting.inspect}", "the `#{conflicting.join("`, `")}` groups conflict") end end + + rule %w[path], "relative paths are expanded relative to the current working directory" do |key, value, settings| + next if value.nil? + + path = Pathname.new(value) + next if !path.relative? || !Bundler.feature_flag.path_relative_to_cwd? + + path = path.expand_path + + root = begin + Bundler.root + rescue GemfileNotFound + Pathname.pwd.expand_path + end + + path = begin + path.relative_path_from(root) + rescue ArgumentError + path + end + + set(settings, key, path.to_s) + end end end end diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index f0aa96290d..b149d9d00b 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -54,7 +54,7 @@ RSpec.shared_examples "bundle install --standalone" do source "file://#{gem_repo1}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) end let(:expected_gems) do @@ -69,15 +69,14 @@ RSpec.shared_examples "bundle install --standalone" do describe "with gems with native extension" do before do - install_gemfile <<-G, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) source "file://#{gem_repo1}" gem "very_simple_binary" G end it "generates a bundle/bundler/setup.rb with the proper paths", :rubygems => "2.4" do - expected_path = (Bundler.feature_flag.path_relative_to_cwd? ? Pathname.pwd : bundled_app). - join("bundle/bundler/setup.rb") + expected_path = bundled_app("bundle/bundler/setup.rb") extension_line = File.read(expected_path).each_line.find {|line| line.include? "/extensions/" }.strip expect(extension_line).to start_with '$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/' expect(extension_line).to end_with '/very_simple_binary-1.0"' @@ -103,7 +102,7 @@ RSpec.shared_examples "bundle install --standalone" do end G end - install_gemfile <<-G, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -123,7 +122,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) end let(:expected_gems) do @@ -150,7 +149,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rack-test" end G - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) end let(:expected_gems) do @@ -163,7 +162,7 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "allows creating a standalone file with limited groups" do - bundle! "install", forgotten_command_line_options(:path => "bundle").merge(:standalone => "default") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default") Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -181,7 +180,7 @@ RSpec.shared_examples "bundle install --standalone" do end it "allows --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:path => "bundle", :without => "test").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true) Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -198,7 +197,7 @@ RSpec.shared_examples "bundle install --standalone" do expect(last_command.stderr).to eq("ZOMG LOAD ERROR") end - it "allows --path to change the location of the standalone bundle" do + it "allows --path to change the location of the standalone bundle", :bundler => "< 2" do bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) Dir.chdir(bundled_app) do @@ -214,9 +213,26 @@ RSpec.shared_examples "bundle install --standalone" do expect(last_command.stdout).to eq("2.3.2") end + it "allows --path to change the location of the standalone bundle", :bundler => "2" do + bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) + path = File.expand_path("path/to/bundle") + + Dir.chdir(bundled_app) do + ruby <<-RUBY, :no_lib => true + $:.unshift File.expand_path(#{path.dump}) + require "bundler/setup" + + require "actionpack" + puts ACTIONPACK + RUBY + end + + expect(last_command.stdout).to eq("2.3.2") + end + it "allows remembered --without to limit the groups used in a standalone" do bundle! :install, forgotten_command_line_options(:without => "test") - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) Dir.chdir(bundled_app) do load_error_ruby <<-RUBY, "spec", :no_lib => true @@ -243,7 +259,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{source_uri}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true, :artifice => "endpoint") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint") end let(:expected_gems) do @@ -263,7 +279,7 @@ RSpec.shared_examples "bundle install --standalone" do source "file://#{gem_repo1}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => "bundle").merge(:standalone => true, :binstubs => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true) end let(:expected_gems) do @@ -314,9 +330,7 @@ end RSpec.describe "bundle install --standalone run in a subdirectory" do before do - subdir = bundled_app("bob") - FileUtils.mkdir_p(subdir) - Dir.chdir(subdir) + Dir.chdir(bundled_app("bob").tap(&:mkpath)) end include_examples("bundle install --standalone") diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb index 196cbb4ab7..95fa0fbf50 100644 --- a/spec/install/path_spec.rb +++ b/spec/install/path_spec.rb @@ -24,7 +24,7 @@ RSpec.describe "bundle install" do Dir.chdir(dir) do bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") - expect(out).to include("installed into `../vendor/bundle`") + expect(out).to include("installed into `./vendor/bundle`") end dir.rmtree @@ -65,18 +65,18 @@ RSpec.describe "bundle install" do it "installs the standalone bundle relative to the cwd" do Dir.chdir(bundled_app.parent) do bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true - expect(out).to include("installed into `./bundle`") - expect(bundled_app("../bundle")).to be_directory - expect(bundled_app("../bundle/ruby")).to be_directory + expect(out).to include("installed into `./bundled_app/bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory end - bundle! "config --delete path" + bundle! "config unset path" Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true - expect(out).to include("installed into `./bundle`") - expect(bundled_app("subdir/bundle")).to be_directory - expect(bundled_app("subdir/bundle/ruby")).to be_directory + expect(out).to include("installed into `../bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory end end end |