summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Brugidou <m.brugidou@criteo.com>2017-03-24 09:44:03 +0100
committerRyan Hass <rhass@users.noreply.github.com>2017-11-01 11:04:15 -0700
commit166f600e7aad115a7d311459b4a92028507e85b0 (patch)
tree53872e405c2c73637a2df4de21c10a5b2d872cad
parenta769920c0546caf6e90b38c71da91e327d87a080 (diff)
downloadchef-rhass/backport-cookbook-gem-fix.tar.gz
Fix cookbook gem installerrhass/backport-cookbook-gem-fix
Current gem installer does not work if multiple cookbook request the same gem. The solution is to merge all the gem requirements for the same gem. If multiple cookbooks have conflicting constraints, the install will fail anyway. This bug affects Chef 12 too and make the feature almost unusable. Change-Id: I73bdb3db94052dadc4bac7bf03f74db8c420aad5 Signed-off-by: Maxime Brugidou <m.brugidou@criteo.com> Signed-off-by: Ryan Hass <rhass@users.noreply.github.com>
-rw-r--r--lib/chef/cookbook/gem_installer.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb
index df73ce3ee4..365b185426 100644
--- a/lib/chef/cookbook/gem_installer.rb
+++ b/lib/chef/cookbook/gem_installer.rb
@@ -36,10 +36,12 @@ class Chef
# Installs the gems into the omnibus gemset.
#
def install
- cookbook_gems = []
+ cookbook_gems = Hash.new { |h, k| h[k] = [] }
cookbook_collection.each do |cookbook_name, cookbook_version|
- cookbook_gems += cookbook_version.metadata.gems
+ cookbook_version.metadata.gems.each do |args|
+ cookbook_gems[args.first] += args[1..-1]
+ end
end
events.cookbook_gem_start(cookbook_gems)
@@ -49,8 +51,8 @@ class Chef
Dir.mktmpdir("chef-gem-bundle") do |dir|
File.open("#{dir}/Gemfile", "w+") do |tf|
tf.puts "source '#{Chef::Config[:rubygems_url]}'"
- cookbook_gems.each do |args|
- tf.puts "gem(*#{args.inspect})"
+ cookbook_gems.each do |gem_name, args|
+ tf.puts "gem(*#{([gem_name] + args).inspect})"
end
tf.close
Chef::Log.debug("generated Gemfile contents:")