update README custom builder examples

This commit is contained in:
Josh Holtrop 2013-12-27 14:56:25 -05:00
parent 295324eafd
commit 8976d7dea2

View File

@ -66,7 +66,8 @@ end
```ruby ```ruby
class GenerateFoo < Rscons::Builder class GenerateFoo < Rscons::Builder
def run(target, sources, cache, env, vars) def run(target, sources, user_deps, cache, env, vars)
cache.mkdir_p(File.dirname(target))
File.open(target, "w") do |fh| File.open(target, "w") do |fh|
fh.puts <<EOF fh.puts <<EOF
#define GENERATED 42 #define GENERATED 42
@ -81,6 +82,40 @@ Rscons::Environment.new do |env|
end end
``` ```
### Example: Custom Builder That Only Regenerates When Necessary
```ruby
class CmdBuilder < Rscons::Builder
def run(target, sources, user_deps, cache, env, vars)
cmd = ["cmd", "-i", sources.first, "-o", target]
unless cache.up_to_date?(target, cmd, sources, user_deps)
cache.mkdir_p(File.dirname(target))
system(cmd)
cache.register_build(target, cmd, sources, user_deps)
end
end
end
Rscons::Environment.new do |env|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
end
```
### Example: Custom Builder Using Builder#standard_build()
```ruby
class CmdBuilder < Rscons::Builder
def run(target, sources, user_deps, cache, env, vars)
cmd = ["cmd", "-i", sources.first, "-o", target]
standard_build("CmdBld #{target}", target, cmd, sources, user_deps, env, cache)
end
end
Rscons::Environment.new do |env|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
end
```
### Example: Using different compilation flags for some sources ### Example: Using different compilation flags for some sources
```ruby ```ruby