rename "tweakers" to "build hooks"
This commit is contained in:
parent
49be46199f
commit
243eb9a4ab
@ -86,7 +86,7 @@ end
|
||||
```ruby
|
||||
Rscons::Environment.new do |env|
|
||||
env["CFLAGS"] = ["-O3", "-Wall", "-DDEFINE"]
|
||||
env.add_tweaker do |build_op|
|
||||
env.add_build_hook do |build_op|
|
||||
if build_op[:target] =~ %r{build/third-party}
|
||||
build_op[:vars]["CFLAGS"] -= ["-Wall"]
|
||||
end
|
||||
@ -125,11 +125,11 @@ An Rscons::Environment consists of:
|
||||
* a collection of builders
|
||||
* a mapping of build directories
|
||||
* a collection of targets to build
|
||||
* a collection of tweakers
|
||||
* a collection of build hooks
|
||||
|
||||
When cloning an environment, the construction variables, builders, and build
|
||||
directories are cloned, but the new environment does not inherit any of the
|
||||
targets or tweakers from the source environment.
|
||||
targets or build hooks from the source environment.
|
||||
|
||||
Cloned environments contain "deep copies" of construction variables.
|
||||
For example, in:
|
||||
|
@ -22,7 +22,7 @@ module Rscons
|
||||
@targets = {}
|
||||
@builders = {}
|
||||
@build_dirs = []
|
||||
@tweakers = []
|
||||
@build_hooks = []
|
||||
@varset[:exclude_builders] ||= []
|
||||
unless @varset[:exclude_builders] == :all
|
||||
exclude_builders = Set.new(@varset[:exclude_builders] || [])
|
||||
@ -43,7 +43,7 @@ module Rscons
|
||||
# Make a copy of the Environment object.
|
||||
# The cloned environment will contain a copy of all environment options,
|
||||
# construction variables, builders, and build directories. It will not
|
||||
# contain a copy of the targets or tweakers.
|
||||
# contain a copy of the targets or build hooks.
|
||||
# If a block is given, the Environment object is yielded to the block and
|
||||
# when the block returns, the {#process} method is automatically called.
|
||||
def clone(variables = {})
|
||||
@ -72,9 +72,9 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Add a tweaker block to the Environment.
|
||||
def add_tweaker(&block)
|
||||
@tweakers << block
|
||||
# Add a build hook to the Environment.
|
||||
def add_build_hook(&block)
|
||||
@build_hooks << block
|
||||
end
|
||||
|
||||
# Specify a build directory for this Environment.
|
||||
@ -238,14 +238,14 @@ module Rscons
|
||||
# Return the result of the builder's run() method.
|
||||
def run_builder(builder, target, sources, cache, vars)
|
||||
vars = @varset.merge(vars)
|
||||
@tweakers.each do |tweaker_block|
|
||||
@build_hooks.each do |build_hook_block|
|
||||
build_operation = {
|
||||
builder: builder,
|
||||
target: target,
|
||||
sources: sources,
|
||||
vars: vars,
|
||||
}
|
||||
tweaker_block.call(build_operation)
|
||||
build_hook_block.call(build_operation)
|
||||
end
|
||||
builder.run(target, sources, cache, self, vars)
|
||||
end
|
||||
|
@ -283,25 +283,25 @@ EOF
|
||||
`ar t lib.a`.should == "one.o\ntwo.o\n"
|
||||
end
|
||||
|
||||
it 'supports tweakers to override construction variables' do
|
||||
it 'supports build hooks to override construction variables' do
|
||||
test_dir("build_dir")
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
|
||||
env.add_tweaker do |build_op|
|
||||
env.add_build_hook do |build_op|
|
||||
if build_op[:target] =~ %r{build_one/.*\.o}
|
||||
build_op[:vars]["CFLAGS"] << "-O1"
|
||||
elsif build_op[:target] =~ %r{build_two/.*\.o}
|
||||
build_op[:vars]["CFLAGS"] << "-O2"
|
||||
end
|
||||
end
|
||||
env.Program('tweaker', Dir['src/**/*.c'])
|
||||
env.Program('build_hook', Dir['src/**/*.c'])
|
||||
end
|
||||
`./tweaker`.should == "Hello from two()\n"
|
||||
`./build_hook`.should == "Hello from two()\n"
|
||||
lines.should =~ [
|
||||
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -Isrc/one/ -Isrc/two/ -O1 src/one/one.c',
|
||||
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -Isrc/one/ -Isrc/two/ -O2 src/two/two.c',
|
||||
'gcc -o tweaker build_one/one.o build_two/two.o',
|
||||
'gcc -o build_hook build_one/one.o build_two/two.o',
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -246,9 +246,9 @@ module Rscons
|
||||
end
|
||||
|
||||
describe "#run_builder" do
|
||||
it "tweaks the construction variables using given tweakers and invokes the builder" do
|
||||
it "modifies the construction variables using given build hooks and invokes the builder" do
|
||||
env = Environment.new
|
||||
env.add_tweaker do |build_op|
|
||||
env.add_build_hook do |build_op|
|
||||
if build_op[:sources].first =~ %r{src/special}
|
||||
build_op[:vars]["CFLAGS"] += ["-O3", "-DSPECIAL"]
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user