Skip to content

Commit

Permalink
(maint) Relax gem dependencies for Windows
Browse files Browse the repository at this point in the history
The version of Puppet/Facter/Hiera will determine the exact versions
of the Windows gems, so relax the versioning a bit to allow for the
proper versions of gems to be pulled in.

Explicitly determine when we need to require Windows gems, which is
when we are using a git or file location for Puppet, or are requiring
a Puppet version less than 3.5.0 (the first versions we had Windows
platform specific gems).
  • Loading branch information
ferventcoder committed Jul 2, 2015
1 parent 0210070 commit 806c3f6
Showing 1 changed file with 76 additions and 25 deletions.
101 changes: 76 additions & 25 deletions Gemfile
@@ -1,12 +1,30 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

def location_for(place, fake_version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
# Determines what type of gem is requested based
# on place_or_version.
def gem_type(place_or_version)
if place_or_version =~ /^git:/
:git
elsif place_or_version =~ /^file:/
:file
else
:gem
end
end

# Find a location or specific version for a gem.
# place_or_version can be a version, which is most
# often used. It can also be git, which is
# specified as `git://somewhere.git#branch`. You
# can also use a file source location, which is
# specified as `file://some/location/on/disk`.
def location_for(place_or_version, fake_version = nil)
if place_or_version =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
elsif place =~ /^file:\/\/(.*)/
elsif place_or_version =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
else
[place, { :require => false }]
[place_or_version, { :require => false }]
end
end

Expand All @@ -28,31 +46,64 @@ group :system_tests do
gem 'beaker-puppet_install_helper', :require => false
end

is_x64 = Gem::Platform.local.cpu == 'x64'
if is_x64
platform(:x64_mingw) do
gem "win32-dir", "~> 0.4.9", :require => false
gem "win32-process", "~> 0.7.4", :require => false
gem "win32-service", "~> 0.8.4", :require => false
gem "minitar", "~> 0.5.4", :require => false
end
else
platform(:mingw) do
gem "win32-process", "~> 0.6.5", :require => false
gem "win32-service", "~> 0.7.2", :require => false
gem "minitar", "~> 0.5.4", :require => false
if RUBY_VERSION =~ /^1\./ then
gem "win32console", :require => false
# The recommendation is for PROJECT_GEM_VERSION,
# there are older ways of referencing these. Add
# them all for compatibility reasons. Remove
# later when no issues are known
puppetversion = ENV['PUPPET_GEM_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_LOCATION'] || '>= 0'
gem 'puppet', *location_for(puppetversion)
puppet_gem_location = gem_type(puppetversion)

if puppet_gem_location != :gem
gem "facter", *location_for(ENV['FACTER_GEM_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_LOCATION'] || '>= 0')
gem "hiera", *location_for(ENV['HIERA_GEM_VERSION'] || ENV['GEM_HIERA_VERSION'] || ENV['HIERA_LOCATION'] || '>= 0')
end

# For Windows dependencies, these could be required
# based on the version of Puppet you are requiring.
# Anything greater than v3.5.0 is going to have
# Windows-specific dependencies dictated by the gem
# itself.
# The other scenario is when you are faking out the
# Puppet Gem to use a local file path / git path.
explicitly_require_windows_gems = false
# This is not a perfect answer to the version check
if puppet_gem_location != :gem || puppetversion < '3.5.0'
is_x64 = Gem::Platform.local.cpu == 'x64'
if is_x64
platform(:x64_mingw) do
explicitly_require_windows_gems = true
end
else
platform (:mingw) do
explicitly_require_windows_gems = true
end
end
end

ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION']
puppetversion = ENV['GEM_PUPPET_VERSION']
if puppetversion
gem 'puppet', *location_for(puppetversion)
else
gem 'puppet', :require => false
if explicitly_require_windows_gems
gem "ffi", "~> 1.9.0", :require => false
gem "win32-dir", "~> 0.3", :require => false
gem "win32-eventlog", "~> 0.5", :require => false
gem "win32-process", "~> 0.6", :require => false
gem "win32-security", "~> 0.1", :require => false
gem "win32-service", "~> 0.7", :require => false
gem "minitar", "~> 0.5.4", :require => false

if RUBY_VERSION =~ /^1\./ then
gem "win32console", :require => false
end

# Puppet less than 3.7.0 requires these
# granted anything over 3.5 won't make it in
# here anyway
if puppetversion < '3.7.0'
gem "sys-admin", "~> 1.5.6", :require => false
gem "win32-api", "~> 1.4.8", :require => false
gem "win32-taskscheduler", "~> 0.2", :require => false
gem "windows-api", "~> 0.4", :require => false
gem "windows-pr", "~> 1.2", :require => false
end
end

if File.exists? "#{__FILE__}.local"
Expand Down

0 comments on commit 806c3f6

Please sign in to comment.