From 178940cd5dd70ff5988ac01fa6cb550c6ad9b9a4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 25 May 2017 15:28:01 -0400 Subject: [PATCH] fully parallelize the CFile builder --- build_tests/cfile/Rsconsfile | 4 +++ build_tests/cfile/error_unknown_extension.rb | 3 +++ build_tests/cfile/lexer.l | 4 +++ build_tests/cfile/parser.y | 9 +++++++ lib/rscons/builders/cfile.rb | 15 ++++++++++- spec/build_tests_spec.rb | 24 +++++++++++++++++ spec/rscons/builders/cfile_spec.rb | 28 -------------------- 7 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 build_tests/cfile/Rsconsfile create mode 100644 build_tests/cfile/error_unknown_extension.rb create mode 100644 build_tests/cfile/lexer.l create mode 100644 build_tests/cfile/parser.y delete mode 100644 spec/rscons/builders/cfile_spec.rb diff --git a/build_tests/cfile/Rsconsfile b/build_tests/cfile/Rsconsfile new file mode 100644 index 0000000..41308ec --- /dev/null +++ b/build_tests/cfile/Rsconsfile @@ -0,0 +1,4 @@ +Rscons::Environment.new do |env| + env.CFile("lexer.c", "lexer.l") + env.CFile("parser.c", "parser.y") +end diff --git a/build_tests/cfile/error_unknown_extension.rb b/build_tests/cfile/error_unknown_extension.rb new file mode 100644 index 0000000..ad62f52 --- /dev/null +++ b/build_tests/cfile/error_unknown_extension.rb @@ -0,0 +1,3 @@ +Rscons::Environment.new do |env| + env.CFile("file.c", "foo.bar") +end diff --git a/build_tests/cfile/lexer.l b/build_tests/cfile/lexer.l new file mode 100644 index 0000000..d0c6f0d --- /dev/null +++ b/build_tests/cfile/lexer.l @@ -0,0 +1,4 @@ +%{ +%} + +%% diff --git a/build_tests/cfile/parser.y b/build_tests/cfile/parser.y new file mode 100644 index 0000000..1657847 --- /dev/null +++ b/build_tests/cfile/parser.y @@ -0,0 +1,9 @@ +%{ +%} + +%token ONE + +%% + +one: ONE + ; diff --git a/lib/rscons/builders/cfile.rb b/lib/rscons/builders/cfile.rb index 7534628..b935337 100644 --- a/lib/rscons/builders/cfile.rb +++ b/lib/rscons/builders/cfile.rb @@ -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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index db51d95..af71f26 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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") diff --git a/spec/rscons/builders/cfile_spec.rb b/spec/rscons/builders/cfile_spec.rb deleted file mode 100644 index 93ac23a..0000000 --- a/spec/rscons/builders/cfile_spec.rb +++ /dev/null @@ -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