fully parallelize the CFile builder
This commit is contained in:
parent
145d51c825
commit
178940cd5d
4
build_tests/cfile/Rsconsfile
Normal file
4
build_tests/cfile/Rsconsfile
Normal file
@ -0,0 +1,4 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env.CFile("lexer.c", "lexer.l")
|
||||
env.CFile("parser.c", "parser.y")
|
||||
end
|
3
build_tests/cfile/error_unknown_extension.rb
Normal file
3
build_tests/cfile/error_unknown_extension.rb
Normal file
@ -0,0 +1,3 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env.CFile("file.c", "foo.bar")
|
||||
end
|
4
build_tests/cfile/lexer.l
Normal file
4
build_tests/cfile/lexer.l
Normal file
@ -0,0 +1,4 @@
|
||||
%{
|
||||
%}
|
||||
|
||||
%%
|
9
build_tests/cfile/parser.y
Normal file
9
build_tests/cfile/parser.y
Normal file
@ -0,0 +1,9 @@
|
||||
%{
|
||||
%}
|
||||
|
||||
%token ONE
|
||||
|
||||
%%
|
||||
|
||||
one: ONE
|
||||
;
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user