Added a command builder to the list of default builders
This commit is contained in:
parent
469f575564
commit
e279959d79
13
README.md
13
README.md
@ -210,6 +210,7 @@ end
|
|||||||
|
|
||||||
Rscons ships with a number of builders:
|
Rscons ships with a number of builders:
|
||||||
|
|
||||||
|
* Command, which executes a user-defined command to produce the target
|
||||||
* CFile, which builds a C or C++ source file from a lex or yacc input file
|
* CFile, which builds a C or C++ source file from a lex or yacc input file
|
||||||
* Disassemble, which disassembles an object file to a disassembly listing
|
* Disassemble, which disassembles an object file to a disassembly listing
|
||||||
* Library, which collects object files into a static library archive file
|
* Library, which collects object files into a static library archive file
|
||||||
@ -220,6 +221,18 @@ Rscons ships with a number of builders:
|
|||||||
If you want to create an Environment that does not contain any builders,
|
If you want to create an Environment that does not contain any builders,
|
||||||
you can use the `exclude_builders` key to the Environment constructor.
|
you can use the `exclude_builders` key to the Environment constructor.
|
||||||
|
|
||||||
|
#### Command
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
env.Command(target, sources, 'CMD' => command)
|
||||||
|
# Example
|
||||||
|
env.Command("docs.html", "docs.md",
|
||||||
|
CMD => ['pandoc', '-fmarkdown', '-thtml', '-o${_TARGET}', '${_SOURCES}'])
|
||||||
|
```
|
||||||
|
|
||||||
|
The command builder executes a user-defined command in order to produce the
|
||||||
|
desired target file based on the provided source files.
|
||||||
|
|
||||||
#### CFile
|
#### CFile
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
@ -6,6 +6,7 @@ require_relative "rscons/varset"
|
|||||||
require_relative "rscons/version"
|
require_relative "rscons/version"
|
||||||
|
|
||||||
# default builders
|
# default builders
|
||||||
|
require_relative "rscons/builders/command"
|
||||||
require_relative "rscons/builders/cfile"
|
require_relative "rscons/builders/cfile"
|
||||||
require_relative "rscons/builders/disassemble"
|
require_relative "rscons/builders/disassemble"
|
||||||
require_relative "rscons/builders/library"
|
require_relative "rscons/builders/library"
|
||||||
@ -18,6 +19,7 @@ module Rscons
|
|||||||
# Names of the default builders which will be added to all newly created
|
# Names of the default builders which will be added to all newly created
|
||||||
# {Environment} objects.
|
# {Environment} objects.
|
||||||
DEFAULT_BUILDERS = [
|
DEFAULT_BUILDERS = [
|
||||||
|
:Command,
|
||||||
:CFile,
|
:CFile,
|
||||||
:Disassemble,
|
:Disassemble,
|
||||||
:Library,
|
:Library,
|
||||||
|
30
lib/rscons/builders/command.rb
Normal file
30
lib/rscons/builders/command.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
module Rscons
|
||||||
|
module Builders
|
||||||
|
# Execute a command that will produce the given target based on the given
|
||||||
|
# sources.
|
||||||
|
#
|
||||||
|
# Example::
|
||||||
|
# env.Command("docs.html", "docs.md",
|
||||||
|
# CMD => ['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.
|
||||||
|
#
|
||||||
|
# @return [String,false]
|
||||||
|
# Name of the target file on success or false on failure.
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
vars = vars.merge({
|
||||||
|
"_TARGET" => target,
|
||||||
|
"_SOURCES" => sources,
|
||||||
|
})
|
||||||
|
command = env.build_command("${CMD}", vars)
|
||||||
|
standard_build("CMD #{target}", target, command, sources, env, cache)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
spec/rscons/builders/command_spec.rb
Executable file
16
spec/rscons/builders/command_spec.rb
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
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("CMD foo.html", "foo.html", expected_cmd, ["foo.md"], env, :cache)
|
||||||
|
subject.run("foo.html", ["foo.md"], :cache, env, {'CMD' => command})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user