From c1887fb75d2159350e9505dad23180ad53641d66 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Mon, 28 Sep 2015 23:25:38 +0100 Subject: Raises an error if there are missing dependencies Also forces all installs through the parallel_installer to ensure consistency. --- lib/bundler/installer.rb | 22 +++++----------------- lib/bundler/installer/parallel_installer.rb | 18 +++++++++++++----- spec/install/parallel/spec_installation_spec.rb | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 00bd2158eb..e55ecfa535 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -1,6 +1,7 @@ require "erb" require "rubygems/dependency_installer" require "bundler/worker" +require "bundler/installer/parallel_installer" module Bundler class Installer < Environment @@ -176,13 +177,9 @@ module Bundler # installation is just SO MUCH FASTER. so we let people opt in. def install(options) force = options["force"] - jobs = [Bundler.settings[:jobs].to_i - 1, 1].max - if jobs > 1 && can_install_in_parallel? - require "bundler/installer/parallel_installer" - install_in_parallel jobs, options[:standalone], force - else - install_sequentially options[:standalone], force - end + jobs = 1 + jobs = [Bundler.settings[:jobs].to_i - 1, 1].max if can_install_in_parallel? + install_in_parallel jobs, options[:standalone], force end def can_install_in_parallel? @@ -190,7 +187,7 @@ module Bundler true else Bundler.ui.warn "Rubygems #{Gem::VERSION} is not threadsafe, so your "\ - "gems must be installed one at a time. Upgrade to Rubygems 2.1.0 " \ + "gems will be installed one at a time. Upgrade to Rubygems 2.1.0 " \ "or higher to enable parallel gem installation." false end @@ -248,15 +245,6 @@ module Bundler end end - def install_sequentially(standalone, force = false) - specs.each do |spec| - message = install_gem_from_spec spec, standalone, 0, force - if message - Installer.post_install_messages[spec.name] = message - end - end - end - def install_in_parallel(size, standalone, force = false) ParallelInstaller.call(self, specs, size, standalone, force) end diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 84bdb425fa..fd677c70c7 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -35,13 +35,21 @@ class ParallelInstaller # sure needed dependencies have been installed. def dependencies_installed?(all_specs) installed_specs = all_specs.select(&:installed?).map(&:name) - dependencies.all? {|d| installed_specs.include? d.name } + dependencies(all_specs.map(&:name)).all? {|d| installed_specs.include? d.name } end - # Represents only the non-development dependencies and the ones that - # are itself. - def dependencies - @dependencies ||= all_dependencies.reject {|dep| ignorable_dependency? dep } + # Represents only the non-development dependencies, the ones that are + # itself and are in the total list. + def dependencies(all_spec_names) + @dependencies ||= begin + deps = all_dependencies.reject {|dep| ignorable_dependency? dep } + missing = deps.reject {|dep| all_spec_names.include? dep.name } + if missing.size > 0 + raise Bundler::GemfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing\n" \ + "from the DEPENDENCIES section: '#{missing.map(&:name).join('\' \'')}'" + end + deps + end end # Represents all dependencies diff --git a/spec/install/parallel/spec_installation_spec.rb b/spec/install/parallel/spec_installation_spec.rb index 2d741a15ff..b9bb16ddaa 100644 --- a/spec/install/parallel/spec_installation_spec.rb +++ b/spec/install/parallel/spec_installation_spec.rb @@ -57,5 +57,21 @@ describe ParallelInstaller::SpecInstallation do expect(spec.dependencies_installed?(all_specs)).to be_falsey end end + + context "when dependencies that are not on the overall installation list are the only ones not installed" do + it "raises an error" do + dependencies = [] + dependencies << instance_double("SpecInstallation", :spec => "alpha", :name => "alpha", :installed? => true, :all_dependencies => [], :type => :production) + all_specs = dependencies + [instance_double("SpecInstallation", :spec => "gamma", :name => "gamma", :installed? => false, :all_dependencies => [], :type => :production)] + # Add dependency which is not in all_specs + dependencies << instance_double("SpecInstallation", :spec => "beta", :name => "beta", :installed? => false, :all_dependencies => [], :type => :production) + dependencies << instance_double("SpecInstallation", :spec => "delta", :name => "delta", :installed? => false, :all_dependencies => [], :type => :production) + spec = ParallelInstaller::SpecInstallation.new(dep) + allow(spec).to receive(:all_dependencies).and_return(dependencies) + expect { spec.dependencies_installed?(all_specs) }. + to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*\n.*'beta' 'delta'/) + end + end + end end -- cgit v1.2.1 From c539a4cbedf2cf0285d79339a8919cf6a0f35f9a Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Mon, 28 Sep 2015 23:25:38 +0100 Subject: Raises an error if there are missing dependencies Also forces all installs through the parallel_installer to ensure consistency. --- lib/bundler/installer.rb | 22 +++++----------------- lib/bundler/installer/parallel_installer.rb | 18 +++++++++++++----- spec/install/parallel/spec_installation_spec.rb | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 29f2a30fb0..923fbd1faf 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -1,6 +1,7 @@ require "erb" require "rubygems/dependency_installer" require "bundler/worker" +require "bundler/installer/parallel_installer" module Bundler class Installer < Environment @@ -176,13 +177,9 @@ module Bundler # installation is just SO MUCH FASTER. so we let people opt in. def install(options) force = options["force"] - jobs = [Bundler.settings[:jobs].to_i - 1, 1].max - if jobs > 1 && can_install_in_parallel? - require "bundler/installer/parallel_installer" - install_in_parallel jobs, options[:standalone], force - else - install_sequentially options[:standalone], force - end + jobs = 1 + jobs = [Bundler.settings[:jobs].to_i - 1, 1].max if can_install_in_parallel? + install_in_parallel jobs, options[:standalone], force end def can_install_in_parallel? @@ -190,7 +187,7 @@ module Bundler true else Bundler.ui.warn "Rubygems #{Gem::VERSION} is not threadsafe, so your "\ - "gems must be installed one at a time. Upgrade to Rubygems 2.1.0 " \ + "gems will be installed one at a time. Upgrade to Rubygems 2.1.0 " \ "or higher to enable parallel gem installation." false end @@ -250,15 +247,6 @@ module Bundler end end - def install_sequentially(standalone, force = false) - specs.each do |spec| - message = install_gem_from_spec spec, standalone, 0, force - if message - Installer.post_install_messages[spec.name] = message - end - end - end - def install_in_parallel(size, standalone, force = false) ParallelInstaller.call(self, specs, size, standalone, force) end diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 84bdb425fa..fd677c70c7 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -35,13 +35,21 @@ class ParallelInstaller # sure needed dependencies have been installed. def dependencies_installed?(all_specs) installed_specs = all_specs.select(&:installed?).map(&:name) - dependencies.all? {|d| installed_specs.include? d.name } + dependencies(all_specs.map(&:name)).all? {|d| installed_specs.include? d.name } end - # Represents only the non-development dependencies and the ones that - # are itself. - def dependencies - @dependencies ||= all_dependencies.reject {|dep| ignorable_dependency? dep } + # Represents only the non-development dependencies, the ones that are + # itself and are in the total list. + def dependencies(all_spec_names) + @dependencies ||= begin + deps = all_dependencies.reject {|dep| ignorable_dependency? dep } + missing = deps.reject {|dep| all_spec_names.include? dep.name } + if missing.size > 0 + raise Bundler::GemfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing\n" \ + "from the DEPENDENCIES section: '#{missing.map(&:name).join('\' \'')}'" + end + deps + end end # Represents all dependencies diff --git a/spec/install/parallel/spec_installation_spec.rb b/spec/install/parallel/spec_installation_spec.rb index 2d741a15ff..b9bb16ddaa 100644 --- a/spec/install/parallel/spec_installation_spec.rb +++ b/spec/install/parallel/spec_installation_spec.rb @@ -57,5 +57,21 @@ describe ParallelInstaller::SpecInstallation do expect(spec.dependencies_installed?(all_specs)).to be_falsey end end + + context "when dependencies that are not on the overall installation list are the only ones not installed" do + it "raises an error" do + dependencies = [] + dependencies << instance_double("SpecInstallation", :spec => "alpha", :name => "alpha", :installed? => true, :all_dependencies => [], :type => :production) + all_specs = dependencies + [instance_double("SpecInstallation", :spec => "gamma", :name => "gamma", :installed? => false, :all_dependencies => [], :type => :production)] + # Add dependency which is not in all_specs + dependencies << instance_double("SpecInstallation", :spec => "beta", :name => "beta", :installed? => false, :all_dependencies => [], :type => :production) + dependencies << instance_double("SpecInstallation", :spec => "delta", :name => "delta", :installed? => false, :all_dependencies => [], :type => :production) + spec = ParallelInstaller::SpecInstallation.new(dep) + allow(spec).to receive(:all_dependencies).and_return(dependencies) + expect { spec.dependencies_installed?(all_specs) }. + to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*\n.*'beta' 'delta'/) + end + end + end end -- cgit v1.2.1 From 04c3ac41e074ec0d2fbe5743d3ab97341ed33746 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Tue, 29 Sep 2015 10:08:51 +0100 Subject: Fix rubocop offense --- spec/install/parallel/spec_installation_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/install/parallel/spec_installation_spec.rb b/spec/install/parallel/spec_installation_spec.rb index b9bb16ddaa..8a32107bc1 100644 --- a/spec/install/parallel/spec_installation_spec.rb +++ b/spec/install/parallel/spec_installation_spec.rb @@ -72,6 +72,5 @@ describe ParallelInstaller::SpecInstallation do to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*\n.*'beta' 'delta'/) end end - end end -- cgit v1.2.1 From ced3616171d9236da2e296ebafc9c483de79077c Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Tue, 29 Sep 2015 16:37:00 +0100 Subject: remove newline from error message. --- lib/bundler/installer/parallel_installer.rb | 2 +- spec/install/parallel/spec_installation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index fd677c70c7..1fe86c4030 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -45,7 +45,7 @@ class ParallelInstaller deps = all_dependencies.reject {|dep| ignorable_dependency? dep } missing = deps.reject {|dep| all_spec_names.include? dep.name } if missing.size > 0 - raise Bundler::GemfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing\n" \ + raise Bundler::GemfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing " \ "from the DEPENDENCIES section: '#{missing.map(&:name).join('\' \'')}'" end deps diff --git a/spec/install/parallel/spec_installation_spec.rb b/spec/install/parallel/spec_installation_spec.rb index 8a32107bc1..77bfe1cf9c 100644 --- a/spec/install/parallel/spec_installation_spec.rb +++ b/spec/install/parallel/spec_installation_spec.rb @@ -69,7 +69,7 @@ describe ParallelInstaller::SpecInstallation do spec = ParallelInstaller::SpecInstallation.new(dep) allow(spec).to receive(:all_dependencies).and_return(dependencies) expect { spec.dependencies_installed?(all_specs) }. - to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*\n.*'beta' 'delta'/) + to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*'beta' 'delta'/) end end end -- cgit v1.2.1 From c34e2d9750c107c4f2a784404906fba18b17d236 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Tue, 29 Sep 2015 17:34:27 +0100 Subject: Change error type to LockfileError --- lib/bundler/installer/parallel_installer.rb | 2 +- spec/install/parallel/spec_installation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 1fe86c4030..c1a8065a09 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -45,7 +45,7 @@ class ParallelInstaller deps = all_dependencies.reject {|dep| ignorable_dependency? dep } missing = deps.reject {|dep| all_spec_names.include? dep.name } if missing.size > 0 - raise Bundler::GemfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing " \ + raise Bundler::LockfileError, "Your Gemfile.lock is corrupt. The following #{missing.size > 1 ? "gems are" : "gem is"} missing " \ "from the DEPENDENCIES section: '#{missing.map(&:name).join('\' \'')}'" end deps diff --git a/spec/install/parallel/spec_installation_spec.rb b/spec/install/parallel/spec_installation_spec.rb index 77bfe1cf9c..6e92bb4cb8 100644 --- a/spec/install/parallel/spec_installation_spec.rb +++ b/spec/install/parallel/spec_installation_spec.rb @@ -69,7 +69,7 @@ describe ParallelInstaller::SpecInstallation do spec = ParallelInstaller::SpecInstallation.new(dep) allow(spec).to receive(:all_dependencies).and_return(dependencies) expect { spec.dependencies_installed?(all_specs) }. - to raise_error(Bundler::GemfileError, /Your Gemfile.lock is corrupt\. The following.*'beta' 'delta'/) + to raise_error(Bundler::LockfileError, /Your Gemfile.lock is corrupt\. The following.*'beta' 'delta'/) end end end -- cgit v1.2.1