simp-rake-helpers 1.0.15 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ require 'simp/rake/build/constants'
2
+
3
+ module Simp; end
4
+ module Simp::Rake; end
5
+ module Simp::Rake::Build
6
+
7
+ class Clean < ::Rake::TaskLib
8
+ include Simp::Rake::Build::Constants
9
+
10
+ def initialize( base_dir )
11
+ init_member_vars( base_dir )
12
+ define_tasks
13
+ end
14
+
15
+ def define_tasks
16
+ ::CLEAN.include(
17
+ "#{@dist_dir}/*",
18
+ ".discinfo",
19
+ @dvd_dir,
20
+ "#{@build_dir}/SIMP",
21
+ "#{@base_dir}/SIMP_ISO*"
22
+ )
23
+
24
+ ::CLOBBER.include(
25
+ @dist_dir,
26
+ "#{@build_dir}/build_keys/dev",
27
+ "#{@build_dir}/yum_data/*/packages"
28
+ )
29
+
30
+ # This just abstracts the clean/clobber space in such a way that clobber can actally be used!
31
+ def advanced_clean(type,args)
32
+ fail "Type must be one of 'clean' or 'clobber'" unless ['clean','clobber'].include?(type)
33
+
34
+ validate_in_mock_group?
35
+
36
+ mock_dirs = Dir.glob("/var/lib/mock/*").map{|x| x = File.basename(x) }
37
+
38
+ if not mock_dirs.empty? and not args.chroot then
39
+ $stderr.puts "Notice: You must pass a Mock chroot to erase a specified build root."
40
+ end
41
+
42
+ Rake::Task["pkg:#{type}"].invoke(args.chroot)
43
+ end
44
+
45
+ task :clobber,[:chroot] do |t,args|
46
+ advanced_clean('clobber',args)
47
+ end
48
+
49
+ task :clean,[:chroot] do |t,args|
50
+ advanced_clean('clean',args)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,150 @@
1
+ require 'simp/rake'
2
+ require 'simp/rake/build/constants'
3
+
4
+ module Simp; end
5
+ module Simp::Rake; end
6
+ module Simp::Rake::Build
7
+
8
+ class Code < ::Rake::TaskLib
9
+ include Simp::Rake
10
+ include Simp::Rake::Build::Constants
11
+
12
+ def initialize( base_dir )
13
+ init_member_vars( base_dir )
14
+ define_tasks
15
+ end
16
+
17
+ def define_tasks
18
+ namespace :code do
19
+
20
+ desc "Show some basic stats. Uses git to figure out what has changed.
21
+ * :since - Do not include any stats before this date.
22
+ * :until - Do not include any stats after this date."
23
+ task :stats,[:since,:until] do |t,args|
24
+ cur_branch = %x{git rev-parse --abbrev-ref HEAD}.chomp
25
+
26
+ if cur_branch.empty? then
27
+ fail "Error: Could not find branch ID!"
28
+ end
29
+
30
+ changed = 0
31
+ new = 0
32
+ removed = 0
33
+
34
+ cmd = "git log --shortstat --reverse --pretty=oneline"
35
+
36
+ if args.since then
37
+ cmd = cmd + " --since=#{args.since}"
38
+ end
39
+ if args.until then
40
+ cmd = cmd + " --until=#{args.until}"
41
+ end
42
+
43
+ %x{#{cmd}}.each_line do |line|
44
+ if encode_line(line) =~ /(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*/ then
45
+ changed = changed + $1.to_i
46
+ new = new + $2.to_i
47
+ removed = removed + $3.to_i
48
+ end
49
+ end
50
+
51
+ cmd = "git submodule foreach git log --shortstat --reverse --pretty=oneline"
52
+
53
+ if args.since then
54
+ cmd = cmd + " --since=#{args.since}"
55
+ end
56
+ if args.until then
57
+ cmd = cmd + " --until=#{args.until}"
58
+ end
59
+
60
+ %x{#{cmd}}.each_line do |line|
61
+ if encode_line(line) =~ /(\d+) files changed, (\d+) insertions\(\+\), (\d+) del.*/ then
62
+ changed = changed + $1.to_i
63
+ new = new + $2.to_i
64
+ removed = removed + $3.to_i
65
+ end
66
+ end
67
+
68
+ puts "Code Stats for #{cur_branch}:"
69
+ printf " Files Changed: %6d\n", changed
70
+ printf " New Lines: %6d\n", new
71
+ printf " Removed Lines: %6d\n", removed
72
+ end # End of :stats task.
73
+
74
+ desc "Show line count. Prints a report of the lines of code in the source.
75
+ * :show_unknown - Flag for displaying any file extensions not expected."
76
+ task :count,[:show_unknown] do |t,args|
77
+ require 'find'
78
+
79
+ loc = Hash.new
80
+ loc["rake"] = 0
81
+ loc["pp"] = 0
82
+ loc["rb"] = 0
83
+ loc["erb"] = 0
84
+ loc["sh"] = 0
85
+ loc["csh"] = 0
86
+ loc["html"] = 0
87
+ loc["spec"] = 0
88
+ loc["other"] = 0
89
+
90
+ File.open("#{SRC_DIR}/../Rakefile","r").each do |line|
91
+ if encode_line(line) !~ /^\s*$/ then
92
+ loc["rake"] = loc["rake"] + 1
93
+ end
94
+ end.close
95
+
96
+ other_ext = Array.new
97
+
98
+ Find.find(SRC_DIR) do |path|
99
+ if (
100
+ ( File.basename(path)[0] == ?. ) or
101
+ ( path =~ /src\/rsync/ ) or
102
+ ( path[-3..-1] =~ /\.gz|pem|pub/ ) or
103
+ ( path =~ /developers_guide\/rdoc/ )
104
+ ) then
105
+ Find.prune
106
+ else
107
+ next if FileTest.symlink?(path) or FileTest.directory?(path)
108
+ end
109
+
110
+ ext = File.extname(path)[1..-1]
111
+ if not ext then ext = 'none' end
112
+ if not loc[ext] then
113
+ other_ext.push(ext) if not other_ext.include?(ext)
114
+ ext = 'other'
115
+ end
116
+
117
+ File.open(path,'r').each do |line|
118
+ if encode_line(line) !~ /^\s*$/ then
119
+ loc[ext] = loc[ext] + 1
120
+ end
121
+ end
122
+ end
123
+
124
+ puts "Code Count Report:"
125
+ printf " %-6s %6s\n", "Ext", "Count"
126
+ puts " " + ("-" * 13)
127
+
128
+ total_loc = 0
129
+ loc.sort.each do |key,val|
130
+ printf " %-6s %6d\n", key, val
131
+ total_loc = total_loc + val
132
+ end
133
+
134
+ puts " " + ("-" * 13)
135
+ printf " %-6s %6d\n", "Total", "#{total_loc}"
136
+ puts
137
+ puts "Unknown Extension Count: #{other_ext.length}"
138
+
139
+ if args.show_unknown then
140
+ puts "Unknown Extensions:"
141
+ other_ext.sort.each do |ext|
142
+ puts " #{ext}"
143
+ end
144
+ end
145
+ end # End of :count task.
146
+
147
+ end # End of :code namespace.
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,23 @@
1
+ require 'rake/tasklib'
2
+
3
+ module Simp::Rake; end
4
+ module Simp::Rake::Build; end
5
+ module Simp::Rake::Build::Constants
6
+ def init_member_vars( base_dir )
7
+ @run_dir = Dir.pwd
8
+ @base_dir = base_dir
9
+ @build_arch = ENV['buld_arch'] || %x{#{:facter} hardwaremodel 2>/dev/null}.chomp
10
+ @build_dir = "#{@base_dir}/build"
11
+ @dist_dir = "#{@build_dir}/dist"
12
+ @dvd_dir = "#{@build_dir}/DVD_Overlay"
13
+ @src_dir = "#{@base_dir}/src"
14
+ @dvd_src = "#{@src_dir}/DVD"
15
+ @spec_dir = "#{@src_dir}/build"
16
+ @spec_file = FileList["#{@spec_dir}/*.spec"]
17
+ @target_dists = ['CentOS','RHEL'] # The first item is the default build...
18
+ @simp_version = Simp::RPM.get_info("#{@spec_dir}/simp.spec")[:full_version]
19
+ @rhel_version = ENV['rhel_version'] || '6'
20
+ @simp_dvd_dirs = ["SIMP","ks","Config"]
21
+ end
22
+ end
23
+
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/rake -T
2
+
3
+ require 'yaml'
4
+
5
+ class FakeLibrarian
6
+ attr_reader :forge, :environment
7
+ attr_accessor :puppetfile
8
+ attr_writer :modules
9
+
10
+ require 'librarian/puppet/util'
11
+ include Librarian::Puppet::Util
12
+
13
+ require 'librarian/puppet/environment'
14
+ require 'librarian/puppet/source/git'
15
+
16
+ def initialize(puppetfile)
17
+ @environment = Librarian::Puppet::Environment.new
18
+ if puppetfile
19
+ @puppetfile = Pathname.new(puppetfile)
20
+
21
+ unless @puppetfile.absolute?
22
+ @puppetfile = File.expand_path(@puppetfile,@environment.project_path)
23
+ end
24
+ end
25
+ end
26
+
27
+ def modules
28
+ @modules ||= {}
29
+
30
+ if @modules.empty?
31
+ txt = File.readlines(@puppetfile)
32
+ eval(txt.join)
33
+ end
34
+
35
+ @modules
36
+ end
37
+
38
+ # Return a list of modules that are in the install path but not known to the
39
+ # Puppetfile
40
+ def unknown_modules
41
+ known_modules = []
42
+ all_modules = Dir.glob(File.join(@environment.install_path,'*')).map{|x| x = File.basename(x)}
43
+
44
+ relative_path = @environment.install_path.to_s.split(@environment.project_path.to_s).last
45
+ relative_path[0] = '' if relative_path[0].chr == File::SEPARATOR
46
+
47
+ unless all_modules.empty?
48
+ modules.each do |name,opts|
49
+ known_modules << module_name(name)
50
+ end
51
+ end
52
+
53
+ module_list = (all_modules - known_modules).map do |x|
54
+ if File.exist?(File.join(@environment.install_path,x,'metadata.json'))
55
+ x = File.join(relative_path,x)
56
+ else
57
+ x = nil
58
+ end
59
+ end
60
+
61
+ module_list.compact
62
+ end
63
+
64
+ def puppetfile
65
+ str = StringIO.new
66
+ str.puts "forge '#{@forge}'\n\n" if @forge
67
+ modules.each do |name,opts|
68
+ str.puts "mod '#{name}',"
69
+ str.puts (opts.map{|k,v| " :#{k} => '#{v}'"}).join(",\n") , ''
70
+ end
71
+ str.string
72
+ end
73
+
74
+ def each_module(&block)
75
+ Dir.chdir(@environment.project_path) do
76
+ modules.each do |name,mod|
77
+ # This works for Puppet Modules
78
+ path = File.expand_path(module_name(name),environment.install_path)
79
+ unless File.directory?(path)
80
+ # This works for everything else
81
+ if mod[:path]
82
+ path = File.expand_path(mod[:path],environment.project_path)
83
+ end
84
+ end
85
+ unless File.directory?(path)
86
+ $stderr.puts("Warning: Could not find path for module '#{name}'...skipping")
87
+ next
88
+ end
89
+
90
+ block.call(@environment,name,path)
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def mod(name,args)
98
+ @modules[name] = args
99
+ end
100
+
101
+ def forge(forge)
102
+ @forge = forge
103
+ end
104
+ end
105
+
106
+ module Simp; end
107
+ module Simp::Rake; end
108
+ module Simp::Rake::Build
109
+ class Deps < ::Rake::TaskLib
110
+ def initialize( base_dir )
111
+ @base_dir = base_dir
112
+ define_tasks
113
+ end
114
+
115
+ # define rake tasks
116
+ def define_tasks
117
+ namespace :deps do
118
+ desc <<-EOM
119
+ Checks out all dependency repos.
120
+
121
+ This task runs 'librarian-puppet' and updates all dependencies.
122
+
123
+ Arguments:
124
+ * :method => The update method to use (Default => 'tracking')
125
+ tracking => checks out each dep (by branch) according to Puppetfile.tracking
126
+ stable => checks out each dep (by ref) according to in Puppetfile.stable
127
+ EOM
128
+ task :checkout, [:method] do |t,args|
129
+ args.with_defaults(:method => 'tracking')
130
+
131
+ Dir.chdir @base_dir
132
+ FileUtils.ln_s( "Puppetfile.#{args[:method]}", 'Puppetfile', :force => true )
133
+ Bundler.with_clean_env do
134
+ sh 'bundle exec librarian-puppet-pr328 install --use-forge=false'
135
+ end
136
+ FileUtils.remove_entry_secure "Puppetfile"
137
+ end
138
+
139
+ desc <<-EOM
140
+ Get the status of the project Git repositories
141
+
142
+ Arguments:
143
+ * :method => The update method to use (Default => 'tracking')
144
+ tracking => checks out each dep (by branch) according to Puppetfile.tracking
145
+ stable => checks out each dep (by ref) according to in Puppetfile.stable
146
+ EOM
147
+ task :status, [:method] do |t,args|
148
+ args.with_defaults(:method => 'tracking')
149
+ Dir.chdir @base_dir
150
+ @dirty_repos = nil
151
+
152
+ fake_lp = FakeLibrarian.new("Puppetfile.#{args[:method]}")
153
+ mods_with_changes = {}
154
+
155
+ fake_lp.each_module do |environment, name, path|
156
+ unless File.directory?(path)
157
+ $stderr.puts("Warning: '#{path}' is not a module...skipping")
158
+ next
159
+ end
160
+
161
+ repo = Librarian::Puppet::Source::Git::Repository.new(environment,path)
162
+ if repo.dirty?
163
+ # Clean up the path a bit for printing
164
+ dirty_path = path.split(environment.project_path.to_s).last
165
+ if dirty_path[0].chr == File::SEPARATOR
166
+ dirty_path[0] = ''
167
+ end
168
+
169
+ mods_with_changes[name] = dirty_path
170
+ end
171
+ end
172
+
173
+ if mods_with_changes.empty?
174
+ puts "No repositories have changes."
175
+ @dirty_repos = false
176
+ else
177
+ puts "The following repositories have changes:"
178
+ puts mods_with_changes.map{|k,v| " + #{k} => #{v}"}.join("\n")
179
+
180
+ @dirty_repos = true
181
+ end
182
+
183
+ unknown_mods = fake_lp.unknown_modules
184
+ unless unknown_mods.empty?
185
+ puts "The following modules were unknown:"
186
+ puts unknown_mods.map{|k,v| " ? #{k}"}.join("\n")
187
+ end
188
+ end
189
+
190
+ desc 'Records the current dependencies into Puppetfile.stable.'
191
+ task :record do
192
+ fake_lp = FakeLibrarian.new('Puppetfile.tracking')
193
+ modules = fake_lp.modules
194
+
195
+ fake_lp.each_module do |environment, name, path|
196
+ Dir.chdir(path) do
197
+ modules[name][:ref] = %x{git rev-parse --verify HEAD}.strip
198
+ end
199
+ end
200
+
201
+ fake_lp.modules = modules
202
+ File.open('Puppetfile.stable','w'){|f| f.puts fake_lp.puppetfile }
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,26 @@
1
+ require 'rake/tasklib'
2
+ require 'ruby-progressbar'
3
+ require 'rake/clean'
4
+
5
+ module Simp; end
6
+ module Simp::Rake; end
7
+ module Simp::Rake::Build; end
8
+ class Simp::Rake::Build::Helpers
9
+ def initialize( dir = Dir.pwd )
10
+ Dir[ File.join(File.dirname(__FILE__),'*.rb') ].each do |rake_file|
11
+ next if rake_file == __FILE__
12
+ require rake_file
13
+ end
14
+ Simp::Rake::Build::Auto.new( dir )
15
+ Simp::Rake::Build::Build.new( dir )
16
+ Simp::Rake::Build::Clean.new( dir )
17
+ Simp::Rake::Build::Code.new( dir )
18
+ Simp::Rake::Build::Deps.new( dir )
19
+ Simp::Rake::Build::Iso.new( dir )
20
+ Simp::Rake::Build::Pkg.new( dir )
21
+ Simp::Rake::Build::Spec.new( dir )
22
+ Simp::Rake::Build::Tar.new( dir )
23
+ Simp::Rake::Build::Upload.new( dir )
24
+ Simp::Rake::Build::Unpack.new( dir )
25
+ end
26
+ end