fully parallelize the Command builder

This commit is contained in:
Josh Holtrop 2017-05-25 16:03:05 -04:00
parent 80a80a7cb0
commit 68468b6422
4 changed files with 40 additions and 26 deletions

View File

@ -0,0 +1,7 @@
Rscons::Environment.new do |env|
command = %W[gcc -o ${_TARGET} ${_SOURCES}]
env.Command("simple.exe",
"simple.c",
"CMD" => command,
"CMD_DESC" => "BuildIt")
end

View File

@ -9,16 +9,14 @@ module Rscons
# env.Command("docs.html", "docs.md",
# CMD => %w[pandoc -fmarkdown -thtml -o${_TARGET} ${_SOURCES}])
class Command < Builder
# Run the builder to produce a build target.
#
# @param target [String] Target file name.
# @param sources [Array<String>] Source file name(s).
# @param cache [Cache] The Cache object.
# @param env [Environment] The Environment executing the builder.
# @param vars [Hash,VarSet] Extra construction variables.
# @param options [Hash] Builder run options.
#
# @return [String,false]
# Name of the target file on success or false on failure.
# @return [String, ThreadedCommand]
# Target file name if target is up to date or a {ThreadedCommand}
# to execute to build the target.
def run(target, sources, cache, env, vars)
vars = vars.merge({
"_TARGET" => target,
@ -26,8 +24,20 @@ module Rscons
})
command = env.build_command("${CMD}", vars)
cmd_desc = vars["CMD_DESC"] || "Command"
standard_build("#{cmd_desc} #{target}", target, command, sources, env, cache)
standard_threaded_build("#{cmd_desc} #{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

@ -706,6 +706,21 @@ EOF
end
end
context "Command builder" do
it "allows executing an arbitrary command" do
test_dir('simple')
result = run_test(rsconsfile: "command_builder.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["BuildIt simple.exe"]
expect(`./simple.exe`).to eq "This is a simple C program\n"
result = run_test(rsconsfile: "command_builder.rb")
expect(result.stderr).to eq ""
expect(result.stdout).to eq ""
end
end
context "Directory builder" do
it "creates the requested directory" do
test_dir("simple")

View File

@ -1,18 +0,0 @@
module Rscons
module Builders
describe Command do
let(:command) { ['pandoc', '-fmarkdown', '-thtml', '-o${_TARGET}', '${_SOURCES}'] }
let(:env) {Environment.new}
subject {Command.new}
it "invokes the command to build the target" do
expected_cmd = ['pandoc', '-fmarkdown', '-thtml', '-ofoo.html', 'foo.md']
expect(subject).to receive(:standard_build).with("PANDOC foo.html", "foo.html", expected_cmd, ["foo.md"], env, :cache)
subject.run("foo.html", ["foo.md"], :cache, env,
"CMD" => command, "CMD_DESC" => "PANDOC")
end
end
end
end