-
Notifications
You must be signed in to change notification settings - Fork 143
/
Gemfile.erb
136 lines (115 loc) · 3.84 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
131
132
133
134
135
136
<%
def gem_length(gem)
if gem['version']
gem_output = ''
Array(gem['version']).each do |version|
gem_output += " '#{version}',"
end
gem_output = gem_output.chomp(',')
if gem['from_env']
version_len = " *location_for(ENV['#{gem['from_env']}'])".length + " ||#{gem_output}".length
else
version_len = ",#{gem_output}".length
end
else
version_len = 0
end
gem['gem'].length + version_len
end
def gem_spec(gem, max_len)
output = "\"#{gem['gem']}\""
if gem['version']
gem_output = ''
# For each version requirement given add to the string and place a `,`
Array(gem['version']).each do |version|
gem_output += " '#{version}',"
end
gem_output = gem_output.chomp(',')
if gem['from_env']
output += ", *location_for(ENV['#{gem['from_env']}'] ||#{gem_output})"
else
output += ",#{gem_output}"
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?
options << "source: #{gem['source'].inspect}" unless gem['source'].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
<%
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 = @configs['overrides']&.find { |prefer| prefer['gem'] == gem['gem'] } || 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'],
'source' => gem['source'],
}
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
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