Skip to content

Commit

Permalink
fix bundle locking on bundler 1.12 and enforce version we want
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed May 25, 2016
1 parent 7e3a0aa commit 5d37fc2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
17 changes: 6 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ extend GemfileUtil

source "https://rubygems.org"

# Pick the gemspec for our platform
gemspec_name = "chef"
Dir.glob("chef-*.gemspec").each do |gemspec_filename|
gemspec_filename =~ /^chef-(.+).gemspec/
gemspec_platform = $1
if Gem::Platform.match(Gem::Platform.new(gemspec_platform))
Bundler.ui.info "Using gemspec #{gemspec_filename} for current platform."
gemspec_name = "chef-#{gemspec_platform}"
end
end
gemspec name: gemspec_name
# Note we do not use the gemspec DSL which restricts to the
# gemspec for the current platform and filters out other platforms
# during a bundle lock operation. We actually want dependencies from
# both of our gemspecs. Also note this this mimics gemspec behavior
# of bundler versions prior to 1.12.0 (https://github.com/bundler/bundler/commit/193a14fe5e0d56294c7b370a0e59f93b2c216eed)
gem "chef", path: "."

gem "chef-config", path: File.expand_path("../chef-config", __FILE__) if File.exist?(File.expand_path("../chef-config", __FILE__))
# Ensure that we can always install rake, regardless of gem groups
Expand Down
8 changes: 6 additions & 2 deletions tasks/bin/bundle-platform
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/usr/bin/env ruby

platforms = ARGV.shift
platforms = platforms.split(" ").map { |p| Gem::Platform.new(p) }
Gem::Platform.instance_eval { @local = platforms.last }
old_platforms = Gem.platforms
Gem.platforms = platforms.split(" ").map { |p| Gem::Platform.new(p) }
Gem.platforms = platforms
puts "bundle-platform set Gem.platforms to #{Gem.platforms.map { |p| p.to_s }} (was #{old_platforms.map { |p| p.to_s } })"

desired_version = ARGV.shift.delete("_", "")

# The rest of this is a normal bundler binstub
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"

load Gem.bin_path("bundler", "bundle")
load Gem.bin_path("bundler", "bundle", desired_version)
20 changes: 18 additions & 2 deletions tasks/bundle_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,22 @@ def bundle(args, gemfile: nil, platform: nil, cwd: nil, extract_output: false, d

# Run the bundle command
ruby_platforms = platform ? PLATFORMS[platform].join(" ") : "ruby"
cmd = Shellwords.join([Gem.ruby, "-S", bundle_platform, ruby_platforms, *args])
cmd = Shellwords.join([
Gem.ruby,
"-S",
bundle_platform,
ruby_platforms,
"_#{desired_bundler_version}_",
*args,
])
puts "#{prefix}#{Shellwords.join(["bundle", *args])}#{platform ? " for #{platform} platform" : ""}:"
with_gemfile(gemfile) do
puts "#{prefix}BUNDLE_GEMFILE=#{gemfile}"
puts "#{prefix}> #{cmd}"
if extract_output
`#{cmd}`
else
unless system(bundle_platform, ruby_platforms, *args)
unless system(bundle_platform, ruby_platforms, "_#{desired_bundler_version}_", *args)
raise "#{bundle_platform} failed: exit code #{$?}"
end
end
Expand All @@ -91,4 +98,13 @@ def with_gemfile(gemfile)
def platforms
PLATFORMS.keys
end

def desired_bundler_version
@desired_bundler_version ||= begin
omnibus_overrides = File.join(project_root, "omnibus_overrides.rb")
File.readlines(omnibus_overrides).each do |line|
return $1 if line =~ /^override :bundler, version: "(.+)"$/
end
end
end
end

0 comments on commit 5d37fc2

Please sign in to comment.