summaryrefslogtreecommitdiff
path: root/omnibus/files
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-04-12 16:04:27 -0700
committerJohn Keiser <john@johnkeiser.com>2016-04-18 14:21:02 -0700
commitbbc1d6ebccbd7f22fea72a9c2b76ef19f3b5beb3 (patch)
tree97bd064d63268eb7ff39e1b4416abdff42ad0f34 /omnibus/files
parent612932e984e4a210891e5d2d00d25723afd6b6a4 (diff)
downloadchef-bbc1d6ebccbd7f22fea72a9c2b76ef19f3b5beb3.tar.gz
Simplify external tests and make them work with Gemfile.lock
Diffstat (limited to 'omnibus/files')
-rw-r--r--omnibus/files/chef-gem/build-chef-gem/gem-install-software-def.rb43
-rw-r--r--omnibus/files/chef/build-chef.rb18
2 files changed, 28 insertions, 33 deletions
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