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.
@@ -1,4 +1,5 @@
1
1
  require 'bundler'
2
+ require 'simp/yum'
2
3
  require 'simp/rake'
3
4
  require 'simp/rake/build/constants'
4
5
 
@@ -112,28 +113,8 @@ module Simp::Rake::Build
112
113
  # Helpers
113
114
  ##############################################################################
114
115
 
115
- # This is a complete hack to get around the fact that yumdownloader doesn't
116
- # cache properly when setting TMPDIR.
117
- def clean_yumdownloader_cache_dir
118
- require 'etc'
119
-
120
- tmp_dir = '/tmp'
121
- tmp_dir = ENV['TMPDIR'] if ENV['TMPDIR']
122
-
123
- Dir.glob("#{tmp_dir}/yum-#{Etc.getlogin}-*").each do |cache_dir|
124
- cache_dir = File.expand_path(cache_dir)
125
-
126
- puts "Cleaning Yumdownloader Cache Dir '#{cache_dir}'"
127
- begin
128
- rm_rf(cache_dir)
129
- rescue Exception => e
130
- puts "Could not remove cache Dir: #{e}"
131
- end
132
- end
133
- end
134
-
135
116
  # Return the target directory
136
- # Expects one argument wich is the 'arguments' hash to one of the tasks.
117
+ # Expects one argument which is the 'arguments' hash to one of the tasks.
137
118
  def get_target_dir(args)
138
119
  if $simp6
139
120
  return @build_base_dir
@@ -156,49 +137,11 @@ module Simp::Rake::Build
156
137
  end
157
138
 
158
139
  # Return where YUM finds the passed RPM
159
- def get_rpm_source(rpm,yum_conf)
160
- # Do we have what we need?
161
-
162
- unless @have_yumdownloader
163
- %x(yumdownloader --version > /dev/null 2>&1)
164
-
165
- if $?.exitstatus == 127
166
- fail("Error: Could not find 'yumdownloader'. Please install it and try again.")
167
- end
168
- @have_yumdownloader = true
169
- end
170
-
171
- source = nil
172
-
140
+ def get_rpm_source(rpm, yum_conf)
173
141
  puts("Looking up: #{rpm}")
