-
Notifications
You must be signed in to change notification settings - Fork 143
/
Gemfile.erb
130 lines (108 loc) · 3.9 KB
/
Gemfile.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<%
def gem_length(gem)
if gem['from_env']
version_len = " *location_for(ENV['#{gem['from_env']}'])".length + ((" || '#{gem['version']}'".length if gem['version']) || 0)
else
version_len = (", '#{gem['version']}'".length if gem['version']) || 0
end
gem['gem'].length + version_len
end
def gem_spec(gem, max_len)
output = "\"#{gem['gem']}\""
if gem['version']
if gem['from_env']
output += ", *location_for(ENV['#{gem['from_env']}'] || '#{gem['version']}')"
else
output += ", '#{gem['version']}'"
end
end
options = []
options << "require: false" if gem['from_env'].nil?
options << "git: '#{gem['git']}'" unless gem['git'].nil?
options << "branch: '#{gem['branch']}'" unless gem['branch'].nil?
options << "ref: '#{gem['ref']}'" unless gem['ref'].nil?
options << "platforms: #{gem['platforms'].inspect}" unless gem['platforms'].nil?
unless options.empty?
output += ', '
output += ' ' * (max_len - gem['length'])
output += options.join(', ')
end
output += " if #{gem['condition']}" unless gem['condition'].nil?
output
end
-%>
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
def location_for(place_or_version, fake_version = nil)
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
file_url_regex = %r{\Afile:\/\/(?<path>.*)}
if place_or_version && (git_url = place_or_version.match(git_url_regex))
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
else
[place_or_version, { require: false }]
end
end
ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
minor_version = ruby_version_segments[0..1].join('.')
<%
groups = {}
(@configs['required'].keys + ((@configs['optional'] || {}).keys)).uniq.each do |key|
groups[key] = (@configs['required'][key] || []) + ((@configs['optional'] || {})[key] || [])
end
-%>
<% groups.each do |group, gems| -%>
group <%= group %> do
<%
gems.map! do |gem|
{
'gem' => gem['gem'],
'version' => gem['version'],
'platforms' => gem['platforms'].nil? ? nil : Array[*gem['platforms']].map(&:to_sym),
'git' => gem['git'],
'branch' => gem['branch'],
'ref' => gem['ref'],
'length' => gem_length(gem),
'from_env' => gem['from_env'],
'condition' => gem['condition'],
}
end
maxlen = gems.map { |r| r['length'] }.max
-%>
<% gems.each do |gem| -%>
gem <%= gem_spec(gem, maxlen) %>
<% end -%>
end
<% end -%>
puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']
gems = {}
gems['puppet'] = location_for(puppet_version)
# If facter or hiera versions have been specified via the environment
# variables
gems['facter'] = location_for(facter_version) if facter_version
gems['hiera'] = location_for(hiera_version) if hiera_version
if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)}
# If we're using a Puppet gem on Windows which handles its own win32-xxx gem
# dependencies (>= 3.5.0), set the maximum versions (see PUP-6445).
gems['win32-dir'] = ['<= 0.4.9', require: false]
gems['win32-eventlog'] = ['<= 0.6.5', require: false]
gems['win32-process'] = ['<= 0.7.5', require: false]
gems['win32-security'] = ['<= 0.2.5', require: false]
gems['win32-service'] = ['0.8.8', require: false]
end
gems.each do |gem_name, gem_params|
gem gem_name, *gem_params
end
# Evaluate Gemfile.local and ~/.gemfile if they exist
extra_gemfiles = [
"#{__FILE__}.local",
File.join(Dir.home, '.gemfile'),
]
extra_gemfiles.each do |gemfile|
if File.file?(gemfile) && File.readable?(gemfile)
eval(File.read(gemfile), binding)
end
end
# vim: syntax=ruby