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/gen_binding.rb

119 lines
2.7 KiB
Ruby

#! /usr/bin/env ruby
# frozen_string_literal: true
ENV['LIBCLANG'] = "#{ENV['PREFIX']}/lib/libclang.so" if ENV['PREFIX']
require_relative 'gen_binding/dump'
require_relative 'gen_binding/lua'
require_relative 'gen_binding/main'
require_relative 'gen_binding/util'
require 'etc'
require 'optparse'
Parser.add_opts %W(
-DLIBSHIT_BINDING_GENERATOR
-DLIBSHIT_WITH_LUA=1
-nostdinc++
-D_LIBCPP_NO_CONFIG
-isystem #{__dir__}/ext/libcxx/libcxx/include
-isystem #{__dir__}/ext/libcxx/libcxxabi/include
-I#{__dir__}/src
-I#{__dir__}/ext/boost/boost
-I#{__dir__}/ext/lua/lua-5.3.6/src
-I#{__dir__}/ext/doctest/doctest/doctest
)
Parser.add_src [LuaBinding], %w(
test/container/ordered_map.cpp
test/container/parent_list.cpp
test/lua/function_ref.cpp
test/lua/user_type.cpp
).map {|f| File.join __dir__, f }
def main
jobs = Etc.nprocessors
single = false
dump = nil
if i = ARGV.index('--')
ARGV.insert i, '--'
end
OptionParser.new do |opt|
opt.banner = "Usage #$0 [options] files..."
opt.on '-j', '--jobs=N', Integer,
'Set job number (default: number of CPUs)' do |v|
jobs = v
end
opt.on '--single', 'Run single job (specify in, out, extra clang args)' do
single = true
end
opt.on '--dump=FILE' do |v|
dump = v
end
end.parse!
if single
Parser.gen_binding ARGV[0], ARGV[1], ARGV[2..]
elsif dump
Dumper.dump Parser.new.parse dump, ARGV
else
files, args = ARGV.slice_before('--').to_a
files ||= []
args ||= []
args.shift
src = files.empty? ? Parser.src.keys : files
i = 0
n = src.size
digits = n.to_s.size # ehh...
if jobs <= 1 || n <= 1
src.each do |f|
CI.einfo format '[%*d/%d] %s', digits, i+=1, n, f
begin
Parser.gen_binding f, nil, args
rescue
Util.print_error $!
end
end
else
files_mtx = Mutex.new
console_mtx = Mutex.new
jobs.times.map do
Thread.new do
loop do
f = files_mtx.synchronize { src.pop } || break
rd, wr = IO.pipe
pid = fork do
rd.close
$stdout = wr
$stderr = wr
Parser.gen_binding f, nil, args
exit Util.success?
rescue
Util.print_error $!
exit! false
end
wr.close
out = rd.read
Process.wait pid
console_mtx.synchronize do
CI.einfo format '[%*d/%d] %s', digits, i+=1, n, f
$stderr.write out
Util.fail! unless $?.success?
end
end
end
end.each { |t| nil until t.join 1 }
end
end
exit Util.success?
end
main if __FILE__ == $0