simp-rake-helpers 4.1.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,7 +110,7 @@ module Simp::Rake::Build::RpmDeps
110
110
 
111
111
  begin
112
112
  rpm_metadata_content << get_version_requires(pkg, dep_version)
113
- rescue SIMPRpmDepVersionException => e
113
+ rescue SIMPRpmDepVersionException
114
114
  err_msg = "Unable to parse #{short_names.first} dependency" +
115
115
  " version '#{dep_version}'"
116
116
  raise SIMPRpmDepException.new(err_msg)
@@ -141,7 +141,7 @@ module Simp::Rake::Build::RpmDeps
141
141
 
142
142
  begin
143
143
  rpm_metadata_content << get_version_requires(pkg, dep_version)
144
- rescue SIMPRpmDepVersionException => e
144
+ rescue SIMPRpmDepVersionException
145
145
  err_msg = "Unable to parse #{dep['name']} dependency" +
146
146
  " version '#{dep_version}'"
147
147
  raise SIMPRpmDepException.new(err_msg)
@@ -10,7 +10,6 @@ module Simp::Rake::Build
10
10
  def initialize( base_dir )
11
11
  init_member_vars( base_dir )
12
12
 
13
- @mock = ENV['mock'] || '/usr/bin/mock'
14
13
  define_tasks
15
14
  end
16
15
 
@@ -23,8 +22,10 @@ module Simp::Rake::Build
23
22
  end
24
23
 
25
24
 
25
+ =begin
26
26
  desc "Bump spec files. Bump all spec files' release numbers up by one.
27
27
  * :list - Flag to just print the current version numbers."
28
+ =end
28
29
  task :bump,[:list] => [:prep] do |t,args|
