diff --git a/build_tests/simple/command_builder.rb b/build_tests/simple/command_builder.rb new file mode 100644 index 0000000..5b1c02d --- /dev/null +++ b/build_tests/simple/command_builder.rb @@ -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 diff --git a/lib/rscons/builders/command.rb b/lib/rscons/builders/command.rb index 797d7ed..5403e37 100644 --- a/lib/rscons/builders/command.rb +++ b/lib/rscons/builders/command.rb @@ -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] 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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index af71f26..2e7ff1e 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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") diff --git a/spec/rscons/builders/command_spec.rb b/spec/rscons/builders/command_spec.rb deleted file mode 100755 index 96ae96c..0000000 --- a/spec/rscons/builders/command_spec.rb +++ /dev/null @@ -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