Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Fix Windows lockfiles to match gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed Apr 7, 2016
1 parent c21e82a commit 57f5670
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 109 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -6,7 +6,6 @@ pkg/*
*~
bin
! bin/chef
! bin/bundle-platform

# You should check in your Gemfile.lock in applications, and not in gems
/Gemfile.local
Expand Down
42 changes: 12 additions & 30 deletions Gemfile
Expand Up @@ -17,7 +17,10 @@

source 'https://rubygems.org'

gemspec :name => "chef-dk"
# path is needed because when we attempt to load this gemspec to look at it from
# another bundle, it will expand the path relative to the other bundle rather than
# this file.
gemspec path: File.dirname(__FILE__), name: "chef-dk"

# EXPERIMENTAL: ALL gems specified here will be installed in chef-dk omnibus.
# This represents all gems that will be part of chef-dk.
Expand Down Expand Up @@ -59,6 +62,14 @@ gem "pry-stack_explorer"
gem "rb-readline"
gem "rubocop", "~> 0.37.2"
gem "winrm-fs"
# NOTE this needs to be excluded from AIX too, but we don't support that on
# ChefDK and putting a thing in multiple groups :no_windows, :no_aix won't work
# because it --without no_aix will still install things in group :no_windows.
# Need to specify groups positively; investigate.
# http://stackoverflow.com/questions/8420414/how-to-add-mac-specific-gems-to-bundle-on-mac-but-not-on-linux
group :no_windows do
gem "ruby-shadow"
end

# bundled or development dependencies we want to ship
gem "dep_selector"
Expand All @@ -69,32 +80,3 @@ gem "rdoc"
gem "yard"

gem "jmespath", '< 1.2'


# See `rake dependencies` for the usage of this:

# If we're running out of bin/bundle-platform, we're updating deps. If the platform
# is set to anything other than "ruby," we are doing a platform-specific lockfile,
# and therefore MUST pin all gem versions to the same as the generic Gemfile.lock.
# It is an error if we use different versions anywhere. This ensures that by
# pinning all dependencies to their version in Gemfile.lock.
if File.basename($0) == "bundle-platform" && Gem.platforms != [ "ruby" ]
puts "platform-bundling for a different platform: #{Gem.platforms.map { |p| p.to_s }}."
puts "Reading all versions from Gemfile.lock"
# We ensure everything in windows is pinned to the same version as "generic"
# by reading the generic Gemfile.lock and pinning to that version in the Gemfile.
lockfile = File.expand_path("../Gemfile.lock", __FILE__)
Bundler::LockfileParser.new(IO.read(lockfile)).specs.each do |spec|
# copy the groups from the existing spec if they are there
options = {}
current = dependencies.find { |d| d.name == spec.name }
if current
unless current.requirement.satisfied_by?(spec.version)
puts "WARN: using locked #{spec.name} version #{spec.version} when gemfile asks for #{current}"
end
dependencies.delete(current)
options[:groups] = current.groups
end
gem spec.name, spec.version, options
end
end
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -580,6 +580,7 @@ GEM
unicode-display_width (~> 0.3)
ruby-prof (0.15.9)
ruby-progressbar (1.7.5)
ruby-shadow (2.5.0)
rubyntlm (0.6.0)
rubyzip (1.2.0)
rufus-lru (1.0.5)
Expand Down Expand Up @@ -665,6 +666,7 @@ PLATFORMS
DEPENDENCIES
appbundler!
berkshelf
bundler
chef!
chef-dk!
chef-provisioning (>= 1.6.0)
Expand Down Expand Up @@ -702,6 +704,7 @@ DEPENDENCIES
rspec-mocks (~> 3.0)
rubocop (~> 0.37.2)
ruby-prof
ruby-shadow
test-kitchen (>= 1.6.0)
winrm-fs
yard
Expand Down
35 changes: 35 additions & 0 deletions Gemfile.windows
@@ -0,0 +1,35 @@
#
# We ensure everything in windows is pinned to the same version as "generic"
# by reading the generic Gemfile.lock and pinning to that version in the Gemfile.
#
# This could *almost* be accomplished by simply copying the lockfile and doing a
# `bundle install` to add any windows dependencies, but bundler can still update
# existing versions in a couple of cases:
#
# 1. When the source has changed since the main lockfile was built.
# 2. When Windows-specific dependencies constrain our solution.
#
# We do NOT allow windows gem versions to differ from non-windows, so that our
# packages are consistent across operating systems.
#
# At the end of this process, this `Gemfile`:
#
# ```
# gem 'chef', github: 'chef/chef'
# gem 'berkshelf'
# ```
#
# Is transformed to something like this:
#
# ```
# gem 'chef', github: 'chef/chef', ref: '23049723984237948023'
# gem 'berkshelf', '= 2.0.5'
# gem 'ohai', '= 12.9.30' # implicit dependency of chef
# ```
#

require_relative "tasks/gemfile_util"
extend GemfileUtil
generic_gemfile = File.expand_path("../Gemfile", __FILE__)
puts "Reading locks from #{generic_gemfile} to fill in #{__FILE__}"
include_locked_gemfile(generic_gemfile)
48 changes: 9 additions & 39 deletions Gemfile.windows.lock
@@ -1,41 +1,16 @@
GIT
remote: git://github.com/chef/appbundler.git
revision: b7040eeea2cbe7793a05b415488e4ae8949b7b1e
branch: jk/multiple-gems
ref: b7040eeea2cbe7793a05b415488e4ae8949b7b1e
specs:
appbundler (0.8.0)
mixlib-cli (~> 1.4)

GIT
remote: git://github.com/chef/chef.git
revision: d3aecf5aeb05a5d0762d3df42feb9de7054a845c
branch: v12.9.7
ref: d3aecf5aeb05a5d0762d3df42feb9de7054a845c
specs:
chef (12.9.7)
bundler (>= 1.10)
chef-config (= 12.9.7)
chef-zero (~> 4.5)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
ffi-yajl (~> 2.2)
highline (~> 1.6, >= 1.6.9)
mixlib-authentication (~> 1.4)
mixlib-cli (~> 1.4)
mixlib-log (~> 1.3)
mixlib-shellout (~> 2.0)
net-ssh (>= 2.9, < 4.0)
net-ssh-multi (~> 1.1)
ohai (>= 8.6.0.alpha.1, < 9)
plist (~> 3.2)
proxifier (~> 1.0)
rspec-core (~> 3.4)
rspec-expectations (~> 3.4)
rspec-mocks (~> 3.4)
rspec_junit_formatter (~> 0.2.0)
serverspec (~> 2.7)
specinfra (~> 2.10)
syslog-logger (~> 1.6)
uuidtools (~> 2.1.5)
chef (12.9.7-universal-mingw32)
bundler (>= 1.10)
chef-config (= 12.9.7)
Expand Down Expand Up @@ -222,7 +197,6 @@ GEM
multipart-post (>= 1.2, < 3)
fauxhai (3.2.0)
net-ssh
ffi (1.9.10)
ffi (1.9.10-x86-mingw32)
ffi-yajl (2.2.3)
libyajl2 (~> 1.2)
Expand Down Expand Up @@ -365,8 +339,6 @@ GEM
yajl-ruby (~> 1.1)
formatador (0.2.5)
fuzzyurl (0.8.0)
gherkin (2.12.2)
multi_json (~> 1.3)
gherkin (2.12.2-x86-mingw32)
multi_json (~> 1.3)
git (1.3.0)
Expand Down Expand Up @@ -419,7 +391,6 @@ GEM
builder (>= 2.1.2)
hashie (3.4.3)
highline (1.7.8)
hitimes (1.2.3)
hitimes (1.2.3-x86-mingw32)
httpclient (2.7.1)
i18n (0.7.0)
Expand Down Expand Up @@ -486,7 +457,6 @@ GEM
mixlib-config (2.2.1)
mixlib-install (0.7.1)
mixlib-log (1.6.0)
mixlib-shellout (2.2.6)
mixlib-shellout (2.2.6-universal-mingw32)
win32-process (~> 0.8.2)
wmi-lite (~> 1.0)
Expand All @@ -505,8 +475,6 @@ GEM
net-ssh-gateway (>= 1.2.0)
net-telnet (0.1.1)
nio4r (1.2.1)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.7.2-x86-mingw32)
mini_portile2 (~> 2.0.0.rc2)
nori (2.6.0)
Expand Down Expand Up @@ -625,6 +593,7 @@ GEM
unicode-display_width (~> 0.3)
ruby-prof (0.15.9)
ruby-progressbar (1.7.5)
ruby-shadow (2.5.0)
rubyntlm (0.6.0)
rubyzip (1.2.0)
rufus-lru (1.0.5)
Expand Down Expand Up @@ -724,15 +693,14 @@ GEM
yard (0.8.7.6)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
CFPropertyList (= 2.3.2)
activesupport (= 4.2.6)
addressable (= 2.4.0)
app_conf (= 0.4.2)
appbundler (= 0.8.0)
appbundler!
ast (= 2.2.0)
autoparse (= 0.3.3)
aws-sdk (= 2.2.31)
Expand All @@ -748,12 +716,13 @@ DEPENDENCIES
buff-ruby_engine (= 0.1.0)
buff-shell_out (= 0.2.0)
builder (= 3.2.2)
bundler (= 1.11.2)
byebug (= 8.2.2)
celluloid (= 0.16.0)
celluloid-io (= 0.16.2)
chef (= 12.9.7)
chef-config (= 12.9.7)
chef-dk (= 0.13.4)
chef!
chef-config!
chef-dk!
chef-provisioning (= 1.6.0)
chef-provisioning-aws (= 1.8.0)
chef-provisioning-azure (= 0.5.0)
Expand Down Expand Up @@ -912,6 +881,7 @@ DEPENDENCIES
rubocop (= 0.37.2)
ruby-prof (= 0.15.9)
ruby-progressbar (= 1.7.5)
ruby-shadow (= 2.5.0)
rubyntlm (= 0.6.0)
rubyzip (= 1.2.0)
rufus-lru (= 1.0.5)
Expand Down
2 changes: 1 addition & 1 deletion chef-dk.gemspec
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |gem|
gem.files = %w(Rakefile LICENSE README.md CONTRIBUTING.md warning.txt) +
Dir.glob("Gemfile*") + # Includes Gemfile and locks
Dir.glob("*.gemspec") +
Dir.glob("{lib,spec,acceptance}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
Dir.glob("{lib,spec,acceptance,tasks}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
gem.executables = %w( chef )
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
Expand Down
6 changes: 6 additions & 0 deletions omnibus/config/software/chef-dk-gem-ruby-shadow.rb
@@ -0,0 +1,6 @@
# gem installs this gem from the version specified in chef-dk's Gemfile.lock
# so we can take advantage of omnibus's caching. Just duplicate this file and
# add the new software def to chef-dk software def if you want to separate
# another gem's installation.
require_relative "../../files/chef-dk-gem/build-chef-dk-gem/gem-install-software-def"
BuildChefDKGem::GemInstallSoftwareDef.define(self, __FILE__)
4 changes: 3 additions & 1 deletion omnibus/config/software/chef-dk.rb
Expand Up @@ -62,7 +62,9 @@
chefdk_build_env["BUNDLE_GEMFILE"] = chefdk_gemfile

# Prepare to install: build config, retries, job, frozen=true
create_bundle_config(chefdk_gemfile, retries: 4, jobs: 4, frozen: true)
# TODO Windows install seems to sometimes install already-installed gems such
# as gherkin (and fail as a result) if you use jobs: 4.
create_bundle_config(chefdk_gemfile, retries: 4, jobs: 1, frozen: true)

# Install all the things. Arguments are specified in .bundle/config (see create_bundle_config)
bundle "install --verbose", env: chefdk_build_env
Expand Down
Expand Up @@ -63,19 +63,21 @@ def root_path

def gemfile_path
# gemfile path could be relative to software filename (and often is)
@gemfile_path ||= File.join(root_path, "Gemfile")
end

def lockfile_path
@lockfile_path ||= begin
@gemfile_path ||= begin
# Grab the version (and maybe source) from the lockfile so omnibus knows whether
# to toss the cache or not
lockfile_path = "#{gemfile_path}.#{Omnibus::Ohai["platform"]}.lock"
unless File.exist?(lockfile_path)
lockfile_path = "#{gemfile_path}.lock"
gemfile_path = File.join(root_path, "Gemfile")
platform_gemfile_path = "#{gemfile_path}.#{Omnibus::Ohai["platform"]}"
if File.exist?(platform_gemfile_path)
gemfile_path = platform_gemfile_path
end
lockfile_path
gemfile_path
end

end

def lockfile_path
@lockfile_path ||= "#{gemfile_path}.lock"
end

def gem_name
Expand All @@ -93,10 +95,16 @@ def gem_name

def gemspec
@gemspec ||= begin
lockfile = Bundler::LockfileParser.new(IO.read(lockfile_path))
gemspec = lockfile.specs.find { |s| s.name == gem_name }
raise "#{gem_name} not found in #{lockfile_path}" unless gemspec
gemspec
old_frozen = Bundler.settings[:frozen]
Bundler.settings[:frozen] = true
begin
bundle = Bundler::Definition.build(gemfile_path, lockfile_path, nil)
gemspec = bundle.resolve.find { |spec| spec.name == gem_name }
raise "#{gem_name} not found in #{lockfile_path}" unless gemspec
gemspec
ensure
Bundler.settings[:frozen] = old_frozen
end
end
end

Expand Down

0 comments on commit 57f5670

Please sign in to comment.