29
30
  (
30
31
  Dir.glob("#{@spec_dir}/*.spec") +
@@ -32,7 +32,8 @@ module Simp::Rake::Build
32
32
  def get_simp_version
33
33
  simp_rpm = Dir.glob("#{@build_dir}/SIMP/RPMS/*/simp-[0-9]*.rpm").max_by {|f| File.mtime(f)}
34
34
  fail("Could not find simp main RPM in output directory!") unless simp_rpm
35
- simp_version = File.basename(simp_rpm).gsub(".noarch.rpm","").gsub("simp-","")
35
+
36
+ simp_version = Simp::RPM.new(simp_rpm).full_version
36
37
 
37
38
  # For picking up the correct RPM template
38
39
  ENV['SIMP_BUILD_version'] ||= simp_version
@@ -45,10 +46,6 @@ module Simp::Rake::Build
45
46
  ##############################################################################
46
47
 
47
48
  task :validate => [:prep] do |t,args|
48
- rpm_dir = File.join(@build_dir,'SIMP','RPMS')
49
-
50
- fail("Could not find output dir: '#{rpm_dir}'") unless File.directory?(rpm_dir)
51
-
52
49
  required_rpms = {
53
50
  'noarch' => [
54
51
  'rubygem-simp-cli',
@@ -59,10 +56,13 @@ module Simp::Rake::Build
59
56
  ]
60
57
  }
61
58
 
59
+ rpm_dir = File.join(@build_dir,'SIMP','RPMS')
60
+ fail("Could not find directory '#{rpm_dir}'") unless File.directory?(rpm_dir)
61
+
62
62
  Dir.chdir(rpm_dir) do
63
63
  failures = []
64
64
  required_rpms.keys.each do |dir|
65
- fail("Could not find directory '#{File.join(rpm_dir,dir)}'") unless File.directory?(dir)
65
+ fail("Could not find directory '#{File.join(rpm_dir, dir)}'") unless File.directory?(dir)
66
66
 
67
67
  Dir.chdir(dir) do
68
68
  required_rpms[dir].each do |pkg|
@@ -85,19 +85,17 @@ module Simp::Rake::Build
85
85
  end
86
86
  end
87
87
 
88
+ =begin
88
89
  desc <<-EOM
89
90
  Build the DVD tarball(s).
90
91
 
91
- * :chroot - The mock chroot to use for pkg:build
92
92
  * :key - What key to use for signing the RPMs
93
93
  * :docs - Whether or not to build the documentation
94
- * :snapshot_release - Append the timestamp to the SIMP tarball(s)
95
94
  EOM
96
- task :build,[:chroot,:key,:docs,:snapshot_release] => ['pkg:build','pkg:checksig','tar:validate'] do |t,args|
95
+ =end
96
+ task :build,[:key,:docs] => ['pkg:build','pkg:checksig','tar:validate'] do |t,args|
97
97
  args.with_defaults(:docs => 'true')
98
98
 
99
- validate_in_mock_group?
100
-
101
99
  if $tarball_tgt
102
100
  target_dists = ['simp6']
103
101
  else
@@ -161,7 +159,7 @@ module Simp::Rake::Build
161
159
  raise(StandardError,"Error: Could not find simp-doc*.rpm in the build, something went very wrong")
162
160
  end
163
161
 
164
- Dir.mktmpdir { |dir|
162
+ Dir.mktmpdir do |dir|
165
163
  Dir.chdir(dir) do
166
164
  %x{rpm2cpio #{simp_doc_rpm} | cpio -u --quiet --warning none -ivd ./usr/share/doc/simp-*/pdf/SIMP*.pdf 2>&1 > /dev/null}
167
165
  pdf_docs = Dir.glob("usr/share/doc/simp-*/pdf/*.pdf")
@@ -174,7 +172,7 @@ module Simp::Rake::Build
174
172
  cp(pdf,base_dir)
175
173
  end
176
174
  end
177
- }
175
+ end
178
176
  end
179
177
  end
180
178
  end
@@ -11,13 +11,13 @@ module Simp::Rake::Build
11
11
  def initialize( base_dir )
12
12
  init_member_vars( base_dir )
13
13
 
14
- @mock = ENV['mock'] || '/usr/bin/mock'
15
14
  define_tasks
16
15
  end
17
16
 
18
17
  def define_tasks
19
18
  #!/usr/bin/rake -T
20
19
 
20
+ =begin
21
21
  desc "Unpack an ISO. Unpacks either a RHEL or CentOS ISO into
22
22
  <targetdir>/<RHEL|CentOS><version>-<arch>.
23
23
  * :iso_path - Full path to the ISO image to unpack.
@@ -30,6 +30,7 @@ module Simp::Rake::Build
30
30
  * :version - optional override for the <version> number (e.g., '7.0' instead of '7')
31
31
 
32
32
  "
33
+ =end
33
34
  task :unpack,[:iso_path, :merge, :targetdir, :isoinfo, :version] do |t,args|
34
35
  args.with_defaults(
35
36
  :iso_path => '',
@@ -13,7 +13,6 @@ module Simp::Rake::Build
13
13
  def initialize( base_dir )
14
14
  init_member_vars( base_dir )
15
15
 
16
- @mock = ENV['mock'] || '/usr/bin/mock'
17
16
  define_tasks
18
17
  end
19
18
 
@@ -112,11 +111,13 @@ module Simp::Rake::Build
112
111
  return pkg_info
113
112
  end
114
113
 
114
+ =begin
115
115
  desc <<-EOM
116
116
  Get a list of modified packages.
117
117
 
118
118
  The package list is created from the given date or git identifier (tag, branch, or hash)
119
119
  EOM
120
+ =end
120
121
  task :get_modified,[:start,:script_format] => [:prep] do |t,args|
121
122
  args.with_defaults(:script_format => false)
122
123
 
@@ -14,4 +14,27 @@ class Simp::Rake::Helpers
14
14
  Simp::Rake::Fixtures.new( dir )
15
15
  end
16
16
 
17
+ def self.check_required_commands(required_commands)
18
+ require 'facter'
19
+
20
+ invalid_commands = Array.new
21
+
22
+ Array(required_commands).each do |command|
23
+ unless Facter::Core::Execution.which(command)
24
+ invalid_commands << command
25
+ end
26
+ end
27
+
28
+ unless invalid_commands.empty?
29
+ errmsg = <<-EOM
30
+ Error: The following required commands were not found on your system:
31
+
32
+ * #{invalid_commands.join("\n * ")}
33
+
34
+ Please update your system and try again.
35
+ EOM
36
+
37
+ raise(errmsg)
38
+ end
39
+ end
17
40
  end
@@ -2,5 +2,5 @@ module Simp; end
2
2
  module Simp::Rake; end
3
3
 
4
4
  class Simp::Rake::Helpers
5
- VERSION = '4.1.1'
5
+ VERSION = '5.0.0'
6
6
  end
data/lib/simp/rake/pkg.rb CHANGED
@@ -24,7 +24,7 @@ module Simp::Rake
24
24
  # path to the project's RPM specfile
25
25
  attr_accessor :spec_file
26
26
 
27
- # path to the directory to place generated assets (e.g., rpm, srpm, tar.gz)
27
+ # path to the directory to place generated assets (e.g., rpm, tar.gz)
28
28
  attr_accessor :pkg_dir
29
29
 
30
30
  # array of items to exclude from the tarball
@@ -38,26 +38,28 @@ module Simp::Rake
38
38
 
39
39
  attr_reader :spec_info
40
40
 
41
- def initialize( base_dir, unique_name=nil, unique_namespace=nil, simp_version=nil )
41
+ def initialize( base_dir, unique_namespace = nil, simp_version=nil )
42
42
  @base_dir = base_dir
43
43
  @pkg_name = File.basename(@base_dir)
44
44
  @pkg_dir = File.join(@base_dir, 'dist')
45
45
  @pkg_tmp_dir = File.join(@pkg_dir, 'tmp')
46
- @pkg_stash_dir = File.join(@pkg_tmp_dir, '.stash')
47
46
  @exclude_list = [ File.basename(@pkg_dir) ]
48
47
  @clean_list = []
49
48
  @ignore_changes_list = [
50
49
  'Gemfile.lock',
50
+ 'dist/logs',
51
+ 'dist/tmp',
52
+ 'dist/*.rpm',
53
+ 'dist/rpmbuild',
51
54
  'spec/fixtures/modules'
52
55
  ]
53
- @chroot_name = unique_name
56
+
57
+ FileUtils.mkdir_p(@pkg_tmp_dir)
54
58
 
55
59
  local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
56
60
  unless local_spec.empty?
57
61
  @spec_file = local_spec.first
58
62
  else
59
- FileUtils.mkdir_p(@pkg_stash_dir) unless File.directory?(@pkg_stash_dir)
60
-
61
63
  @spec_tempfile = File.open(File.join(@pkg_tmp_dir, "#{@pkg_name}.spec"), 'w')
62
64
  @spec_tempfile.write(rpm_template(simp_version))
63
65
 
@@ -73,11 +75,10 @@ module Simp::Rake
73
75
  # LUA-based RPM template
74
76
 
75
77
  @puppet_module_info_files = [
76
- @spec_file,
77
- %(#{@base_dir}/build),
78
+ Dir.glob(%(#{@base_dir}/build/rpm_metadata/*)),
78
79
  %(#{@base_dir}/CHANGELOG),
79
80
  %(#{@base_dir}/metadata.json)
80
- ]
81
+ ].flatten
81
82
 
82
83
  ::CLEAN.include( @pkg_dir )
83
84
 
@@ -102,94 +103,46 @@ module Simp::Rake
102
103
  define_clean
103
104
  define_clobber
104
105
  define_pkg_tar
105
- define_pkg_srpm
106
106
  define_pkg_rpm
107
- define_pkg_scrub
108
107
  define_pkg_check_version
109
108
  task :default => 'pkg:tar'
110
109
 
111
- Rake::Task['pkg:tar'].enhance(['pkg:restore_stash'])
112
- Rake::Task['pkg:srpm'].enhance(['pkg:restore_stash'])
113
- Rake::Task['pkg:rpm'].enhance(['pkg:restore_stash'])
110
+ Rake::Task['pkg:tar']
111
+ Rake::Task['pkg:rpm']
114
112
 
115
113
  self
116
114
  end
117
115
 
118
- # Add a file to the pkg stash
119
- # These will be restored to the @pkg_dir at the end of the run
120
- def stash(file)
121
- FileUtils.mv(file, @pkg_stash_dir)
122
- end
123
-
124
- # Restore everything from the stash dir
125
- def restore_stash
126
- Dir.glob(File.join(@pkg_stash_dir, '*')).each do |file|
127
- FileUtils.mv(file, @pkg_dir)
128
- end
129
- end
130
-
131
- # Initialize the mock space if passed and retrieve the spec info from that
132
- # space directly.
133
- #
134
116
  # Ensures that the correct file names are used across the board.
135
- def initialize_spec_info(chroot, unique='false')
117
+ def initialize_spec_info
136
118
  unless @spec_info
137
119
  # This gets the resting spec file and allows us to pull out the name
138
- @spec_info = Simp::RPM.get_info(@spec_file)
139
- @spec_info_dir = @base_dir
120
+ @spec_info ||= Simp::RPM.new(@spec_file)
121
+ @spec_info_dir ||= @base_dir
140
122
 
141
- if chroot
142
- @chroot_name = @chroot_name || "#{@spec_info[:name]}__#{ENV.fetch( 'USER', 'USER' )}"
123
+ @dir_name ||= "#{@spec_info.basename}-#{@spec_info.version}"
124
+ @full_pkg_name ||= "#{@dir_name}-#{@spec_info.release}"
143
125
 
144
- if ENV['SIMP_PKG_rand_name'] && (ENV['SIMP_PKG_rand_name'] != 'no')
145
- @chroot_name = @chroot_name + '__' + Time.now.strftime('%s%L')
146
- end
147
-
148
- if @spec_info[:has_dist_tag]
149
- mock_cmd = mock_pre_check( chroot, @chroot_name, unique ) + " --root #{chroot}"
150
-
151
- # Need to do this in case there is already a directory in /tmp
152
- rand_dirname = (0...10).map { ('a'..'z').to_a[rand(26)] }.join
153
- rand_tmpdir = %(/tmp/#{rand_dirname}_tmp)
154
-
155
- # Hack to work around the fact that we have conflicting '-D' entries
156
- # TODO: Refactor this
157
- mock_cmd = mock_cmd.split(/-D '.*?'/).join
158
- mock_cmd = "#{mock_cmd} -D 'pup_module_info_dir #{rand_tmpdir}'"
126
+ _rpmbuild_srcdir = `rpm -E '%{_sourcedir}'`.strip
159
127
 
160
- sh %Q(#{mock_cmd} --chroot 'mkdir -p #{rand_tmpdir}')
161
-
162
- @puppet_module_info_files.each do |copy_in|
163
- if File.exist?(copy_in)
164
- sh %Q(#{mock_cmd} --copyin #{copy_in} #{rand_tmpdir})
165
- end
166
- end
167
-
168
- sh %Q(#{mock_cmd} --chroot 'chmod -R ugo+rwX #{rand_tmpdir}')
169
-
170
- info_hash = {
171
- :command => %Q(#{mock_cmd} --chroot --cwd='#{rand_tmpdir}'),
172
- :rpm_extras => %(--specfile #{rand_tmpdir}/#{File.basename(@spec_file)} )
173
- }
174
-
175
- @spec_info = Simp::RPM.get_info(@spec_file, info_hash)
176
- end
128
+ unless File.exist?(_rpmbuild_srcdir)
129
+ sh 'rpmdev-setuptree'
177
130
  end
178
131
 
179
- @dir_name = "#{@spec_info[:name]}-#{@spec_info[:version]}"
180
- _full_pkg_name = "#{@dir_name}-#{@spec_info[:release]}"
181
- @full_pkg_name = _full_pkg_name.gsub("%{?snapshot_release}","")
182
- @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
132
+ @rpm_srcdir ||= "#{@pkg_dir}/rpmbuild/SOURCES"
133
+ FileUtils.mkdir_p(@rpm_srcdir)
134
+
135
+ @tar_dest ||= "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
183
136
 
184
- if @tar_dest =~ /UNKNOWN/
185
- fail("Error: Could not determine package information from 'metadata.json'. Got '#{File.basename(@tar_dest)}'")
137
+ if @full_pkg_name =~ /UNKNOWN/
138
+ fail("Error: Could not determine package information from 'metadata.json'. Got '#{@full_pkg_name}'")
186
139
  end
187
140
  end
188
141
  end
189
142
 
190
143
  def define_clean
191
144
  desc <<-EOM
192
- Clean build artifacts for #{@pkg_name} (except for mock)
145
+ Clean build artifacts for #{@pkg_name}
193
146
  EOM
194
147
  task :clean do |t,args|
195
148
  # this is provided by 'rake/clean' and the ::CLEAN constant
@@ -198,7 +151,7 @@ module Simp::Rake
198
151
 
199
152
  def define_clobber
200
153
  desc <<-EOM
201
- Clobber build artifacts for #{@pkg_name} (except for mock)
154
+ Clobber build artifacts for #{@pkg_name}
202
155
  EOM
203
156
  task :clobber do |t,args|
204
157
  end
@@ -208,47 +161,21 @@ module Simp::Rake
208
161
  namespace :pkg do
209
162
  directory @pkg_dir
210
163
 
211
- task :restore_stash do |t,args|
212
- at_exit { restore_stash }
213
- end
214
-
215
- task :initialize_spec_info,[:chroot,:unique] => [@pkg_dir] do |t,args|
216
- args.with_defaults(:chroot => nil)
217
- args.with_defaults(:unique => false)
218
-
219
- initialize_spec_info(args[:chroot], args[:unique])
164
+ task :initialize_spec_info => [@pkg_dir] do |t,args|
165
+ initialize_spec_info
220
166
  end
221
167
 
222
168
  # :pkg:tar
223
169
  # -----------------------------
224
170
  desc <<-EOM
225
171
  Build the #{@pkg_name} tar package.
226
- * :snapshot_release - Add snapshot_release (date and time) to rpm
227
- version, rpm spec file must have macro for
228
- this to work.
229
172
  EOM
230
- task :tar,[:chroot,:unique,:snapshot_release] => [:initialize_spec_info] do |t,args|
231
- args.with_defaults(:snapshot_release => 'false')
232
- args.with_defaults(:chroot => nil)
233
- args.with_defaults(:unique => 'false')
234
-
235
- l_date = ''
236
- if args[:snapshot_release] == 'true'
237
- l_date = '.' + "#{TIMESTAMP}"
238
- @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
239
- end
240
-
241
- # Remove any tar files that are not from this version
242
- tar_files = Dir.glob(%(#{@pkg_dir}/#{@spec_info[:name]}-#{@spec_info[:version]}*.tar.gz))
243
- tar_files.delete(@tar_dest)
244
- tar_files.each do |tf|
245
- stash(tf)
246
- end
247
-
173
+ task :tar => [:initialize_spec_info] do |t,args|
248
174
  target_dir = File.basename(@base_dir)
249
175
 
250
176
  Dir.chdir(%(#{@base_dir}/..)) do
251
177
  require_rebuild = false
178
+
252
179
  if File.exist?(@tar_dest)
253
180
  Find.find(target_dir) do |path|
254
181
  filename = File.basename(path)
@@ -261,7 +188,7 @@ module Simp::Rake
261
188
 
262
189
  next if File.directory?(path)
263
190
 
264
- unless uptodate?(@tar_dest,[path])
191
+ if require_rebuild?(@tar_dest, path)
265
192
  require_rebuild = true
266
193
  break
267
194
  end
@@ -278,156 +205,180 @@ module Simp::Rake
278
205
  end
279
206
  end
280
207
 
281
- def define_pkg_srpm
208
+ def define_pkg_rpm
282
209
  namespace :pkg do
283
210
  desc <<-EOM
284
- Build the #{@pkg_name} SRPM.
285
- Building RPMs requires a working Mock setup (http://fedoraproject.org/wiki/Projects/Mock)
286
- * :chroot - The Mock chroot configuration to use. See the '--root' option in mock(1)."
287
- * :unique - Whether or not to build the SRPM in a unique Mock environment.
288
- This can be very useful for parallel builds of all modules.
289
- * :snapshot_release - Add snapshot_release (date and time) to rpm version.
290
- Rpm spec file must have macro for this to work.
211
+ Build the #{@pkg_name} RPM.
291
212
 
292
213
  By default, the package will be built to support a SIMP-6.X file structure.
293
214
  To build the package for a different version of SIMP, export SIMP_BUILD_version=<5.X,4.X>
294
- EOM
295
- task :srpm,[:chroot,:unique,:snapshot_release] => [:tar] do |t,args|
296
- args.with_defaults(:unique => 'false')
297
- args.with_defaults(:snapshot_release => 'false')
298
-
299
- l_date = ''
300
- if args[:snapshot_release] == 'true'
301
- l_date = '.' + "#{TIMESTAMP}"
302
- mocksnap = "-D 'snapshot_release #{l_date}'"
303
- @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
304
- end
215
+ EOM
216
+ task :rpm => [:tar] do |t,args|
217
+ rpm_opts = [
218
+ %(-D 'buildroot #{@pkg_dir}/rpmbuild/BUILDROOT'),
219
+ %(-D 'builddir #{@pkg_dir}/rpmbuild/BUILD'),
220
+ %(-D '_sourcedir #{@rpm_srcdir}'),
221
+ %(-D '_rpmdir #{@pkg_dir}'),
222
+ %(-D '_srcrpmdir #{@pkg_dir}'),
223
+ %(-D '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm')
224
+ ]
225
+
226
+ Dir.chdir(@pkg_dir) do
227
+
228
+ # Copy in the materials required for the module builds
229
+ @puppet_module_info_files.each do |f|
230
+ if File.exist?(f)
231
+ FileUtils.cp_r(f, @rpm_srcdir)
232
+ end
233
+ end
305
234
 
306
- srpms = Dir.glob(%(#{@pkg_dir}/#{@spec_info[:name]}*-#{@spec_info[:version]}-*#{l_date}*.src.rpm))
235
+ # Link in any misc artifacts that got dumped into 'dist' by other code
236
+ extra_deps = Dir.glob("*")
237
+ extra_deps.delete_if{|x| x =~ /(\.rpm$|(^(rpmbuild|logs|tmp$)))/}
307
238
 
308
- # Get rid of any SRPMs that are not of this distribution build if we
309
- # have found one
310
- if @spec_info[:dist_tag]
311
- srpms.delete_if do |srpm|
312
- if srpm.split(@spec_info[:dist_tag]).last != '.src.rpm'
313
- if File.exist?(srpm)
314
- stash(srpm)
239
+ Dir.chdir(@rpm_srcdir) do
240
+ extra_deps.each do |dep|
241
+ unless File.exist?(dep)
242
+ FileUtils.cp_r("../../#{dep}", dep)
315
243
  end
316
-
317
- true
318
- else
319
- false
320
244
  end
321
245
  end
322
- end
323
-
324
- if require_rebuild?(srpms, @tar_dest)
325
246
 
326
- mock_cmd = mock_pre_check( args[:chroot], @chroot_name, args[:unique] )
247
+ FileUtils.mkdir_p('logs')
248
+ FileUtils.mkdir_p('rpmbuild/BUILDROOT')
249
+ FileUtils.mkdir_p('rpmbuild/BUILD')
327
250
 
328
- @puppet_module_info_files.each do |file|
329
- next unless File.exist?(file)
251
+ srpms = [@full_pkg_name + '.src.rpm']
252
+ if require_rebuild?(srpms.first, @tar_dest)
253
+ # Need to build the SRPM so that we can get the build dependencies
254
+ %x(rpmbuild #{rpm_opts.join(' ')} -bs #{@spec_file} > logs/build.out 2> logs/build.err)
330
255
 
331
- Find.find(file) do |path|
332
- next if File.directory?(path)
256
+ srpms = File.read('logs/build.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten
333
257
 
334
- tgt_file = File.join(@pkg_dir, File.basename(path))
335
- FileUtils.remove_entry_secure(tgt_file) if File.exist?(tgt_file)
336
- FileUtils.cp(path, @pkg_dir) if File.exist?(path)
258
+ if srpms.empty?
259
+ raise <<-EOM
260
+ Could not create SRPM for '#{@spec_info.basename}
261
+ Error: #{File.read('logs/build.err')}
262
+ EOM
337
263
  end
338
264
  end
339
265
 
340
- cmd = %Q(#{mock_cmd} --root #{args[:chroot]} #{mocksnap} --buildsrpm --spec #{@spec_file} --sources #{@pkg_dir})
266
+ # Collect the built, or downloaded, RPMs
267
+ rpms = []
268
+
269
+ @spec_info.packages
270
+ expected_rpms = @spec_info.packages.map{|f|
271
+ latest_rpm = Dir.glob("#{f}-#{@spec_info.version}*.rpm").select{|x|
272
+ # Get all local RPMs that are not SRPMs
273
+ x !~ /\.src\.rpm$/
274
+ }.map{|x|
275
+ # Convert them to objects
276
+ x = Simp::RPM.new(x)
277
+ }.sort_by{|x|
278
+ # Sort by the full version of the package and return the one
279
+ # with the highest version
280
+ Gem::Version.new(x.full_version)
281
+ }.last
282
+
283
+ if latest_rpm && (
284
+ Gem::Version.new(latest_rpm.full_version) >=
285
+ Gem::Version.new(@spec_info.full_version)
286
+ )
287
+ f = latest_rpm.rpm_name
288
+ else
289
+ f = "#{f}-#{@spec_info.full_version}-#{@spec_info.arch}.rpm"
290
+ end
291
+ }
341
292
 
342
- sh cmd
343
- end
344
- end
345
- end
346
- end
293
+ if expected_rpms.empty? || require_rebuild?(expected_rpms, srpms)
347
294
 
348
- def define_pkg_rpm
349
- namespace :pkg do
350
- desc <<-EOM
351
- Build the #{@pkg_name} RPM.
352
- Building RPMs requires a working Mock setup (http://fedoraproject.org/wiki/Projects/Mock)
353
- * :chroot - The Mock chroot configuration to use. See the '--root' option in mock(1)."
354
- * :unique - Whether or not to build the RPM in a unique Mock environment.
355
- This can be very useful for parallel builds of all modules.
356
- * :snapshot_release - Add snapshot_release (date and time) to rpm version.
357
- Rpm spec file must have macro for this to work.
295
+ expected_rpms_data = expected_rpms.map{ |f|
296
+ if File.exist?(f)
297
+ f = Simp::RPM.new(f)
298
+ else
299
+ f = nil
300
+ end
301
+ }
358
302
 
359
- By default, the package will be built to support a SIMP-6.X file structure.
360
- To build the package for a different version of SIMP, export SIMP_BUILD_version=<5.X,4.X>
361
- EOM
362
- task :rpm,[:chroot,:unique,:snapshot_release] => [:srpm] do |t,args|
363
- args.with_defaults(:unique => 'false')
364
- args.with_defaults(:snapshot_release => 'false')
365
-
366
- l_date = ''
367
- if args[:snapshot_release] == 'true'
368
- l_date = '.' + "#{TIMESTAMP}"
369
- mocksnap = "-D 'snapshot_release #{l_date}'"
370
- @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
371
- end
303
+ require_rebuild = true
372
304
 
373
- rpms = Dir.glob(%(#{@pkg_dir}/#{@spec_info[:name]}-*#{@spec_info[:version]}-*#{l_date}*.rpm))
305
+ # We need to rebuild if not *all* of the expected RPMs are present
306
+ unless expected_rpms_data.include?(nil)
307
+ # If all of the RPMs are signed, we do not need a rebuild
308
+ require_rebuild = !expected_rpms_data.compact.select{|x| !x.signature}.empty?
309
+ end
374
310
 
375
- srpms = rpms.select{|x| x =~ /src\.rpm$/}
376
- rpms = (rpms - srpms)
311
+ if !require_rebuild
312
+ # We found all expected RPMs and they all had valid signatures
313
+ #
314
+ # Record the existing RPM metadata in the output file
315
+ rpms = expected_rpms
316
+ else
317
+ # Try a build
318
+ %x(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.out 2> logs/build.err)
319
+
320
+ # If the build failed, it was probably due to missing dependencies
321
+ unless $?.success?
322
+ # Find the RPM build dependencies
323
+ rpm_build_deps = %x(rpm -q -R -p #{srpms.first}).strip.split("\n")
324
+
325
+ # RPM stuffs this in every time
326
+ rpm_build_deps.delete_if {|x| x =~ /^rpmlib/}
327
+
328
+ # See if we have the ability to install things
329
+ unless Process.uid == 0
330
+ unless %x(sudo -ln) =~ %r(NOPASSWD:\s+(ALL|yum( install)?))
331
+ raise <<-EOM
332
+ Please install the following dependencies and try again:
333
+ #{rpm_build_deps.map{|x| x = " * #{x}"}.join("\n")}
334
+ EOM
335
+ end
336
+ end
377
337
 
378
- # Get rid of any RPMs that are not of this distribution build if we
379
- # have found one
380
- if @spec_info[:dist_tag]
381
- rpms.delete_if do |rpm|
382
- if rpm.split(@spec_info[:dist_tag]).last != ".#{@spec_info[:arch]}.rpm"
383
- if File.exist?(rpm)
384
- stash(rpm)
385
- end
338
+ rpm_build_deps.map! do |rpm|
339
+ if rpm =~ %r((.*)\s+(?:<=|=|==)\s+(.+))
340
+ rpm = "#{$1}-#{$2}"
341
+ end
386
342
 
387
- true
388
- else
389
- false
390
- end
391
- end
392
- end
343
+ rpm
344
+ end
393
345
 
394
- srpms.each do |srpm|
395
- dirname = File.dirname(srpm)
396
- basename = File.basename(srpm,'.src.rpm')
397
- srpm_info = Simp::RPM.get_info(srpm)
346
+ yum_install_cmd = %(yum -y install '#{rpm_build_deps.join("' '")}')
347
+ unless Process.uid == 0
348
+ yum_install_cmd = 'sudo ' + yum_install_cmd
349
+ end
398
350
 
399
- rpm = [File.join(dirname, basename), srpm_info[:arch], 'rpm'].join('.')
400
- if require_rebuild?(rpm, srpm)
401
- mock_cmd = mock_pre_check(args[:chroot], @chroot_name, args[:unique])
351
+ install_output = %x(#{yum_install_cmd} 2>&1)
352
+
353
+ if !$?.success? || (install_output =~ %r((N|n)o package))
354
+ raise <<-EOM
355
+ Could not run #{yum_install_cmd}
356
+ Error: #{install_output}
357
+ EOM
358
+ end
359
+ end
402
360
 
403
- cmd = %Q(#{mock_cmd} --root #{args[:chroot]} #{mocksnap} #{srpm})
361
+ # Try it again!
362
+ #
363
+ # If this doesn't work, something we can't fix automatically is wrong
364
+ %x(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.out 2> logs/build.err)
404
365
 
405
- sh cmd
366
+ rpms = File.read('logs/build.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten - srpms
406
367
 
407
- # remote chroot unless told not to (saves LOTS of space during ISO builds)
408
- unless ENV['SIMP_RAKE_MOCK_cleanup'] == 'no'
409
- cmd = %Q(#{mock_cmd} --root #{args[:chroot]} --clean)
410
- sh cmd
368
+ if rpms.empty?
369
+ raise <<-EOM
370
+ Could not create RPM for '#{@spec_info.basename}
371
+ Error: #{File.read('logs/build.err')}
372
+ EOM
373
+ end
411
374
  end
412
- end
413
- end
414
- end
415
- end
416
- end
417
375
 
418
- def define_pkg_scrub
419
- namespace :pkg do
420
- # :pkg:scrub
421
- # -----------------------------
422
- desc <<-EOM
423
- Scrub the #{@pkg_name} mock build directory.
424
- EOM
425
- task :scrub,[:chroot,:unique] do |t,args|
426
- args.with_defaults(:unique => 'false')
376
+ # Prevent overwriting the last good metadata file
377
+ raise %(Could not find any valid RPMs for '#{@spec_info.basename}') if rpms.empty?
427
378
 
428
- mock_cmd = mock_pre_check( args[:chroot], @chroot_name, args[:unique], false )
429
- cmd = %Q(#{mock_cmd} --scrub=all)
430
- sh cmd
379
+ Simp::RPM.create_rpm_build_metadata(File.expand_path(@base_dir), srpms, rpms)
380
+ end
381
+ end
431
382
  end
432
383
  end
433
384
  end
@@ -506,103 +457,17 @@ module Simp::Rake
506
457
  # ------------------------------------------------------------------------------
507
458
  # helper methods
508
459
  # ------------------------------------------------------------------------------
509
- # Get a list of all of the mock configs available on the system.
510
- def Pkg.get_mock_configs
511
- Dir.glob('/etc/mock/*.cfg').sort.map{ |x| x = File.basename(x,'.cfg')}
512
- end
513
-
514
460
  # Return True if any of the 'old' Array are newer than the 'new' Array
515
461
  def require_rebuild?(new, old)
516
462
  return true if ( Array(old).empty? || Array(new).empty?)
517
463
 
518
464
  Array(new).each do |new_file|
519
- unless File.exist?(new_file)
520
- return true
521
- end
465
+ return true unless File.exist?(new_file)
522
466
 
523
- unless uptodate?(new_file, Array(old))
524
- return true
525
- end
467
+ return true unless uptodate?(new_file, Array(old))
526
468
  end
527
469
 
528
470
  return false
529
471
  end
530
-
531
- # Run some pre-checks to make sure that mock will work properly.
532
- #
533
- # chroot = name of mock chroot to use
534
- # unique_ext = TODO
535
- # Pass init=false if you do not want the function to initialize.
536
- #
537
- # Returns a String that contains the appropriate mock command.
538
- def mock_pre_check( chroot, unique_ext, unique='false', init=true )
539
-
540
- mock = ENV['mock'] || '/usr/bin/mock'
541
-
542
- raise(StandardError,"Could not find mock on your system, exiting") unless File.executable?(mock)
543
-
544
- mock_configs = Pkg.get_mock_configs
545
- unless chroot
546
- raise(StandardError,
547
- "Error: No mock chroot provided. Your choices are:\n #{mock_configs.join("\n ")}"
548
- )
549
- end
550
-
551
- # If you pass a config file, just take it
552
- unless chroot.split('.').last == 'cfg'
553
- unless mock_configs.include?(chroot)
554
- raise(StandardError,
555
- "Error: Invalid mock chroot provided. Your choices are:\n #{mock_configs.join("\n ")}"
556
- )
557
- end
558
- end
559
-
560
- raise %Q(unique_ext must be a String ("#{unique_ext}" = #{unique_ext.class})) unless unique_ext.is_a?(String)
561
-
562
- # if true, restrict yum to the chroot's local yum cache (defaults to false)
563
- mock_offline = ENV.fetch( 'SIMP_RAKE_MOCK_OFFLINE', 'N' ).chomp.index( %r{^(1|Y|true|yes)$} ) || false
564
-
565
- mock_cmd = "#{mock} --quiet"
566
- mock_cmd += " --uniqueext=#{unique_ext}" if unique
567
- mock_cmd += ' --offline' if mock_offline
568
-
569
- initialized = is_mock_initialized(mock_cmd, chroot)
570
-
571
- unless initialized && init
572
- sh %Q(#{mock_cmd} --root #{chroot} --init #{unique_ext})
573
- else
574
- # Remove any old build cruft from the mock directory.
575
- # This is kludgy but WAY faster than rebuilding them all, even with a cache.
576
- sh %Q(#{mock_cmd} --root #{chroot} --chroot "/bin/rm -rf /builddir/build/BUILDROOT /builddir/build/*/*")
577
- end
578
-
579
- # Install useful stock packages
580
- if ENV.fetch( 'SIMP_RAKE_MOCK_EXTRAS', 'yes' ) == 'yes'
581
- pkgs = ['openssl', 'openssl-devel']
582
-
583
- env_pkgs = ENV.fetch('SIMP_RAKE_MOCK_PKGS','')
584
- unless env_pkgs.empty?
585
- pkgs = pkgs + env_pkgs.split(',')
586
- end
587
-
588
- pkgs.each do |pkg|
589
- sh %Q(#{mock_cmd} --root #{chroot} --install #{pkg})
590
- end
591
- end
592
-
593
- return mock_cmd + " --no-clean --no-cleanup-after --resultdir=#{@pkg_dir} --disable-plugin=package_state"
594
- end
595
-
596
- def is_mock_initialized( mock_cmd, chroot )
597
- @@initialized_mocks ||= []
598
- return true if @@initialized_mocks.include?(chroot)
599
-
600
- %x{#{mock_cmd} --root #{chroot} --chroot "test -d /tmp" &> /dev/null }
601
- initialized = $?.success?
602
- @@initialized_mocks << chroot
603
-
604
- # A simple test to see if the chroot is initialized.
605
- initialized
606
- end
607
472
  end
608
473
  end