fully parallelize the CFile builder

This commit is contained in:
Josh Holtrop 2017-05-25 15:28:01 -04:00
parent 145d51c825
commit 178940cd5d
7 changed files with 58 additions and 29 deletions

View File

@ -0,0 +1,4 @@
Rscons::Environment.new do |env|
env.CFile("lexer.c", "lexer.l")
env.CFile("parser.c", "parser.y")
end

View File

@ -0,0 +1,3 @@
Rscons::Environment.new do |env|
env.CFile("file.c", "foo.bar")
end

View File

@ -0,0 +1,4 @@
%{
%}
%%

View File

@ -0,0 +1,9 @@
%{
%}
%token ONE
%%
one: ONE
;

View File

@ -7,6 +7,7 @@ module Rscons
# env.CFile("parser.tab.cc", "parser.yy")
# env.CFile("lex.yy.cc", "parser.ll")
class CFile < Builder
# Return default construction variables for the builder.
#
# @param env [Environment] The Environment using the builder.
@ -48,8 +49,20 @@ module Rscons
raise "Unknown source file #{sources.first.inspect} for CFile builder"
end
command = env.build_command("${#{cmd}_CMD}", vars)
standard_build("#{cmd} #{target}", target, command, sources, env, cache)
standard_threaded_build("#{cmd} #{target}", target, command, sources, env, cache)
end
# Finalize a build.
#
# @param options [Hash]
# Finalize options.
#
# @return [String, nil]
# The target name on success or nil on failure.
def finalize(options)
standard_finalize(options)
end
end
end
end

View File

@ -682,6 +682,30 @@ EOF
end
end
context "CFile builder" do
it "builds a .c file using flex and bison" do
test_dir("cfile")
result = run_test
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
"LEX lexer.c",
"YACC parser.c",
]
result = run_test
expect(result.stderr).to eq ""
expect(result.stdout).to eq ""
end
it "raises an error when an unknown source file is specified" do
test_dir("cfile")
result = run_test(rsconsfile: "error_unknown_extension.rb")
expect(result.stderr).to match /Unknown source file .foo.bar. for CFile builder/
expect(result.status).to_not eq 0
end
end
context "Directory builder" do
it "creates the requested directory" do
test_dir("simple")

View File

@ -1,28 +0,0 @@
module Rscons
module Builders
describe CFile do
let(:env) {Environment.new}
subject {CFile.new}
it "invokes bison to create a .c file from a .y file" do
expect(subject).to receive(:standard_build).with("YACC parser.c", "parser.c", ["bison", "-d", "-o", "parser.c", "parser.y"], ["parser.y"], env, :cache)
subject.run("parser.c", ["parser.y"], :cache, env, {})
end
it "invokes a custom lexer to create a .cc file from a .ll file" do
env["LEX"] = "custom_lex"
expect(subject).to receive(:standard_build).with("LEX lexer.cc", "lexer.cc", ["custom_lex", "-o", "lexer.cc", "parser.ll"], ["parser.ll"], env, :cache)
subject.run("lexer.cc", ["parser.ll"], :cache, env, {})
end
it "supports overriding construction variables" do
expect(subject).to receive(:standard_build).with("LEX lexer.c", "lexer.c", ["hi", "parser.l"], ["parser.l"], env, :cache)
subject.run("lexer.c", ["parser.l"], :cache, env, "LEX_CMD" => ["hi", "${_SOURCES}"])
end
it "raises an error when an unknown source file is specified" do
expect {subject.run("file.c", ["foo.bar"], :cache, env, {})}.to raise_error /Unknown source file .foo.bar. for CFile builder/
end
end
end
end