You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libshit/tools/ci_conf.iwyu.rb

70 lines
2.0 KiB
Ruby

step :iwyu_setup do
opt.os = 'linux'
opt.architecture = 'amd64'
opt.compiler = 'gcc'
opt.mode = 'debug'
opt.lua = 'lua'
opt.is_cross = false
opt.is_iwyu = true
opt.iwyu_targets ||= %w(
libshit-lua-gen-hdr libshit-translate-generate
translate-gen-libshit-test-builtin)
end
iwyu_cond = -> { opt.is_iwyu }
step :iwyu_opts, always_after: :default_values, before: :final_opts, cond: iwyu_cond do
opt.config_opts.append '--luac-mode=copy'
opt.build_opts.append "--targets=#{opt.iwyu_targets.join ','}"
end
step :iwyu_build_if_needed, after: :do_build, cond: -> { !opt.iwyu_targets.empty? }
def parallel_run dir, files, keep_going: true
calc_env []
print_cd dir
Signal.trap 'CHLD', 'DEFAULT'
files_mtx = Mutex.new
console_mtx = Mutex.new
failed = false
n = files.size
digits = n.to_s.size # ehh...
i = 0
einfo "Running #{n} tasks with -j#{opt.jobs}#{keep_going ? ' -k' : ''}"
opt.jobs.times.map do
Thread.new do
loop do
f = files_mtx.synchronize do
break if failed && !keep_going
files.pop
end
break unless f
args = yield f
out, err, st = Open3.capture3 @last_env, *args, chdir: dir
files_mtx.synchronize { failed = true } unless st.success?
console_mtx.synchronize do
ecmd format '[%*d/%d] %s', digits, i+=1, n, args.shelljoin
$stdout.write out
$stderr.write err
eerror "Command failure: #{st}" unless st.success?
end
end
end
# somewhy Thread.join deadlocks sometimes when failing, but not with a timeout
end.each { |t| nil until t.join 1 }
fail 'Parallell commands failed' if failed
end
step :iwyu, after: [:iwyu_setup, :prepare_checkout, :iwyu_build_if_needed] do
fail if opt.is_cross || !opt.is_iwyu
Linux.clonens_wait do
files = Dir.glob '{src,test}/**/*.[ch]{,pp}', base: opt.base_dir
env.build_dir = File.join opt.run_dir, 'build'
cd = rel_from opt.base_dir, opt.run_dir
parallel_run(opt.base_dir, files) {|f| ['./iwyu.sh', f] }
end
end