diff options
-rw-r--r-- | Rakefile | 12 | ||||
-rw-r--r-- | lib/bundler/cli/package.rb | 11 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 7 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 18 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/Gemfile.tt | 8 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/newgem.gemspec.tt | 9 | ||||
-rw-r--r-- | spec/bundler/definition_spec.rb | 28 | ||||
-rw-r--r-- | spec/bundler/plugin/installer_spec.rb | 8 | ||||
-rw-r--r-- | spec/bundler/shared_helpers_spec.rb | 1 | ||||
-rw-r--r-- | spec/bundler/source/git/git_proxy_spec.rb | 10 | ||||
-rw-r--r-- | spec/commands/clean_spec.rb | 4 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 10 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 5 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 27 | ||||
-rw-r--r-- | spec/commands/package_spec.rb | 29 | ||||
-rw-r--r-- | spec/install/gemfile/git_spec.rb | 6 | ||||
-rw-r--r-- | spec/runtime/inline_spec.rb | 13 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 |
20 files changed, 145 insertions, 68 deletions
@@ -3,12 +3,6 @@ $:.unshift File.expand_path("../lib", __FILE__) require "benchmark" -RUBYGEMS_REPO = if `git -C "#{File.expand_path("..")}" remote --verbose 2> #{IO::NULL}` =~ /rubygems/i - File.expand_path("..") -else - File.expand_path("tmp/rubygems") -end - def development_dependencies @development_dependencies ||= Gem::Specification.load("bundler.gemspec").development_dependencies end @@ -139,7 +133,11 @@ namespace :spec do end task "setup_co" do - ENV["RGV"] = RUBYGEMS_REPO + ENV["RGV"] = if `git -C "#{File.expand_path("..")}" remote --verbose 2> #{IO::NULL}` =~ /rubygems/i + File.expand_path("..") + else + File.expand_path("tmp/rubygems") + end end task "co" => "setup_co" diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb index 120a3fdcf3..3fa87ff265 100644 --- a/lib/bundler/cli/package.rb +++ b/lib/bundler/cli/package.rb @@ -11,7 +11,6 @@ module Bundler def run Bundler.ui.level = "error" if options[:quiet] 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"] setup_cache_all @@ -19,7 +18,10 @@ module Bundler # TODO: move cache contents here now that all bundles are locked custom_path = Bundler.settings[:path] if options[:path] - Bundler.load.cache(custom_path) + + Bundler.settings.temporary(:cache_all_platforms => options["all-platforms"]) do + Bundler.load.cache(custom_path) + end end private @@ -27,10 +29,7 @@ module Bundler def install require_relative "install" options = self.options.dup - if Bundler.settings[:cache_all_platforms] - options["local"] = false - options["update"] = true - end + options["local"] = false if Bundler.settings[:cache_all_platforms] Bundler::CLI::Install.new(options).run end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 4664eec24d..98fa2c1ef7 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -167,7 +167,7 @@ module Bundler def specs @specs ||= begin begin - specs = resolve.materialize(Bundler.settings[:cache_all_platforms] ? dependencies : requested_dependencies) + specs = resolve.materialize(requested_dependencies) rescue GemNotFound => e # Handle yanked gem gem_name, gem_version = extract_gem_info(e) locked_gem = @locked_specs[gem_name].last @@ -812,9 +812,8 @@ module Bundler end resolve = SpecSet.new(converged) - expanded_deps = expand_dependencies(deps, true) - @locked_specs_incomplete_for_platform = !resolve.for(expanded_deps, @unlock[:gems], true, true) - resolve = resolve.for(expanded_deps, @unlock[:gems], false, false, false) + @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(deps), @unlock[:gems], true, true) + resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems], false, false, false) diff = nil # Now, we unlock any sources that do not have anymore gems pinned to it diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 5bc53a8b61..700f0a4737 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -296,7 +296,7 @@ module Bundler # returns whether or not a re-resolve was needed def resolve_if_needed(options) - if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file? + if !@definition.unlocking? && !options["force"] && !options["all-platforms"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file? return false if @definition.nothing_changed? && !@definition.missing_specs? end diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index f5af10f206..c383c5ecbb 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -26,7 +26,11 @@ module Bundler end class GitCommandError < GitError + attr_reader :command + def initialize(command, path = nil, extra_info = nil) + @command = command + msg = String.new msg << "Git error: command `git #{command}` in directory #{SharedHelpers.pwd} has failed." msg << "\n#{extra_info}" if extra_info @@ -35,10 +39,10 @@ module Bundler end end - class MissingGitRevisionError < GitError - def initialize(ref, repo) + class MissingGitRevisionError < GitCommandError + def initialize(command, path, ref, repo) msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?" - super msg + super command, path, msg end end @@ -63,8 +67,8 @@ module Bundler begin @revision ||= find_local_revision - rescue GitCommandError - raise MissingGitRevisionError.new(ref, URICredentialsFilter.credential_filtered_uri(uri)) + rescue GitCommandError => e + raise MissingGitRevisionError.new(e.command, path, ref, URICredentialsFilter.credential_filtered_uri(uri)) end @revision @@ -135,8 +139,8 @@ module Bundler begin git "reset --hard #{@revision}" - rescue GitCommandError - raise MissingGitRevisionError.new(@revision, URICredentialsFilter.credential_filtered_uri(uri)) + rescue GitCommandError => e + raise MissingGitRevisionError.new(e.command, path, @revision, URICredentialsFilter.credential_filtered_uri(uri)) end if submodules diff --git a/lib/bundler/templates/newgem/Gemfile.tt b/lib/bundler/templates/newgem/Gemfile.tt index 4cd2e40f4f..83878ec7f8 100644 --- a/lib/bundler/templates/newgem/Gemfile.tt +++ b/lib/bundler/templates/newgem/Gemfile.tt @@ -2,3 +2,11 @@ source "https://rubygems.org" # Specify your gem's dependencies in <%= config[:name] %>.gemspec gemspec + +gem "rake", "~> 12.0" +<%- if config[:ext] -%> +gem "rake-compiler" +<%- end -%> +<%- if config[:test] -%> +gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" +<%- end -%> diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 7feae6b18c..9bb3d0ff50 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -31,13 +31,4 @@ Gem::Specification.new do |spec| <%- if config[:ext] -%> spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"] <%- end -%> - - spec.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>" - spec.add_development_dependency "rake", "~> 12.0" -<%- if config[:ext] -%> - spec.add_development_dependency "rake-compiler" -<%- end -%> -<%- if config[:test] -%> - spec.add_development_dependency "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" -<%- end -%> end diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb index 38b37570fe..8736fef060 100644 --- a/spec/bundler/definition_spec.rb +++ b/spec/bundler/definition_spec.rb @@ -147,6 +147,34 @@ RSpec.describe Bundler::Definition do G end + it "for a locked gem for another platform" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "only_java", platform: :jruby + G + + bundle "lock --add-platform java" + bundle :check, :env => { "DEBUG" => 1 } + + expect(out).to match(/using resolution from the lockfile/) + lockfile_should_be <<-G + GEM + remote: #{file_uri_for(gem_repo1)}/ + specs: + only_java (1.1-java) + + PLATFORMS + java + #{lockfile_platforms} + + DEPENDENCIES + only_java + + BUNDLED WITH + #{Bundler::VERSION} + G + end + it "for a rubygems gem" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/plugin/installer_spec.rb b/spec/bundler/plugin/installer_spec.rb index 65f6b4ab6b..c7e0d06746 100644 --- a/spec/bundler/plugin/installer_spec.rb +++ b/spec/bundler/plugin/installer_spec.rb @@ -66,7 +66,7 @@ RSpec.describe Bundler::Plugin::Installer do expect(spec.full_name).to eq "ga-plugin-1.0" end - it "has expected full gem path" do + it "has expected full_gem_path" do rev = revision_for(lib_path("ga-plugin")) expect(result["ga-plugin"].full_gem_path). to eq(Bundler::Plugin.root.join("bundler", "gems", "ga-plugin-#{rev[0..11]}").to_s) @@ -89,7 +89,7 @@ RSpec.describe Bundler::Plugin::Installer do expect(spec.full_name).to eq "ga-plugin-1.0" end - it "has expected full gem path" do + it "has expected full_gem_path" do rev = revision_for(lib_path("ga-plugin")) expect(result["ga-plugin"].full_gem_path). to eq(Bundler::Plugin.root.join("bundler", "gems", "ga-plugin-#{rev[0..11]}").to_s) @@ -105,7 +105,7 @@ RSpec.describe Bundler::Plugin::Installer do expect(result["re-plugin"]).to be_kind_of(Bundler::RemoteSpecification) end - it "has expected full_gem)path" do + it "has expected full_gem_path" do expect(result["re-plugin"].full_gem_path). to eq(global_plugin_gem("re-plugin-1.0").to_s) end @@ -121,7 +121,7 @@ RSpec.describe Bundler::Plugin::Installer do expect(result["ma-plugin"]).to be_kind_of(Bundler::RemoteSpecification) end - it "has expected full_gem)path" do + it "has expected full_gem_path" do expect(result["re-plugin"].full_gem_path).to eq(global_plugin_gem("re-plugin-1.0").to_s) expect(result["ma-plugin"].full_gem_path).to eq(global_plugin_gem("ma-plugin-1.0").to_s) end diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index f24d85c241..3b30a1f49f 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -263,6 +263,7 @@ RSpec.describe Bundler::SharedHelpers do end it "calls the appropriate set methods" do + expect(subject).to receive(:set_bundle_variables) expect(subject).to receive(:set_path) expect(subject).to receive(:set_rubyopt) expect(subject).to receive(:set_rubylib) diff --git a/spec/bundler/source/git/git_proxy_spec.rb b/spec/bundler/source/git/git_proxy_spec.rb index 016105ccde..c18490233d 100644 --- a/spec/bundler/source/git/git_proxy_spec.rb +++ b/spec/bundler/source/git/git_proxy_spec.rb @@ -128,16 +128,20 @@ RSpec.describe Bundler::Source::Git::GitProxy do context "when given a SHA as a revision" do let(:revision) { "abcd" * 10 } + let(:command) { "reset --hard #{revision}" } it "fails gracefully when resetting to the revision fails" do expect(subject).to receive(:git_retry).with(start_with("clone ")) { destination.mkpath } expect(subject).to receive(:git_retry).with(start_with("fetch ")) - expect(subject).to receive(:git).with("reset --hard #{revision}").and_raise(Bundler::Source::Git::GitCommandError, "command") + expect(subject).to receive(:git).with(command).and_raise(Bundler::Source::Git::GitCommandError, command) expect(subject).not_to receive(:git) expect { subject.copy_to(destination, submodules) }. - to raise_error(Bundler::Source::Git::MissingGitRevisionError, - "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?") + to raise_error( + Bundler::Source::Git::MissingGitRevisionError, + "Git error: command `git #{command}` in directory #{destination} has failed.\n" \ + "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?" \ + ) end end end diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 17a533ef19..2243a72b3d 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -568,9 +568,7 @@ RSpec.describe "bundle clean" do gemfile_lock.each_with_index do |line, index| gemfile_lock[index] = line[0..(11 + 7)] if line.include?(" revision:") end - File.open(bundled_app("Gemfile.lock"), "w") do |file| - file.print gemfile_lock.join("\n") - end + lockfile(bundled_app("Gemfile.lock"), gemfile_lock.join("\n")) bundle "install", forgotten_command_line_options(:path => "vendor/bundle") diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index a087eeb206..c0ef3bb70c 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -478,12 +478,10 @@ end RSpec.describe "setting gemfile via config" do context "when only the non-default Gemfile exists" do it "persists the gemfile location to .bundle/config" do - File.open(bundled_app("NotGemfile"), "w") do |f| - f.write <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - G - end + gemfile bundled_app("NotGemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" expect(File.exist?(".bundle/config")).to eq(true) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 8167aee3ae..b9be5d7c02 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -40,7 +40,7 @@ RSpec.describe "bundle exec" do bundle "exec 'cd #{tmp("gems")} && rackup'" - expect(out).to include("1.0.0") + expect(out).to eq("1.0.0") end it "works when exec'ing something else" do @@ -453,13 +453,12 @@ RSpec.describe "bundle exec" do it "works when unlocked" do bundle "exec 'cd #{tmp("gems")} && rackup'" expect(out).to eq("1.0.0") - expect(out).to include("1.0.0") end it "works when locked" do expect(the_bundle).to be_locked bundle "exec 'cd #{tmp("gems")} && rackup'" - expect(out).to include("1.0.0") + expect(out).to eq("1.0.0") end end diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index e6d6794462..94f4d82e98 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -363,9 +363,14 @@ RSpec.describe "bundle gem" do expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist end - it "depends on a specific version of rspec" do - rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "rspec" } - expect(rspec_dep).to be_specific + it "depends on a specific version of rspec in generated Gemfile" do + Dir.chdir(bundled_app("test_gem")) do + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("test_gem/Gemfile")) + builder.dependencies + rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } + expect(rspec_dep).to be_specific + end end it "requires 'test-gem'" do @@ -411,8 +416,13 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of minitest" do - rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "minitest" } - expect(rspec_dep).to be_specific + Dir.chdir(bundled_app("test_gem")) do + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("test_gem/Gemfile")) + builder.dependencies + minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } + expect(minitest_dep).to be_specific + end end it "builds spec skeleton" do @@ -703,7 +713,7 @@ RSpec.describe "bundle gem" do end it "includes rake-compiler" do - expect(bundled_app("test_gem/test_gem.gemspec").read).to include('spec.add_development_dependency "rake-compiler"') + expect(bundled_app("test_gem/Gemfile").read).to include('gem "rake-compiler"') end it "depends on compile task for build" do @@ -727,8 +737,7 @@ RSpec.describe "bundle gem" do describe "uncommon gem names" do it "can deal with two dashes" do - bundle "gem a--a" - Bundler.clear_gemspec_cache + execute_bundle_gem("a--a") expect(bundled_app("a--a/a--a.gemspec")).to exist end @@ -809,7 +818,7 @@ Usage: "bundle gem NAME [OPTIONS]" RAKEFILE expect(bundled_app("foobar/Rakefile").read).to eq(rakefile) - expect(bundled_app("foobar/foobar.gemspec").read).to include('spec.add_development_dependency "rspec"') + expect(bundled_app("foobar/Gemfile").read).to include('gem "rspec"') end it "asks about MIT license" do diff --git a/spec/commands/package_spec.rb b/spec/commands/package_spec.rb index 6f6d78d697..e051743fd0 100644 --- a/spec/commands/package_spec.rb +++ b/spec/commands/package_spec.rb @@ -203,6 +203,35 @@ RSpec.describe "bundle package" do bundle "package --all-platforms" expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end + + it "does not attempt to install gems in without groups" do + build_repo4 do + build_gem "uninstallable", "2.0" do |s| + s.add_development_dependency "rake" + s.extensions << "Rakefile" + s.write "Rakefile", "task(:default) { raise 'CANNOT INSTALL' }" + end + end + + install_gemfile! <<-G, forgotten_command_line_options(:without => "wo") + source "file:#{gem_repo1}" + gem "rack" + group :wo do + gem "weakling" + gem "uninstallable", :source => "file:#{gem_repo4}" + end + G + + bundle! :package, "all-platforms" => true + expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist + expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + + bundle! :install, forgotten_command_line_options(:without => "wo") + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + end end context "with --frozen" do diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index fe51650f76..f2dcd33d7d 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -1003,10 +1003,8 @@ RSpec.describe "bundle install with git sources" do update_git "valim" new_revision = revision_for(lib_path("valim-1.0")) - lockfile = File.read(bundled_app("Gemfile.lock")) - File.open(bundled_app("Gemfile.lock"), "w") do |file| - file.puts lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}") - end + old_lockfile = File.read(bundled_app("Gemfile.lock")) + lockfile(bundled_app("Gemfile.lock"), old_lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}")) bundle "install" diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index ec07d6a4f3..6168c0c197 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/runtime/inline_spec.rb @@ -291,6 +291,19 @@ RSpec.describe "bundler/inline#gemfile" do expect(out).to eq "1.0.0" end + context "when BUNDLE_PATH is set" do + it "installs inline gems to the system path regardless" do + script <<-RUBY, :env => { "BUNDLE_PATH" => "./vendor/inline" } + gemfile(true) do + source "file://#{gem_repo1}" + gem "rack" + end + RUBY + expect(last_command).to be_success + expect(system_gem_path("gems/rack-1.0.0")).to exist + end + end + it "skips platform warnings" do simulate_platform "ruby" diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 51de4eb38a..3866bebb44 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -833,7 +833,9 @@ end ruby <<-R, :env => { "GEM_PATH" => symlinked_gem_home }, :no_lib => true TracePoint.trace(:class) do |tp| - puts "OMG" if tp.path.include?("bundler") && !tp.path.start_with?("#{File.expand_path("../..", __dir__)}") + if tp.path.include?("bundler") && !tp.path.start_with?("#{File.expand_path("../..", __dir__)}") + puts "OMG. Defining a class from another bundler at \#{tp.path}:\#{tp.lineno}" + end end gem 'bundler', '#{Bundler::VERSION}' require 'bundler/setup' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 444f3a3cf3..a90d8e9885 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,7 +71,6 @@ RSpec.configure do |config| config.filter_run_excluding :ruby => RequirementChecker.against(RUBY_VERSION) config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) config.filter_run_excluding :git => RequirementChecker.against(git_version) - config.filter_run_excluding :rubygems_master => (ENV["RGV"] != "master") config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) config.filter_run_excluding :ruby_repo => !(ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"]).nil? config.filter_run_excluding :non_windows => Gem.win_platform? |