simp-rake-helpers 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ade6e1ae8a744fa8b543ed966cb67ed411ab41c0
4
+ data.tar.gz: ec51fff88f43b136d2932a655f8f39e2a2344510
5
+ SHA512:
6
+ metadata.gz: 34978e726b9a3378f5ecb2e5b943eb010c6b45722b48bb8ab388404786a7f538359af9ffd751b0aff84daa4f753f19c062ff8e0293a2659267358c402701d55b
7
+ data.tar.gz: 0464603d53ab8e63fa4cc0d130fecafd5a68ce41343ea66e4a1c86448d98232d6762e2ac58901656d6af65797d564c687727d9119ce652d2c32a7be899f694a2
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.sw[pnoqst]
2
+ Gemfile.lock
3
+ dist/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script:
7
+ - "bundle exec rake spec"
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ ### 1.0.6 / 2015-06-24
2
+ * Cleanup gemspec
3
+ * Fixed bugs in the RPM signing code regarding fetching the username and
4
+ password from the appropriate source.
5
+
6
+ ### 1.0.4 / 2015-06-22
7
+ * Added support for reading information directly from RPMs as well as spec
8
+ files.
9
+
10
+ ### 1.0.2 / 2105-04-02
11
+ * Added support for snapshot_release, adds date and time to rpm release
12
+ version
13
+
14
+ ### 1.0.1 / 2015-02-03
15
+ * Added the top level rake and rpm files to the Manifest
16
+
17
+ ### 1.0.0 / 2014-12-09
18
+ * Refactored all the SIMP repositories' common Rakefile tasks into this gem.
19
+ * Birthday!
20
+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Contributing
2
+
3
+ Please refer to the main [SIMP Project Contributing Guide](https://github.com/NationalSecurityAgency/SIMP/blob/master/CONTRIBUTING.md)
4
+ for details on contributing to this project.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: "bundle exec rspec" do
5
+ require "guard/rspec/dsl"
6
+ dsl = Guard::RSpec::Dsl.new(self)
7
+
8
+ # RSpec files
9
+ rspec = dsl.rspec
10
+ watch(rspec.spec_helper) { rspec.spec_dir }
11
+ watch(rspec.spec_support) { rspec.spec_dir }
12
+ watch(rspec.spec_files)
13
+
14
+ # Ruby files
15
+ ruby = dsl.ruby
16
+ dsl.watch_spec_files_for(ruby.lib_files)
17
+ end
18
+
19
+ # Add files and commands to this file, like the example:
20
+ # watch(%r{file/path}) { `command(s)` }
21
+ #
22
+ guard :shell do
23
+ watch(/(.*).md/) {|m| `tail #{m[0]}` }
24
+ end
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ rubygem-simp-rake-helpers - Common helper methods for SIMP Rakefiles
2
+
3
+ --
4
+
5
+ Per Section 105 of the Copyright Act of 1976, these works are not entitled to
6
+ domestic copyright protection under US Federal law.
7
+
8
+ The US Government retains the right to pursue copyright protections outside of
9
+ the United States.
10
+
11
+ The United States Government has unlimited rights in this software and all
12
+ derivatives thereof, pursuant to the contracts under which it was developed and
13
+ the License under which it falls.
14
+
15
+ ---
16
+
17
+ Licensed under the Apache License, Version 2.0 (the "License");
18
+ you may not use this file except in compliance with the License.
19
+ You may obtain a copy of the License at
20
+
21
+ http://www.apache.org/licenses/LICENSE-2.0
22
+
23
+ Unless required by applicable law or agreed to in writing, software
24
+ distributed under the License is distributed on an "AS IS" BASIS,
25
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ See the License for the specific language governing permissions and
27
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # simp-rake-helpers
2
+
3
+ Common helper methods for SIMP Rakefiles
4
+
5
+ ## Features
6
+ * supports multithreaded mock operations
7
+
8
+
9
+ ## Usage
10
+ ```ruby
11
+ require 'simp/rake/helpers'
12
+ ```
13
+
14
+ ## Requirements
15
+ * SIMP source
16
+
17
+
18
+ ## Install
19
+ * sudo gem install simp-rake-helpers
20
+
21
+
22
+ ## License
23
+ See [LICENSE](LICENSE)
24
+
25
+
26
+ ## History
27
+ See [CHANGELOG.md](CHANGELOG.md)
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require 'rake/clean'
5
+ require 'find'
6
+
7
+ @package='simp-rake-helpers'
8
+ @rakefile_dir=File.dirname(__FILE__)
9
+
10
+ CLEAN.include "#{@package}-*.gem"
11
+ CLEAN.include 'pkg'
12
+ CLEAN.include 'dist'
13
+ Find.find( @rakefile_dir ) do |path|
14
+ if File.directory? path
15
+ CLEAN.include path if File.basename(path) == 'tmp'
16
+ else
17
+ Find.prune
18
+ end
19
+ end
20
+
21
+ desc 'Ensure gemspec-safe permissions on all files'
22
+ task :chmod do
23
+ gemspec = File.expand_path( "#{@package}.gemspec", @rakefile_dir ).strip
24
+ spec = Gem::Specification::load( gemspec )
25
+ spec.files.each do |file|
26
+ FileUtils.chmod 'go=r', file
27
+ end
28
+ end
29
+
30
+ desc 'run all RSpec tests'
31
+ task :spec do
32
+ Dir.chdir @rakefile_dir
33
+ sh 'bundle exec rspec spec'
34
+ end
35
+
36
+ namespace :pkg do
37
+ desc "build rubygem package for #{@package}"
38
+ task :gem => :chmod do
39
+ Dir.chdir @rakefile_dir
40
+ Dir['*.gemspec'].each do |spec_file|
41
+ cmd = %Q{SIMP_RPM_BUILD=1 bundle exec gem build "#{spec_file}"}
42
+ sh cmd
43
+ FileUtils.mkdir_p 'dist'
44
+ FileUtils.mv Dir.glob("#{@package}*.gem"), 'dist/'
45
+ end
46
+ end
47
+
48
+ desc "build and install rubygem package for #{@package}"
49
+ task :install_gem => [:clean, :gem] do
50
+ Dir.chdir @rakefile_dir
51
+ Dir.glob("dist/#{@package}*.gem") do |pkg|
52
+ sh %Q{bundle exec gem install #{pkg}}
53
+ end
54
+ end
55
+ end
56
+ # vim: syntax=ruby
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ abort "you need to write me"
data/lib/simp/rake.rb ADDED
@@ -0,0 +1,134 @@
1
+ module Simp; end
2
+ module Simp::Rake
3
+ require 'rubygems'
4
+ require 'erb'
5
+ require 'rake/clean'
6
+ require 'find'
7
+ require 'yaml'
8
+ require 'shellwords'
9
+ require 'parallel'
10
+ require 'tempfile'
11
+ require 'simp/rpm'
12
+ require 'simp/rake/pkg'
13
+
14
+ # Force the encoding to something that Ruby >= 1.9 is happy with
15
+ def encode_line(line)
16
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9')
17
+ require 'iconv'
18
+ line = Iconv.new('ISO-8859-1//IGNORE','UTF-8').iconv(line)
19
+ else
20
+ line = line.force_encoding(Encoding::ISO_8859_1).encode(Encoding::UTF_8,:replace => nil,:undef => :replace)
21
+ end
22
+ end
23
+
24
+ # by default, we use all processors - 1
25
+ def get_cpu_limit
26
+ cpus = Parallel.processor_count
27
+ env_cpus = ENV.fetch( 'SIMP_RAKE_LIMIT_CPUS', '-1' ).strip.to_i
28
+
29
+ env_cpus = 1 if env_cpus == 0
30
+ env_cpus += cpus if env_cpus < 0
31
+ # sanitize huge numbers
32
+ env_cpus = (cpus - 1) if env_cpus >= cpus
33
+ env_cpus = 1 if env_cpus < 0
34
+
35
+ env_cpus
36
+ end
37
+
38
+ # Snarfed from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
39
+ def run_pager
40
+ return if RUBY_PLATFORM =~ /win32/
41
+ return unless STDOUT.tty?
42
+
43
+ read, write = IO.pipe
44
+
45
+ unless Kernel.fork # Child process
46
+ STDOUT.reopen(write)
47
+ STDERR.reopen(write) if STDERR.tty?
48
+ read.close
49
+ write.close
50
+ return
51
+ end
52
+
53
+ # Parent process, become pager
54
+ STDIN.reopen(read)
55
+ read.close
56
+ write.close
57
+
58
+ ENV['LESS'] = 'FSRX' # Don't page if the input is short enough
59
+
60
+ Kernel.select [STDIN] # Wait until we have input before we start the pager
61
+ pager = ENV['PAGER'] || 'less'
62
+ exec pager rescue exec "/bin/sh", "-c", pager
63
+ end
64
+
65
+ # Originally snarfed from
66
+ # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
67
+ def which(cmd)
68
+ File.executable?(cmd) and return cmd
69
+
70
+ cmd = File.basename(cmd)
71
+
72
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
73
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
74
+ exts.each { |ext|
75
+ exe = File.join(path, "#{cmd}#{ext}")
76
+ return exe if File.executable? exe
77
+ }
78
+ end
79
+
80
+ warn "Warning: Command #{cmd} not found on the system."
81
+ return nil
82
+ end
83
+
84
+ # Return whether or not the user is in the mock group
85
+ def validate_in_mock_group?
86
+ if not %x{groups}.split.include?('mock')
87
+ raise(Exception,"You need to be in the 'mock' group.")
88
+ end
89
+ end
90
+
91
+ def help
92
+ run_pager
93
+
94
+ puts <<-EOM
95
+ = SIMP Build Tasks =
96
+
97
+ Use 'rake' and choose one of the options below that best suits your
98
+ needs. If you are simply trying to build the SIMP tarball, use the
99
+ 'rake tar:build[:chroot]' option.
100
+
101
+ NOTE: Any task that requires a :chroot input will require you to be in
102
+ the 'mock' group and have the 'mock' package installed.
103
+
104
+ == Space Requirements ==
105
+
106
+ A full parallel build will take around 500M for each git submodule built.
107
+
108
+ If you are space limited, set SIMP_RAKE_LIMIT_CPUS=1 at build time.
109
+
110
+ == Environment Variables ==
111
+
112
+ * SIMP_RAKE_CHOWN_EVERYTHING=(Y|n)
113
+ - Chown everything to the 'mock' group prior to building
114
+
115
+ * SIMP_RAKE_MOCK_OFFLINE=(y|N)
116
+ - Mock runs are limited to the local cache
117
+
118
+ * SIMP_RAKE_LIMIT_CPUS=#
119
+ - Default: Num system CPUs - 1
120
+ - An Integer that limits builds to # processors
121
+ - If set to '1', will only build in a single mock directory
122
+
123
+ * SIMP_GIT_BRANCH=<Branch ID>
124
+ - If you are working in the supermodule and wish to perform a reset, but
125
+ retain your working branch at the supermodule level. You can set this to
126
+ ignore the current supermodule branch value.
127
+ - This is particularly valuable when using Jenkins.
128
+
129
+ ********************
130
+ EOM
131
+
132
+ sh %{rake -D}
133
+ end
134
+ end
@@ -0,0 +1,7 @@
1
+ module Simp; end
2
+ module Simp::Rake; end
3
+
4
+ class Simp::Rake::Helpers
5
+ VERSION = '1.0.6'
6
+ require 'simp/rake/pkg'
7
+ end
@@ -0,0 +1,321 @@
1
+ # This file provided many common build-related tasks and helper methods from
2
+ # the SIMP Rakefile ecosystem.
3
+
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'rake/tasklib'
7
+ require 'fileutils'
8
+ require 'find'
9
+
10
+ module Simp; end
11
+ module Simp::Rake
12
+ class Pkg < ::Rake::TaskLib
13
+
14
+ # path to the project's directory. Usually `File.dirname(__FILE__)`
15
+ attr_accessor :base_dir
16
+
17
+ # the name of the package. Usually `File.basename(@base_dir)`
18
+ attr_accessor :pkg_name
19
+
20
+ # path to the project's RPM specfile
21
+ attr_accessor :spec_file
22
+
23
+ # path to the directory to place generated assets (e.g., rpm, srpm, tar.gz)
24
+ attr_accessor :pkg_dir
25
+
26
+ # array of items to exclude from the tarball
27
+ attr_accessor :exclude_list
28
+
29
+ # array of items to additionally clean
30
+ attr_accessor :clean_list
31
+
32
+ #
33
+ attr_accessor :unique_name
34
+
35
+ # array of items to ignore when checking if the tarball needs to be rebuilt
36
+ attr_accessor :ignore_changes_list
37
+
38
+ def initialize( base_dir, unique_name=nil )
39
+ @base_dir = base_dir
40
+ @pkg_name = File.basename(@base_dir)
41
+ @spec_file = Dir.glob("#{@base_dir}/build/*.spec").first
42
+ @pkg_dir = "#{@base_dir}/dist"
43
+ @exclude_list = [ File.basename(@pkg_dir) ]
44
+ @clean_list = []
45
+ @ignore_changes_list = []
46
+ @chroot_name = unique_name
47
+
48
+ ::CLEAN.include( @pkg_dir )
49
+
50
+ yield self if block_given?
51
+
52
+ ::CLEAN.include( @clean_list )
53
+
54
+ @spec_info = Pkg.get_info( @spec_file )
55
+ @chroot_name = @chroot_name || "#{@spec_info[:name]}__#{ENV.fetch( 'USER', 'USER' )}"
56
+ @dir_name = "#{@spec_info[:name]}-#{@spec_info[:version]}"
57
+ @mfull_pkg_name = "#{@dir_name}-#{@spec_info[:release]}"
58
+ @full_pkg_name = @mfull_pkg_name.gsub("%{?snapshot_release}","")
59
+ @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
60
+
61
+ define
62
+ end
63
+
64
+
65
+ def define
66
+ # For the most part, we don't want to hear Rake's noise, unless it's an error
67
+ # TODO: Make this configurable
68
+ verbose(false)
69
+
70
+ define_clean
71
+ define_clobber
72
+ define_pkg_tar
73
+ define_pkg_srpm
74
+ define_pkg_rpm
75
+ define_pkg_scrub
76
+ task :default => 'pkg:tar'
77
+ self
78
+ end
79
+
80
+
81
+ def define_clean
82
+ desc <<-EOM
83
+ Clean build artifacts for #{@pkg_name} (except for mock)
84
+ EOM
85
+ task :clean do |t,args|
86
+ # this is provided by 'rake/clean' and the ::CLEAN constant
87
+ end
88
+ end
89
+
90
+
91
+
92
+ def define_clobber
93
+ desc <<-EOM
94
+ Clobber build artifacts for #{@pkg_name} (except for mock)
95
+ EOM
96
+ task :clobber do |t,args|
97
+ end
98
+ end
99
+
100
+
101
+ def define_pkg_tar
102
+ namespace :pkg do
103
+ directory @pkg_dir
104
+
105
+ # :pkg:tar
106
+ # -----------------------------
107
+ desc <<-EOM
108
+ Build the #{@pkg_name} tar package
109
+ * :snapshot_release - Add snapshot_release (date and time) to rpm version, rpm spec file must have macro for this to work.
110
+ EOM
111
+ task :tar,[:snapshot_release] => [@pkg_dir] do |t,args|
112
+ args.with_defaults(:snapshot_release => false)
113
+
114
+ l_date = ''
115
+ if args.snapshot_release == 'true' then
116
+ l_date = '.' + "#{TIMESTAMP}"
117
+ @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
118
+ end
119
+ Dir.chdir("#{@base_dir}/..") do
120
+ Find.find(@pkg_name) do |path|
121
+ Find.prune if path =~ /^\.git/
122
+ Find.prune if path == "#{@pkg_name}/#{File.basename(@pkg_dir)}"
123
+ Find.prune if @ignore_changes_list.include?(path)
124
+ if path == @pkg_name and not uptodate?(@tar_dest,[path]) then
125
+ sh %Q{tar --owner 0 --group 0 --exclude-vcs --exclude=#{@exclude_list.join(' --exclude=')} --transform='s/^#{@pkg_name}/#{@dir_name}/' -cpzf "#{@tar_dest}" #{@pkg_name}}
126
+ break
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+
135
+ def define_pkg_srpm
136
+ namespace :pkg do
137
+ desc <<-EOM
138
+ Build the #{@pkg_name} SRPM
139
+ Building RPMs requires a working Mock setup (http://fedoraproject.org/wiki/Projects/Mock)
140
+ * :chroot - The Mock chroot configuration to use. See the '--root' option in mock(1)."
141
+ * :unique - Whether or not to build the SRPM in a unique Mock environment.
142
+ This can be very useful for parallel builds of all modules.
143
+ * :snapshot_release - Add snapshot_release (date and time) to rpm version.
144
+ Rpm spec file must have macro for this to work.
145
+ EOM
146
+ task :srpm,[:chroot,:unique,:snapshot_release] => [:tar] do |t,args|
147
+ args.with_defaults(:unique => false)
148
+ args.with_defaults(:snapshot_release => false)
149
+
150
+ l_date = ''
151
+ if args.snapshot_release == 'true' then
152
+ l_date = '.' + "#{TIMESTAMP}"
153
+ mocksnap = "-D 'snapshot_release #{l_date}'"
154
+ @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
155
+ end
156
+
157
+ mock_cmd = mock_pre_check( args.chroot, @chroot_name, args.unique )
158
+ output = "#{@full_pkg_name}#{l_date}.src.rpm"
159
+ if not uptodate?("#{@pkg_dir}/#{output}",[@tar_dest]) then
160
+ cmd = %Q{#{mock_cmd} --no-clean --root #{args.chroot} #{mocksnap} --buildsrpm --spec #{@spec_file} --source #{@pkg_dir}}
161
+ sh cmd
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+
168
+
169
+ def define_pkg_rpm
170
+ namespace :pkg do
171
+ desc <<-EOM
172
+ Build the #{@pkg_name} RPM
173
+ Building RPMs requires a working Mock setup (http://fedoraproject.org/wiki/Projects/Mock)
174
+ * :chroot - The Mock chroot configuration to use. See the '--root' option in mock(1)."
175
+ * :unique - Whether or not to build the RPM in a unique Mock environment.
176
+ This can be very useful for parallel builds of all modules.
177
+ * :snapshot_release - Add snapshot_release (date and time) to rpm version.
178
+ Rpm spec file must have macro for this to work.
179
+ EOM
180
+ task :rpm,[:chroot,:unique,:snapshot_release] do |t,args|
181
+ args.with_defaults(:unique => false)
182
+ args.with_defaults(:snapshot_release => false)
183
+
184
+ l_date = ''
185
+ if args.snapshot_release == 'true' then
186
+ l_date = '.' + "#{TIMESTAMP}"
187
+ mocksnap = "-D 'snapshot_release #{l_date}'"
188
+ @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}#{l_date}.tar.gz"
189
+ end
190
+
191
+ mock_cmd = mock_pre_check( args.chroot, @chroot_name, args.unique )
192
+ Rake::Task['pkg:srpm'].invoke(args.chroot,args.unique,args.snapshot_release)
193
+
194
+ output = "#{@full_pkg_name}#{l_date}.#{@spec_info[:arch]}.rpm"
195
+ if not uptodate?("#{@pkg_dir}/#{output}",[@tar_dest]) then
196
+ cmd = %Q{#{mock_cmd} --root #{args.chroot} #{mocksnap} #{@pkg_dir}/#{@full_pkg_name}#{l_date}.src.rpm}
197
+ sh cmd
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ def define_pkg_scrub
204
+ namespace :pkg do
205
+ # :pkg:scrub
206
+ # -----------------------------
207
+ desc <<-EOM
208
+ Scrub the #{@pkg_name} mock build directory
209
+ EOM
210
+ task :scrub,[:chroot,:unique] do |t,args|
211
+ args.with_defaults(:unique => false)
212
+
213
+ mock_cmd = mock_pre_check( args.chroot, @chroot_name, args.unique, false )
214
+ cmd = %Q{#{mock_cmd} --scrub=all}
215
+ sh cmd
216
+ end
217
+
218
+ end
219
+
220
+ end
221
+
222
+ # ------------------------------------------------------------------------------
223
+ # helper methods
224
+ # ------------------------------------------------------------------------------
225
+ # Pull the main RPM information out of the package spec file.
226
+ def Pkg.get_info(specfile)
227
+ info = Hash.new
228
+ info[:arch] = %x{uname -i}
229
+
230
+ if File.readable?(specfile) then
231
+ File.open(specfile).each do |line|
232
+ if line =~ /^\s*Version:\s+(.*)\s*/ then
233
+ info[:version] = $1
234
+ next
235
+ elsif line =~ /^\s*Release:\s+(.*)\s*/ then
236
+ info[:release] = $1
237
+ next
238
+ elsif line =~ /^\s*Name:\s+(.*)\s*/ then
239
+ info[:name] = $1
240
+ next
241
+ elsif line =~ /^\s*Buildarch:\s+(.*)\s*/ then
242
+ info[:arch] = $1
243
+ next
244
+ end
245
+ end
246
+ else
247
+ raise "Error: unable to read the spec file '#{specfile}'"
248
+ end
249
+ return info
250
+ end
251
+
252
+
253
+ # Get a list of all of the mock configs available on the system.
254
+ def Pkg.get_mock_configs
255
+ Dir.glob('/etc/mock/*.cfg').sort.map{ |x| x = File.basename(x,'.cfg')}
256
+ end
257
+
258
+
259
+ # Run some pre-checks to make sure that mock will work properly.
260
+ #
261
+ # chroot = name of mock chroot to use
262
+ # unique_ext = TODO
263
+ # Pass init=false if you do not want the function to initialize.
264
+ #
265
+ # Returns a String that contains the appropriate mock command.
266
+ def mock_pre_check( chroot, unique_ext, unique=false, init=true )
267
+
268
+ raise %Q{unique_ext must be a String ("#{unique_ext}" = #{unique_ext.class})} if not unique_ext.is_a? String
269
+
270
+ mock = ENV['mock'] || '/usr/bin/mock'
271
+ raise(Exception,"Could not find mock on your system, exiting") unless File.executable?('/usr/bin/mock')
272
+
273
+ mock_configs = Pkg.get_mock_configs
274
+ if not chroot then
275
+ raise(Exception,
276
+ "Error: No mock chroot provided. Your choices are:\n #{mock_configs.join("\n ")}"
277
+ )
278
+ end
279
+ if not mock_configs.include?(chroot) then
280
+ raise(Exception,
281
+ "Error: Invalid mock chroot provided. Your choices are:\n #{mock_configs.join("\n ")}"
282
+ )
283
+ end
284
+
285
+ # if true, restrict yum to the chroot's local yum cache (defaults to false)
286
+ mock_offline = ENV.fetch( 'SIMP_RAKE_MOCK_OFFLINE', 'N' ).chomp.index( %r{^(1|Y|true|yes)$} ) || false
287
+
288
+ mock_cmd = "#{mock} --quiet"
289
+ mock_cmd += " --uniqueext=#{unique_ext}" if unique
290
+ mock_cmd += " --offline" if mock_offline
291
+
292
+ initialized = is_mock_initialized( mock_cmd, chroot)
293
+
294
+ if init and not initialized then
295
+ sh %Q{#{mock_cmd} --root #{chroot} --init ##{unique_ext} }
296
+ else
297
+ # Remove any old build cruft from the mock directory.
298
+ # This is kludgy but WAY faster than rebuilding them all, even with a cache.
299
+ sh %Q{#{mock_cmd} --root #{chroot} --chroot "/bin/rm -rf /builddir/build/BUILDROOT /builddir/build/*/*"}
300
+ end
301
+
302
+ mock_cmd + " --no-clean --no-cleanup-after --resultdir=#{@pkg_dir} --disable-plugin=package_state"
303
+ end
304
+
305
+ def is_mock_initialized( mock_cmd, chroot )
306
+ %x{#{mock_cmd} --root #{chroot} --chroot "test -d /tmp" &> /dev/null }
307
+ initialized = $?.success?
308
+
309
+ # A simple test to see if the chroot is initialized.
310
+ initialized
311
+ end
312
+
313
+ def pry
314
+ #FIXME: remove this debugging nonsense before release
315
+ if Rake::verbose.is_a? TrueClass
316
+ require 'pry'
317
+ binding.pry
318
+ end
319
+ end
320
+ end
321
+ end
data/lib/simp/rpm.rb ADDED
@@ -0,0 +1,162 @@
1
+ module Simp
2
+ # Simp::RPM represents a single package that is built and packaged by the Simp team.
3
+ class Simp::RPM
4
+ require 'expect'
5
+ require 'pty'
6
+
7
+ @@gpg_keys = Hash.new
8
+ attr_accessor :basename, :version, :release, :full_version, :name, :sources, :verbose
9
+
10
+ if Gem.loaded_specs['rake'].version >= Gem::Version.new('0.9')
11
+ def self.sh(args)
12
+ system args
13
+ end
14
+ end
15
+
16
+ # Constructs a new Simp::RPM object. Requires the path to the spec file
17
+ # from which information will be gathered.
18
+ #
19
+ # The following information will be retreived:
20
+ # [basename] The name of the package (as it would be queried in yum)
21
+ # [version] The version of the package
22
+ # [release] The release version of the package
23
+ # [full_version] The full version of the package: [version]-[release]
24
+ # [name] The full name of the package: [basename]-[full_version]
25
+ def initialize(rpm_source)
26
+ info = Simp::RPM.get_info(rpm_source)
27
+ @basename = info[:name]
28
+ @version = info[:version]
29
+ @release = info[:release]
30
+ @full_version = info[:full_version]
31
+ @name = "#{@basename}-#{@full_version}"
32
+ @sources = Array.new
33
+ end
34
+
35
+ # Copies specific content from one directory to another.
36
+ # start_dir:: the root directory where the original files are located within
37
+ # src:: a pattern given to find(1) to match against the desired files to copy
38
+ # dest:: the destination directory to receive the copies
39
+ def self.copy_wo_vcs(start_dir, src, dest, dereference=true)
40
+ if dereference.nil? || dereference
41
+ dereference = "--dereference"
42
+ else
43
+ dereference = ""
44
+ end
45
+
46
+ Dir.chdir(start_dir) do
47
+ sh %{find #{src} \\( -path "*/.svn" -a -type d -o -path "*/.git*" \\) -prune -o -print | cpio -u --warning none --quiet --make-directories #{dereference} -p "#{dest}" 2>&1 > /dev/null}
48
+ end
49
+ end
50
+
51
+ # Parses information, such as the version, from the given specfile or RPM
52
+ # into a hash.
53
+ def self.get_info(rpm_source)
54
+ info = Hash.new
55
+ if File.readable?(rpm_source)
56
+ if rpm_source.split('.').last == 'rpm'
57
+ rpm_info = %x(rpm -q --queryformat '%{NAME} %{VERSION} %{RELEASE}' -p #{rpm_source} 2>/dev/null)
58
+ info[:name],info[:version],info[:release] = rpm_info.split(' ')
59
+ else
60
+ File.open(rpm_source).each do |line|
61
+ if line =~ /^\s*Version:\s+(.*)\s*/
62
+ info[:version] = $1
63
+ next
64
+ elsif line =~ /^\s*Release:\s+(.*)\s*/
65
+ info[:release] = $1
66
+ next
67
+ elsif line =~ /^\s*Name:\s+(.*)\s*/
68
+ info[:name] = $1
69
+ next
70
+ end
71
+ end
72
+ end
73
+ else
74
+ raise "Error: unable to read '#{rpm_source}'"
75
+ end
76
+
77
+ info[:full_version] = "#{info[:version]}-#{info[:release]}"
78
+
79
+ return info
80
+ end
81
+
82
+ # Loads metadata for a GPG key. The GPG key is to be used to sign RPMs. The
83
+ # value of gpg_key should be the full path of the directory where the key
84
+ # resides. If the metadata cannot be found, then the user will be prompted
85
+ # for it.
86
+ def self.load_key(gpg_key)
87
+ keydir = gpg_key
88
+ File.directory?(keydir) || fail("Error: Could not find '#{keydir}'")
89
+
90
+ gpg_key = File.basename(gpg_key)
91
+
92
+ if @@gpg_keys[gpg_key]
93
+ return @@gpg_keys[gpg_key]
94
+ end
95
+
96
+ gpg_name = nil
97
+ gpg_password = nil
98
+ begin
99
+ File.read("#{keydir}/gengpgkey").each_line do |ln|
100
+ name_line = ln.split(/^\s*Name-Email:/)
101
+ if name_line.length > 1
102
+ gpg_name = name_line.last.strip
103
+ end
104
+
105
+ passwd_line = ln.split(/^\s*Passphrase:/)
106
+ if passwd_line.length > 1
107
+ gpg_password = passwd_line.last.strip
108
+ end
109
+ end
110
+ rescue Errno::ENOENT
111
+ end
112
+
113
+ if gpg_name.nil?
114
+ puts "Warning: Could not find valid e-mail address for use with GPG."
115
+ puts "Please enter e-mail address to use:"
116
+ gpg_name = $stdin.gets.strip
117
+ end
118
+
119
+ if gpg_password.nil?
120
+ if File.exist?(%(#{keydir}/password))
121
+ gpg_password = File.read(%(#{keydir}/password)).chomp
122
+ end
123
+
124
+ if gpg_password.nil?
125
+ puts "Warning: Could not find a password in '#{keydir}/password'!"
126
+ puts "Please enter your GPG key password:"
127
+ system 'stty -echo'
128
+ gpg_password = $stdin.gets.strip
129
+ system 'stty echo'
130
+ end
131
+ end
132
+
133
+ @@gpg_keys[gpg_key] = { :dir => keydir, :name => gpg_name, :password => gpg_password }
134
+ end
135
+
136
+ # Signs the given RPM with the given gpg_key (see Simp::RPM.load_key for
137
+ # details on the value of this parameter).
138
+ def self.signrpm(rpm, gpg_key)
139
+ gpgkey = load_key(gpg_key)
140
+ signcommand = "rpm " +
141
+ "--define '%_signature gpg' " +
142
+ "--define '%_gpg_name #{gpgkey[:name]}' " +
143
+ "--define '%_gpg_path #{gpgkey[:dir]}' " +
144
+ "--resign #{rpm}"
145
+ begin
146
+ PTY.spawn(signcommand) do |read, write, pid|
147
+ begin
148
+ read.expect(/Enter pass phrase: /) do |text|
149
+ write.print("#{gpgkey[:password]}\n")
150
+ end
151
+ rescue Errno::EIO
152
+ # This ALWAYS happens in Ruby 1.8.
153
+ end
154
+ Process.wait(pid)
155
+ end
156
+ rescue Exception => e
157
+ puts "Error occured while attempting to sign #{rpm}, skipping."
158
+ puts e
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,37 @@
1
+ Name: testpackage
2
+ Version: 1
3
+ Release: 0%{?dist}
4
+ Summary: a test package
5
+
6
+ License: Apache-2.0
7
+ URL:
8
+ Source0:
9
+
10
+ BuildRequires:
11
+ Requires:
12
+
13
+ %description
14
+
15
+
16
+ %prep
17
+ %setup -q
18
+
19
+
20
+ %build
21
+ %configure
22
+ make %{?_smp_mflags}
23
+
24
+
25
+ %install
26
+ rm -rf $RPM_BUILD_ROOT
27
+ %make_install
28
+
29
+
30
+ %files
31
+ %doc
32
+
33
+
34
+
35
+ %changelog
36
+ * Wed Jun 10 2015 nobody
37
+ - some comment
@@ -0,0 +1,37 @@
1
+ Name: testpackage
2
+ Version: 1
3
+ Release: 0%{?dist}
4
+ Summary: a test package
5
+
6
+ License: Apache-2.0
7
+ URL:
8
+ Source0:
9
+
10
+ BuildRequires:
11
+ Requires:
12
+
13
+ %description
14
+
15
+
16
+ %prep
17
+ %setup -q
18
+
19
+
20
+ %build
21
+ %configure
22
+ make %{?_smp_mflags}
23
+
24
+
25
+ %install
26
+ rm -rf $RPM_BUILD_ROOT
27
+ %make_install
28
+
29
+
30
+ %files
31
+ %doc
32
+
33
+
34
+
35
+ %changelog
36
+ * Wed Jun 10 2015 nobody
37
+ - some comment
@@ -0,0 +1,15 @@
1
+ require 'simp/rake/helpers'
2
+ require 'spec_helper'
3
+
4
+ describe Simp::Rake::Helpers do
5
+ before :each do
6
+ @obj = Simp::Rake::Helpers.new
7
+ end
8
+
9
+ describe "#initialize" do
10
+ it "initialized (smoke test)" do
11
+ expect( @obj.class ).to eq Simp::Rake::Helpers
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,15 @@
1
+ require 'simp/rake/pkg'
2
+ require 'spec_helper'
3
+
4
+ describe Simp::Rake::Pkg do
5
+ before :all do
6
+ dir = File.expand_path( '../files', File.dirname( __FILE__ ) )
7
+ @obj = Simp::Rake::Pkg.new( dir )
8
+ end
9
+
10
+ describe "#initialize" do
11
+ it "initializes (smoke test)" do
12
+ expect( @obj.class ).to eq Simp::Rake::Pkg
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'simp/rake'
2
+ require 'spec_helper'
3
+
4
+ describe Simp::Rake do
5
+ RSpec.configure do |c|
6
+ c.include Simp::Rake
7
+ end
8
+
9
+ describe ".get_cpu_limit" do
10
+ it "detects number of CPUs" do
11
+ expect( get_cpu_limit ).to be > 0
12
+ end
13
+ end
14
+
15
+
16
+ describe 'tests are missing' do
17
+ it 'should have more tests' do
18
+ skip 'TODO: write more tests'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'simp/rpm'
2
+ require 'spec_helper'
3
+
4
+ describe Simp::RPM do
5
+ before :all do
6
+ dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
7
+ @spec_file = File.join( dir, 'testpackage.spec' )
8
+ @obj = Simp::RPM.new( @spec_file )
9
+ end
10
+
11
+ describe "#initialize" do
12
+ it "initializes (smoke test)" do
13
+ expect( @obj.class ).to eq Simp::RPM
14
+ end
15
+ end
16
+
17
+ describe ".get_info" do
18
+ it "extracts correct information from a .spec file" do
19
+ info = Simp::RPM.get_info(@spec_file)
20
+ expect( info.fetch( :name ) ).to eq 'testpackage'
21
+ expect( info.fetch( :version ) ).to eq '1'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
metadata ADDED
@@ -0,0 +1,285 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simp-rake-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Chris Tessmer
8
+ - Trevor Vaughan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10'
42
+ - !ruby/object:Gem::Dependency
43
+ name: coderay
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: puppet
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: puppet-lint
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: puppetlabs_spec_helper
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: parallel
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '1'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '1'
112
+ - !ruby/object:Gem::Dependency
113
+ name: gitlog-md
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: pry-doc
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: highline
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: '1.6'
161
+ - - '>'
162
+ - !ruby/object:Gem::Version
163
+ version: 1.6.1
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ~>
169
+ - !ruby/object:Gem::Version
170
+ version: '1.6'
171
+ - - '>'
172
+ - !ruby/object:Gem::Version
173
+ version: 1.6.1
174
+ - !ruby/object:Gem::Dependency
175
+ name: rspec
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: '3'
181
+ type: :development
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: '3'
188
+ - !ruby/object:Gem::Dependency
189
+ name: guard
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: '2'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ~>
200
+ - !ruby/object:Gem::Version
201
+ version: '2'
202
+ - !ruby/object:Gem::Dependency
203
+ name: guard-shell
204
+ requirement: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ~>
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ type: :development
210
+ prerelease: false
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ~>
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ - !ruby/object:Gem::Dependency
217
+ name: guard-rspec
218
+ requirement: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ~>
221
+ - !ruby/object:Gem::Version
222
+ version: '4'
223
+ type: :development
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ~>
228
+ - !ruby/object:Gem::Version
229
+ version: '4'
230
+ description: |2
231
+ "simp-rake-helpers provides common methods for SIMP Rake Tasks"
232
+ email: simp@simp-project.org
233
+ executables: []
234
+ extensions: []
235
+ extra_rdoc_files: []
236
+ files:
237
+ - .gitignore
238
+ - .rspec
239
+ - .travis.yml
240
+ - CHANGELOG.md
241
+ - CONTRIBUTING.md
242
+ - Gemfile
243
+ - Guardfile
244
+ - LICENSE
245
+ - README.md
246
+ - Rakefile
247
+ - bin/simp_rake_helpers
248
+ - lib/simp/rake.rb
249
+ - lib/simp/rake/helpers.rb
250
+ - lib/simp/rake/pkg.rb
251
+ - lib/simp/rpm.rb
252
+ - spec/lib/simp/files/build/testpackage.spec
253
+ - spec/lib/simp/files/testpackage.spec
254
+ - spec/lib/simp/rake/helpers_spec.rb
255
+ - spec/lib/simp/rake/pkg_spec.rb
256
+ - spec/lib/simp/rake_spec.rb
257
+ - spec/lib/simp/rpm_spec.rb
258
+ - spec/spec_helper.rb
259
+ homepage: https://github.com/simp/rubygem-simp-rake-helpers
260
+ licenses:
261
+ - Apache-2.0
262
+ metadata:
263
+ issue_tracker: https://github.com/simp/rubygem-simp-rake-helpers/issues
264
+ post_install_message:
265
+ rdoc_options: []
266
+ require_paths:
267
+ - lib
268
+ required_ruby_version: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - '>='
271
+ - !ruby/object:Gem::Version
272
+ version: '0'
273
+ required_rubygems_version: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - '>='
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ requirements: []
279
+ rubyforge_project:
280
+ rubygems_version: 2.4.6
281
+ signing_key:
282
+ specification_version: 4
283
+ summary: SIMP rake helpers
284
+ test_files: []
285
+ has_rdoc: