README: add more information about custom builders
This commit is contained in:
parent
c897bcf06e
commit
f278b211f7
15
README.md
15
README.md
@ -64,6 +64,11 @@ end
|
|||||||
|
|
||||||
### Example: Custom Builder
|
### Example: Custom Builder
|
||||||
|
|
||||||
|
Custom builders are implemented as classes which extend from `Rscons::Builder`.
|
||||||
|
The builder must have a `run` method which is called to invoke the builder.
|
||||||
|
The `run` method should return the name of the target built on success, and
|
||||||
|
`false` on failure.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class GenerateFoo < Rscons::Builder
|
class GenerateFoo < Rscons::Builder
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
@ -73,10 +78,12 @@ class GenerateFoo < Rscons::Builder
|
|||||||
#define GENERATED 42
|
#define GENERATED 42
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(GenerateFoo.new)
|
||||||
env.GenerateFoo("foo.h", [])
|
env.GenerateFoo("foo.h", [])
|
||||||
env.Program("a.out", Dir["*.c"])
|
env.Program("a.out", Dir["*.c"])
|
||||||
end
|
end
|
||||||
@ -93,16 +100,23 @@ class CmdBuilder < Rscons::Builder
|
|||||||
system(cmd)
|
system(cmd)
|
||||||
cache.register_build(target, cmd, sources, env)
|
cache.register_build(target, cmd, sources, env)
|
||||||
end
|
end
|
||||||
|
target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CmdBuilder.new)
|
||||||
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example: Custom Builder Using Builder#standard_build()
|
### Example: Custom Builder Using Builder#standard_build()
|
||||||
|
|
||||||
|
The `standard_build` method from the `Rscons::Builder` base class can be used
|
||||||
|
when the builder needs to execute a system command to produce the target file.
|
||||||
|
The `standard_build` method will return the correct value so its return value
|
||||||
|
can be used as the return value from the `run` method.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class CmdBuilder < Rscons::Builder
|
class CmdBuilder < Rscons::Builder
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
@ -112,6 +126,7 @@ class CmdBuilder < Rscons::Builder
|
|||||||
end
|
end
|
||||||
|
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CmdBuilder.new)
|
||||||
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user