174
- sources = %x(yumdownloader -c #{yum_conf} --urls #{File.basename(rpm,'.rpm')} 2>/dev/null )
175
-
176
- unless $?.success?
177
- raise(SIMPBuildException,"Could not find a download source")
178
- end
179
-
180
- sources = sources.split("\n").grep(%r(\.rpm$))
181
-
182
- if sources.empty?
183
- raise(SIMPBuildException,'No Sources found')
184
- else
185
- native_sources = sources.grep(%r((#{@build_arch}|noarch)\.rpm$))
186
-
187
- # One entry, one success
188
- if native_sources.size == 1
189
- source = native_sources.first
190
- # More than one entry is no good.
191
- elsif native_sources.size > 1
192
- raise(SIMPBuildException,'More than one file found')
193
- # The only entry found was for a non-native architecure
194
- # This means that someone specified the arch explicitly at the
195
- # command line and we should take it.
196
- else
197
- source = sources.first
198
- end
199
- end
142
+ yum_helper = Simp::YUM.new(yum_conf)
200
143
 
201
- return source
144
+ return yum_helper.get_source(rpm, @build_arch)
202
145
  end
203
146
 
204
147
  # Snag an RPM via YUM.
@@ -206,35 +149,18 @@ module Simp::Rake::Build
206
149
  #
207
150
  # If passed a source, simply downloads the file into the packages directory
208
151
  def download_rpm(rpm, yum_conf, source=nil, distro_dir=Dir.pwd)
152
+ yum_helper = Simp::YUM.new(yum_conf)
153
+
209
154
  # We're doing this so that we can be 100% sure that we're pulling the RPM
210
155
  # from where the last command indicated. YUM can choose multiple sources
211
156
  # and we definitely want the one that we actually state!
212
- source = get_rpm_source(rpm,yum_conf) unless source
157
+ source = yum_helper.get_source(rpm) unless source
213
158
 
214
159
  Dir.chdir('packages') do
215
160
  full_pkg = source.split('/').last
216
161
  unless File.exist?(full_pkg)
217
162
  puts("Downloading: #{full_pkg}")
218
- unless @use_yumdownloader
219
- %x(curl -L --max-redirs 10 -s -o "#{full_pkg}" -k "#{source}")
220
- if File.exist?(full_pkg) && !%x(file #{full_pkg}).include?('RPM')
221
- @use_yumdownloader = true
222
- FileUtils.rm(full_pkg)
223
- end
224
- end
225
-
226
- if @use_yumdownloader
227
- %x(yumdownloader -c #{yum_conf} #{File.basename(full_pkg,'.rpm')} 2>/dev/null )
228
-
229
- if File.exist?(full_pkg) && !%x(file #{full_pkg}).include?('RPM')
230
- @use_yumdownloader = true
231
- FileUtils.rm(full_pkg)
232
- end
233
- end
234
-
235
- unless $?.success?
236
- raise(SIMPBuildException,"Could not download")
237
- end
163
+ yum_helper.download(full_pkg)
238
164
 
239
165
  begin
240
166
  validate_rpm(full_pkg)
@@ -251,7 +177,7 @@ module Simp::Rake::Build
251
177
  # Check to see if an RPM is actually a valid RPM
252
178
  # Optionally remove any invalid RPMS.
253
179
  #
254
- # Returns true if the rm is valid raises a SIMPBuildException otherwise
180
+ # Returns true if the rpm is valid raises a SIMPBuildException otherwise
255
181
  def validate_rpm(rpm, clean=true)
256
182
  # Check to see if what we got is actually valid
257
183
  %x(rpm -K --nosignature "#{rpm}" 2>&1 > /dev/null)
@@ -270,57 +196,6 @@ module Simp::Rake::Build
270
196
  true
271
197
  end
272
198
 
273
- # Create the YUM config file
274
- # * yum_tmp => The directory in which to store the YUM DB and any other
275
- # temporary files.
276
- #
277
- # Returns the location of the YUM Configuration
278
- def generate_yum_conf(distro_dir=Dir.pwd)
279
- yum_conf_template = <<-EOM.gsub(/^\s+/,'')
280
- [main]
281
- keepcache = 1
282
- persistdir = <%= yum_cache %>
283
- logfile = <%= yum_logfile %>
284
- exactarch = 1
285
- obsoletes = 0
286
- gpgcheck = 1
287
- plugins = 1
288
- reposdir = <%= repo_dirs.join(' ') %>
289
- assumeyes = 1
290
- EOM
291
-
292
- yum_conf = nil
293
- Dir.chdir(distro_dir) do
294
- # Create the target directory
295
- yum_tmp = File.join('packages','yum_tmp')
296
- mkdir_p(yum_tmp) unless File.directory?(yum_tmp)
297
-
298
- yum_cache = File.expand_path(File.join(yum_tmp,'yum_cache'))
299
- mkdir_p(yum_cache) unless File.directory?(yum_cache)
300
-
301
- yum_logfile = File.expand_path(File.join(yum_tmp,'yum.log'))
302
-
303
- repo_dirs = []
304
- # Add the global directory
305
- repo_dirs << File.expand_path('../my_repos')
306
- if File.directory?('my_repos')
307
- # Add the local user repos if they exist
308
- repo_dirs << File.expand_path('my_repos')
309
- else
310
- # Add the default Internet repos otherwise
311
- repo_dirs << File.expand_path('repos')
312
- end
313
-
314
- # Create our YUM config file
315
- yum_conf = File.join(yum_tmp,'yum.conf')
316
- File.open(yum_conf,'w') do |fh|
317
- fh.write(ERB.new(yum_conf_template,nil,'-').result(binding))
318
- end
319
- end
320
-
321
- return File.absolute_path(yum_conf)
322
- end
323
-
324
199
  def get_known_packages(target_dir=Dir.pwd)
325
200
  known_package_hash = {}
326
201
 
@@ -354,7 +229,7 @@ module Simp::Rake::Build
354
229
 
355
230
  Dir.chdir(target_dir) do
356
231
  Dir.glob('packages/*.rpm').each do |pkg|
357
- downloaded_packages[Simp::RPM.get_info(pkg)[:name]] = { :rpm_name => File.basename(pkg) }
232
+ downloaded_packages[Simp::RPM.get_info(pkg)[:basename]] = { :rpm_name => File.basename(pkg) }
358
233
  end
359
234
  end
360
235
 
@@ -377,11 +252,12 @@ module Simp::Rake::Build
377
252
  Dir.chdir(target_dir) do
378
253
  unless File.exist?('packages.yaml') || File.directory?('packages')
379
254
  fail <<-EOM
380
- Error: Either 'pacakges.yaml' or the 'packages/' directory need to exist under '#{target_dir}
255
+ Error: Either 'packages.yaml' or the 'packages/' directory need to exist under '#{target_dir}
381
256
  EOM
382
257
  end
383
258
 
384
- yum_conf = generate_yum_conf
259
+ yum_helper = Simp::YUM.new(Simp::YUM.generate_yum_conf)
260
+ yum_conf = yum_helper.yum_conf
385
261
 
386
262
  known_package_hash = get_known_packages
387
263
  downloaded_package_hash = get_downloaded_packages
@@ -425,12 +301,12 @@ module Simp::Rake::Build
425
301
  # Do we have a valid external source?
426
302
  package_source = known_package_hash.find{|k,h| h[:rpm_name] == package_to_download}.last[:source]
427
303
  if package_source && (package_source =~ %r(^[a-z]+://))
428
- download_rpm(package_to_download,yum_conf,package_source)
304
+ download_rpm(package_to_download, yum_conf, package_source)
429
305
  else
430
306
  # If you get here, then you'll need to have an internal mirror of the
431
307
  # repositories in question. This covers things like private RPMs as
432
308
  # well as Commercial RPMs from Red Hat.
433
- download_rpm(package_to_download,yum_conf)
309
+ download_rpm(package_to_download, yum_conf)
434
310
  end
435
311
  rescue SIMPBuildException => e
436
312
  base_package_name = known_package_hash.find{|k,h| h[:rpm_name] == package_to_download}.first
@@ -459,7 +335,8 @@ module Simp::Rake::Build
459
335
  downloaded_package_hash.keys.each do |key|
460
336
  if downloaded_package_hash[key][:rpm_name] == package
461
337
  begin
462
- rpm_source = get_rpm_source(package,yum_conf)
338
+ rpm_source = yum_helper.get_source(package)
339
+ #rpm_source = get_rpm_source(package,yum_conf)
463
340
  known_package_hash[key] = downloaded_package_hash[key]
464
341
  known_package_hash[key][:source] = rpm_source
465
342
  rescue SIMPBuildException => e
@@ -547,9 +424,8 @@ module Simp::Rake::Build
547
424
  # Don't obsolete yourself!
548
425
  next unless new_pkg_info.basename == old_pkg_info.basename
549
426
 
550
- %x(rpmdev-vercmp #{new_pkg_info.full_version} #{old_pkg_info.full_version})
551
- exit_status = $?.exitstatus
552
- if exit_status == 11
427
+
428
+ if new_pkg_info.newer?(old_pkg_info.rpm_name)
553
429
  mkdir('obsolete') unless File.directory?('obsolete')
554
430
 
555
431
  puts("Retiring #{old_pkg}") if verbose
@@ -724,7 +600,7 @@ module Simp::Rake::Build
724
600
 
725
601
  * :arch - The architecture that you support. Default: x86_64
726
602
  EOM
727
- task :fetch,[:pkg,:os,:os_version,:simp_version,:arch] => [:prep, :clean_cache, :scaffold] do |t,args|
603
+ task :fetch,[:pkg,:os,:os_version,:simp_version,:arch] => [:prep, :scaffold] do |t,args|
728
604
  args.with_defaults(:simp_version => @simp_version.split('-').first)
729
605
  args.with_defaults(:arch => @build_arch)
730
606
 
@@ -746,19 +622,10 @@ module Simp::Rake::Build
746
622
  Dir.chdir(get_target_dir(args)) do
747
623
  pkgs.each do |pkg|
748
624
  # Pull down the RPM
749
- update_rpm(pkg,generate_yum_conf,true)
625
+ update_rpm(pkg, Simp::YUM.generate_yum_conf, true)
750
626
  end
751
627
  end
752
628
  end
753
-
754
- desc <<-EOM
755
- Clean the Yumdownloader cache.
756
-
757
- Use this if you're having strange issues fetching packages.
758
- EOM
759
- task :clean_cache do
760
- clean_yumdownloader_cache_dir
761
- end
762
629
  end
763
630
  end
764
631
  end
@@ -35,22 +35,14 @@ module Simp::Rake::Build
35
35
  def advanced_clean(type,args)
36
36
  fail "Type must be one of 'clean' or 'clobber'" unless ['clean','clobber'].include?(type)
37
37
 
38
- validate_in_mock_group?
39
-
40
- mock_dirs = Dir.glob("/var/lib/mock/*").map{|x| x = File.basename(x) }
41
-
42
- unless ( mock_dirs.empty? or args.chroot )
43
- $stderr.puts "Notice: You must pass a Mock chroot to erase a specified build root."
44
- end
45
-
46
- Rake::Task["pkg:#{type}"].invoke(args.chroot)
38
+ Rake::Task["pkg:#{type}"].invoke
47
39
  end
48
40
 
49
- task :clobber,[:chroot] do |t,args|
41
+ task :clobber do |t,args|
50
42
  advanced_clean('clobber',args)
51
43
  end
52
44
 
53
- task :clean,[:chroot] do |t,args|
45
+ task :clean do |t,args|
54
46
  advanced_clean('clean',args)
55
47
  end
56
48
  end
@@ -3,100 +3,38 @@ require 'rake/tasklib'
3
3
  module Simp::Rake; end
4
4
  module Simp::Rake::Build; end
5
5
  module Simp::Rake::Build::Constants
6
- def os_build_metadata(distro=nil, version=nil, arch=nil)
7
- unless @member_vars_initialized
8
- init_member_vars(Dir.pwd)
9
- end
10
-
11
- metadata = nil
12
-
13
- build_metadata_file = File.join(@distro_build_dir, 'build_metadata.yaml')
14
-
15
- if File.exist?(build_metadata_file)
16
- build_metadata = YAML.load_file(build_metadata_file)
17
-
18
- if distro
19
- begin
20
- metadata_init = { 'distributions' => {} }
21
- metadata = metadata_init.dup
22
-
23
- if build_metadata['distributions'][distro]
24
- if version && build_metadata['distributions'][distro][version]
25
- metadata['distributions'][distro] = {}
26
- metadata['distributions'][distro][version] = build_metadata['distributions'][distro][version].dup
27
-
28
- if arch && build_metadata['distributions'][distro][version]['arch'].include?(arch)
29
- metadata['distributions'][distro][version]['arch'] = Array(arch)
30
- else
31
- raise(NoMethodError)
32
- end
33
- else
34
- metadata['distributions'][distro] = build_metadata['distributions'][distro].dup
35
- end
36
-
37
- # Build everything that we've selected
38
- metadata['distributions'][distro].keys.each do |d|
39
- metadata['distributions'][distro][d]['build'] = true
40
- end
41
- end
6
+ def init_member_vars( base_dir )
7
+ return if @member_vars_initialized
42
8
 
43
- if metadata['distributions'].empty?
44
- raise(NoMethodError)
45
- end
46
- rescue NoMethodError
47
- $stderr.puts(%(Error: Could not find distribution for '#{ENV['SIMP_BUILD_distro']}'))
48
- $stderr.puts(%( Check #{File.expand_path(build_metadata_file)}))
49
- exit(1)
50
- end
51
- else
52
- metadata = build_metadata
53
- end
54
- end
9
+ require 'facter'
55
10
 
56
- return metadata
57
- end
11
+ $simp6 = true
12
+ $simp6_clean_dirs = []
58
13
 
59
- def init_member_vars( base_dir )
60
- return if @member_vars_initialized
14
+ @build_distro = Facter.fact('operatingsystem').value
15
+ @build_version = Facter.fact('operatingsystemmajrelease').value
16
+ @build_arch = Facter.fact('architecture').value
61
17
 
62
18
  @run_dir = Dir.pwd
63
19
  @base_dir = base_dir
64
- @build_arch = ENV['SIMP_BUILD_arch'] || %x{#{:facter} hardwaremodel 2>/dev/null}.chomp
65
20
  @build_dir = File.join(@base_dir, 'build')
66
- @dvd_dir = File.join(@build_dir, 'DVD_Overlay')
67
21
  @target_dists = ['CentOS', 'RedHat']
68
- @dist_dir = File.join(@build_dir, 'dist')
69
22
  @src_dir = File.join(@base_dir, 'src')
70
- @dvd_src = File.join(@src_dir, 'DVD')
71
23
  @spec_dir = File.join(@src_dir, 'build')
72
24
  @spec_file = FileList[File.join(@spec_dir, '*.spec')]
73
- @simp_version = Simp::RPM.get_info(File.join(@spec_dir, 'simp.spec'))[:full_version]
25
+ @simp_version = Simp::RPM.new(File.join(@src_dir, 'assets', 'simp', 'build', 'simp.spec')).full_version
74
26
  @simp_dvd_dirs = ["SIMP","ks","Config"]
75
- @distro_build_dir = File.join(@build_dir,'distributions')
76
- @os_build_metadata = nil
77
27
  @member_vars_initialized = true
78
28
 
79
- if ENV['SIMP_BUILD_distro']
80
- distro, version, arch = ENV['SIMP_BUILD_distro'].split(/,|\//)
29
+ @distro_build_dir = File.join(@build_dir, 'distributions', @build_distro, @build_version, @build_arch)
30
+ @dvd_src = File.join(@distro_build_dir, 'DVD')
31
+ @dvd_dir = File.join(@distro_build_dir, 'DVD_Overlay')
81
32
 
82
- @os_build_metadata = os_build_metadata(distro, version, arch)
83
- else
84
- @os_build_metadata = os_build_metadata()
33
+ if File.exist?(File.join(@build_dir, 'distributions'))
34
+ @build_dir = @distro_build_dir
85
35
  end
86
36
 
87
- if @os_build_metadata && !@os_build_metadata.empty?
88
- $simp6 = true
89
- $simp6_clean_dirs = []
90
-
91
- @os_build_metadata['distributions'].keys.sort.each do |d|
92
- @os_build_metadata['distributions'][d].keys.sort.each do |v|
93
- next unless @os_build_metadata['distributions'][d][v]['build']
94
- @os_build_metadata['distributions'][d][v]['arch'].sort.each do |a|
95
- $simp6_clean_dirs << File.join(@distro_build_dir, d, v, a, 'SIMP')
96
- $simp6_clean_dirs << File.join(@distro_build_dir, d, v, a, 'SIMP_ISO*')
97
- end
98
- end
99
- end
100
- end
37
+ @dist_dir = File.join(@build_dir, 'dist')
38
+ @rpm_dir = "#{@build_dir}/SIMP/RPMS"
101
39
  end
102
40
  end
@@ -36,7 +36,14 @@ class R10KHelper
36
36
  end
37
37
 
38
38
  unless repo_status
39
- untracked_files = %x(git ls-files -o -d --exclude-standard)
39
+ # Things that may be out of date but which should stop the updating
40
+ # of the git repo
41
+ our_exclusions=[
42
+ 'build/rpm_metadata',
43
+ 'dist/'
44
+ ]
45
+
46
+ untracked_files = %x(git ls-files -o -d --exclude-standard --exclude=#{our_exclusions.join(' --exclude=')})
40
47
 
41
48
  if $?.success?
42
49
  unless untracked_files.empty?
@@ -12,7 +12,6 @@ module Simp::Rake::Build
12
12
  def initialize( base_dir )
13
13
  init_member_vars( base_dir )
14
14
 
15
- @mock = ENV['mock'] || '/usr/bin/mock'
16
15
  define_tasks
17
16
  end
18
17
 
@@ -94,6 +93,7 @@ module Simp::Rake::Build
94
93
  end
95
94
  end # End of prune_packages
96
95
 
96
+ =begin
97
97
  desc <<-EOM
98
98
  Build the SIMP ISO(s).
99
99
  * :tarball - Path of the source tarball or directory containing the source
@@ -106,6 +106,7 @@ module Simp::Rake::Build
106
106
  ENV vars:
107
107
  - Set `SIMP_ISO_verbose=yes` to report file operations as they happen.
108
108
  EOM
109
+ =end
109
110
  task :build,[:tarball,:unpacked_dvds,:prune] => [:prep] do |t,args|
110
111
  args.with_defaults(:unpacked_dvds => "#{@run_dir}", :prune => 'true')
111
112
 
@@ -320,22 +321,23 @@ module Simp::Rake::Build
320
321
  fail('Error: No ISO was built!') unless @simp_output_iso
321
322
  end
322
323
 
324
+ =begin
323
325
  desc <<-EOM
324
326
  Build the source ISO.
325
327
  Note: The process clobbers the temporary and built files, rebuilds the
326
328
  tarball(s) and packages the source ISO. Therefore it will take a
327
329
  while.
328
330
  * :key - The GPG key to sign the RPMs with. Defaults to 'prod'.
329
- * :chroot - An optional Mock Chroot. If this is passed, the tar:build task will be called.
330
331
  EOM
331
- task :src,[:prep, :key,:chroot] do |t,args|
332
+ =end
333
+ task :src,[:prep, :key] do |t,args|
332
334
  args.with_defaults(:key => 'prod')
333
335
 
334
- if Dir.glob("#{@dvd_dir}/*.gz").empty? && !args.chroot
335
- fail("Error: Could not find compiled source tarballs, please pass a chroot.")
336
+ if Dir.glob("#{@dvd_dir}/*.gz").empty?
337
+ fail("Error: Could not find compiled source tarballs")
336
338
  end
337
339
 
338
- Rake::Task['tar:build'].invoke(args.chroot) if args.chroot
340
+ Rake::Task['tar:build']
339
341
 
340
342
  Dir.chdir(@base_dir) do
341
343
  File.basename(Dir.glob("#{@dvd_dir}/*.tar.gz").first,'.tar.gz') =~ /SIMP-DVD-[^-]+-(.+)/