diff options
author | John Keiser <john@johnkeiser.com> | 2016-04-12 16:04:27 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-04-18 14:21:02 -0700 |
commit | bbc1d6ebccbd7f22fea72a9c2b76ef19f3b5beb3 (patch) | |
tree | 97bd064d63268eb7ff39e1b4416abdff42ad0f34 /omnibus | |
parent | 612932e984e4a210891e5d2d00d25723afd6b6a4 (diff) | |
download | chef-bbc1d6ebccbd7f22fea72a9c2b76ef19f3b5beb3.tar.gz |
Simplify external tests and make them work with Gemfile.lock
Diffstat (limited to 'omnibus')
-rw-r--r-- | omnibus/Gemfile.lock | 12 | ||||
-rw-r--r-- | omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb | 43 | ||||
-rw-r--r-- | omnibus/files/chef/build-chef.rb | 18 |
3 files changed, 35 insertions, 38 deletions
diff --git a/omnibus/Gemfile.lock b/omnibus/Gemfile.lock index e9c711ed78..7e92537e3c 100644 --- a/omnibus/Gemfile.lock +++ b/omnibus/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/chef/omnibus-software.git - revision: 8d611676c4458fa679cbc48e2111892ae7986cbf + revision: 6127be3af79941c32419228cbd9e63c4f061d76b specs: omnibus-software (4.0.0) omnibus (>= 5.2.0) @@ -81,7 +81,8 @@ GEM celluloid-io (0.16.2) celluloid (>= 0.16.0) nio4r (>= 1.1.0) - chef-config (12.8.1) + chef-config (12.9.38) + fuzzyurl (~> 0.8.0) mixlib-config (~> 2.0) mixlib-shellout (~> 2.0) chef-sugar (3.3.0) @@ -99,6 +100,7 @@ GEM ffi (1.9.10) ffi-yajl (2.2.3) libyajl2 (~> 1.2) + fuzzyurl (0.8.0) gssapi (1.2.0) ffi (>= 1.0.1) gyoku (1.3.1) @@ -128,7 +130,7 @@ GEM rspec-mocks (~> 3.2) mixlib-cli (1.5.0) mixlib-config (2.2.1) - mixlib-install (1.0.5) + mixlib-install (1.0.6) artifactory (>= 2.3.0) mixlib-shellout (>= 2.2.6) mixlib-versioning (>= 1.1.0) @@ -209,7 +211,7 @@ GEM dep_selector (~> 1.0) semverse (~> 1.1) systemu (2.6.5) - test-kitchen (1.7.2) + test-kitchen (1.7.3) mixlib-install (~> 1.0, >= 1.0.4) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) @@ -230,7 +232,7 @@ GEM logging (>= 1.6.1, < 3.0) nori (~> 2.0) rubyntlm (~> 0.6.0) - winrm-fs (0.4.1) + winrm-fs (0.4.2) erubis (~> 2.7) logging (>= 1.6.1, < 3.0) rubyzip (~> 1.1) diff --git a/omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb b/omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb index 5992ae8057..ee096b8ed9 100644 --- a/omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb +++ b/omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb @@ -1,6 +1,7 @@ require "bundler" require "omnibus" require_relative "../build-chef-gem" +require_relative "../../../../tasks/gemfile_util" module BuildChefGem class GemInstallSoftwareDef @@ -34,16 +35,16 @@ module BuildChefGem gem_name = self.gem_name gem_version = self.gem_version - gemspec = self.gemspec + gem_metadata = self.gem_metadata lockfile_path = self.lockfile_path software.build do extend BuildChefGem if gem_version == "<skip>" - if gemspec + if gem_metadata block do - log.info(log_key) { "#{gem_name} has source #{gemspec.source.name} in #{lockfile_path}. We only cache rubygems.org installs in omnibus to keep things simple. The chef step will build #{gem_name} ..." } + log.info(log_key) { "#{gem_name} has source #{gem_metadata} in #{lockfile_path}. We only cache rubygems.org installs in omnibus to keep things simple. The chef step will build #{gem_name} ..." } end else block do @@ -95,34 +96,26 @@ module BuildChefGem end end - def gemspec - @gemspec ||= begin - old_frozen = Bundler.settings[:frozen] - Bundler.settings[:frozen] = true - begin - bundle = Bundler::Definition.build(gemfile_path, lockfile_path, nil) - dependencies = bundle.dependencies.select { |d| (d.groups - without_groups).any? } - # This is sacrilege: figure out a way we can grab the list of dependencies *without* - # requiring everything to be installed or calling private methods ... - gemspec = bundle.resolve.for(bundle.send(:expand_dependencies, dependencies)).find { |s| s.name == gem_name } - if gemspec - log.info(software.name) { "Using #{gem_name} version #{gemspec.version} from #{gemfile_path}" } - elsif bundle.resolve.find { |s| s.name == gem_name } - log.info(software.name) { "#{gem_name} not loaded from #{gemfile_path}, skipping" } - else - raise "#{gem_name} not found in #{gemfile_path} or #{lockfile_path}" - end - gemspec - ensure - Bundler.settings[:frozen] = old_frozen + def gem_metadata + @gem_metadata ||= begin + selected = GemfileUtil.select_gems(gemfile_path, without_groups: without_groups) + result = GemfileUtil.locked_gems(lockfile_path, selected)[gem_name] + if result + log.info(software.name) { "Using #{gem_name} version #{result[:version]} from #{gemfile_path}" } + result + elsif GemfileUtil.locked_gems(lockfile_path, GemfileUtil.select_gems(gemfile_path))[gem_name] + log.info(software.name) { "#{gem_name} not loaded from #{gemfile_path} because it was only in groups #{without_groups.join(", ")}, skipping" } + nil + else + raise "#{gem_name} not found in #{gemfile_path} or #{lockfile_path}" end end end def gem_version @gem_version ||= begin - if gemspec && gemspec.source.name == "rubygems repository https://rubygems.org/" - gemspec.version.to_s + if gem_metadata && URI(gem_metadata[:source]) == URI("https://rubygems.org/") + gem_metadata[:version] else "<skip>" end diff --git a/omnibus/files/chef/build-chef.rb b/omnibus/files/chef/build-chef.rb index d3e68d4e8a..21bd6c2250 100644 --- a/omnibus/files/chef/build-chef.rb +++ b/omnibus/files/chef/build-chef.rb @@ -108,22 +108,24 @@ module BuildChef name, version = $1, $2 # rubocop is an exception, since different projects disagree next if GEMS_ALLOWED_TO_FLOAT.include?(name) - gem_pins << "override_gem #{name.inspect}, #{version.inspect}\n" + gem_pins << "gem #{name.inspect}, #{version.inspect}, override: true\n" end end + # Find the installed chef gem by looking for lib/chef.rb + chef_gem = File.expand_path("../..", shellout!("#{gem_bin} which chef").stdout.chomp) + # Figure out the path to gemfile_util from there + gemfile_util = Pathname.new(File.join(chef_gem, "tasks", "gemfile_util")) + gemfile_util = gemfile_util.relative_path_from(Pathname.new(shared_gemfile).dirname) + create_file(shared_gemfile) { <<-EOM } - # Meant to be included in component Gemfiles at the end with: + # Meant to be included in component Gemfiles at the beginning with: # # instance_eval(IO.read("#{install_dir}/Gemfile"), "#{install_dir}/Gemfile") # # Override any existing gems with our own. - def override_gem(name, *args, &block) - # If the Gemfile re-specifies something in our lockfile, ignore it. - current = dependencies.find { |dep| dep.name == name } - dependencies.delete(current) if current - gem(name, *args, &block) - end + require_relative "#{gemfile_util}" + extend GemfileUtil #{gem_pins} EOM end |