Module: ChkBuild
- Defined in:
- lib/chkbuild/lock.rb,
lib/chkbuild.rb,
lib/chkbuild/main.rb,
lib/chkbuild/build.rb,
lib/chkbuild/upload.rb,
lib/chkbuild/logfile.rb,
lib/chkbuild/options.rb,
lib/chkbuild/scm/git.rb,
lib/chkbuild/scm/svn.rb,
lib/chkbuild/targets/gcc.rb,
lib/chkbuild/targets/ruby.rb
Overview
Defined Under Namespace
Modules: GCC, Ruby
Classes: Build, LogFile, Target, Title, ViewVC
Constant Summary
collapse
- LOCK_PATH =
ChkBuild.build_top + '.lock'
- TOP_DIRECTORY =
Pathname.getwd
Class Method Summary
collapse
Class Method Details
.add_upload_hook(&block) ⇒ Object
28
29
30
|
# File 'lib/chkbuild/upload.rb', line 28
def self.add_upload_hook(&block)
@upload_hook << block
end
|
.build_top ⇒ Object
30
|
# File 'lib/chkbuild/main.rb', line 30
def ChkBuild.build_top() TOP_DIRECTORY+"tmp/build" end
|
.def_target(target_name, *args, &block) ⇒ Object
74
75
76
77
78
|
# File 'lib/chkbuild/main.rb', line 74
def ChkBuild.def_target(target_name, *args, &block)
t = ChkBuild::Target.new(target_name, *args, &block)
@target_list << t
t
end
|
.do_upload_rsync_ssh(rsync_target, private_key, name) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/chkbuild/upload.rb', line 50
def self.do_upload_rsync_ssh(rsync_target, private_key, name)
if %r{\A(?:([^@:]+)@)([^:]+)::(.*)\z} !~ rsync_target
raise "invalid rsync target: #{rsync_target.inspect}"
end
remote_user = $1 || ENV['USER'] || Etc.getpwuid.name
remote_host = $2
remote_path = $3
local_host = Socket.gethostname
private_key ||= "#{ENV['HOME']}/.ssh/chkbuild-#{local_host}-#{remote_host}"
pid = fork {
ENV.delete 'SSH_AUTH_SOCK'
exec "rsync", "--delete", "-rte", "ssh -akxi #{private_key}", "#{ChkBuild.public_top}/#{name}", "#{rsync_target}"
}
Process.wait pid
end
|
.get_limit ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/chkbuild/options.rb', line 53
def self.get_limit
ret = {}
@default_options.each {|k, v|
next if /\Alimit_/ !~ k.to_s
s = $'.intern
ret[s] = v
}
ret
end
|
.get_options ⇒ Object
34
35
36
|
# File 'lib/chkbuild/options.rb', line 34
def self.get_options
@default_options.dup
end
|
.limit(hash) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/chkbuild/options.rb', line 45
def self.limit(hash)
hash.each {|k, v|
s = "limit_#{k}".intern
raise "unexpected resource name: #{k}" if !@default_options[s]
@default_options[s] = v
}
end
|
.lock_puts(mesg) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/chkbuild/lock.rb', line 45
def self.lock_puts(mesg)
if block_given?
t1 = Time.now
@lock_io.print "#{t1.iso8601} #{mesg}"
ret = yield
t2 = Time.now
@lock_io.puts "\t#{t2-t1}"
ret
else
@lock_io.puts "#{Time.now.iso8601} #{mesg}"
end
end
|
.lock_start ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/chkbuild/lock.rb', line 28
def self.lock_start
if !defined?(@lock_io)
@lock_io = LOCK_PATH.open(File::WRONLY|File::CREAT)
end
if @lock_io.flock(File::LOCK_EX|File::LOCK_NB) == false
raise "another chkbuild is running."
end
@lock_io.truncate(0)
@lock_io.sync = true
@lock_io.close_on_exec = true
@lock_io.puts "locked pid:#{$$}"
lock_pid = $$
at_exit {
@lock_io.puts "exit pid:#{$$}" if $$ == lock_pid
}
end
|
.main ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/chkbuild/main.rb', line 124
def ChkBuild.main
ARGV.unshift 'build' if ARGV.empty?
subcommand = ARGV.shift
case subcommand
when 'help', '-h' then ChkBuild.main_help
when 'build' then ChkBuild.main_build
when 'list' then ChkBuild.main_list
when 'title' then ChkBuild.main_title
when 'logdiff' then ChkBuild.main_logdiff
else
puts "unexpected subcommand: #{subcommand}"
exit 1
end
end
|
.main_build ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/chkbuild/main.rb', line 52
def ChkBuild.main_build
o = OptionParser.new
o.def_option('--procmemsize') {
@target_list.each {|t|
t.update_option(:procmemsize => true)
}
}
o.parse!
begin
Process.setpriority(Process::PRIO_PROCESS, 0, 10)
rescue Errno::EACCES
end
File.umask(002)
STDIN.reopen("/dev/null", "r")
STDOUT.sync = true
ChkBuild.build_top.mkpath
ChkBuild.lock_start
@target_list.each {|t|
t.make_result
}
end
|
.main_help(status = true) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chkbuild/main.rb', line 33
def ChkBuild.main_help(status=true)
if File.executable? $0
command = $0
else
require 'rbconfig'
ruby = "#{Config::CONFIG["bindir"]}/#{Config::CONFIG["ruby_install_name"]}"
command = "#{ruby} #{$0}"
end
print "usage:\n\#{command} [build [--procmemsize]]\n\#{command} list\n\#{command} title [depsuffixed_name...]\n\#{command} logdiff [depsuffixed_name [date1 [date2]]]\n"
exit status
end
|
.main_list ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/chkbuild/main.rb', line 80
def ChkBuild.main_list
@target_list.each {|t|
t.each_build_obj {|build|
puts build.depsuffixed_name
}
}
end
|
.main_logdiff ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/chkbuild/main.rb', line 103
def ChkBuild.main_logdiff
depsuffixed_name, arg_t1, arg_t2 = ARGV
@target_list.each {|t|
t.each_build_obj {|build|
next if depsuffixed_name && build.depsuffixed_name != depsuffixed_name
ts = build.log_time_sequence
raise "no log: #{build.depsuffixed_name}/#{arg_t1}" if arg_t1 and !ts.include?(arg_t1)
raise "no log: #{build.depsuffixed_name}/#{arg_t2}" if arg_t2 and !ts.include?(arg_t2)
if ts.length < 2
puts "#{build.depsuffixed_name}: less than 2 logs"
next
end
t1 = arg_t1 || ts[-2]
t2 = arg_t2 || ts[-1]
puts "#{build.depsuffixed_name}: #{t1}->#{t2}"
build.output_diff(t1, t2, STDOUT)
puts
}
}
end
|
.main_title ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/chkbuild/main.rb', line 88
def ChkBuild.main_title
@target_list.each {|t|
t.each_build_obj {|build|
next if !ARGV.empty? && !ARGV.include?(build.depsuffixed_name)
last_txt = ChkBuild.public_top + build.depsuffixed_name + 'last.txt'
if last_txt.exist?
logfile = ChkBuild::LogFile.read_open(last_txt)
title = ChkBuild::Title.new(t, logfile)
title.run_hooks
puts "#{build.depsuffixed_name}:\t#{title.make_title}"
end
}
}
end
|
.num_oldbuilds ⇒ Object
38
39
40
|
# File 'lib/chkbuild/options.rb', line 38
def self.num_oldbuilds
@default_options[:num_oldbuilds]
end
|
.num_oldbuilds=(val) ⇒ Object
41
42
43
|
# File 'lib/chkbuild/options.rb', line 41
def self.num_oldbuilds=(val)
@default_options[:num_oldbuilds] = val
end
|
.public_top ⇒ Object
31
|
# File 'lib/chkbuild/main.rb', line 31
def ChkBuild.public_top() TOP_DIRECTORY+"tmp/public_html" end
|
.rsync_ssh_upload_target(rsync_target, private_key = nil) ⇒ Object
44
45
46
47
48
|
# File 'lib/chkbuild/upload.rb', line 44
def self.rsync_ssh_upload_target(rsync_target, private_key=nil)
self.add_upload_hook {|name|
self.do_upload_rsync_ssh(rsync_target, private_key, name)
}
end
|
.run_upload_hooks(suffixed_name) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/chkbuild/upload.rb', line 32
def self.run_upload_hooks(suffixed_name)
@upload_hook.reverse_each {|block|
begin
block.call suffixed_name
rescue Exception
p $!
end
}
end
|