rename "tweakers" to "build hooks"

This commit is contained in:
Josh Holtrop 2013-11-06 13:32:56 -05:00
parent 49be46199f
commit 243eb9a4ab
4 changed files with 17 additions and 17 deletions

View File

@ -86,7 +86,7 @@ end
```ruby ```ruby
Rscons::Environment.new do |env| Rscons::Environment.new do |env|
env["CFLAGS"] = ["-O3", "-Wall", "-DDEFINE"] 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} if build_op[:target] =~ %r{build/third-party}
build_op[:vars]["CFLAGS"] -= ["-Wall"] build_op[:vars]["CFLAGS"] -= ["-Wall"]
end end
@ -125,11 +125,11 @@ An Rscons::Environment consists of:
* a collection of builders * a collection of builders
* a mapping of build directories * a mapping of build directories
* a collection of targets to build * 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 When cloning an environment, the construction variables, builders, and build
directories are cloned, but the new environment does not inherit any of the 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. Cloned environments contain "deep copies" of construction variables.
For example, in: For example, in:

View File

@ -22,7 +22,7 @@ module Rscons
@targets = {} @targets = {}
@builders = {} @builders = {}
@build_dirs = [] @build_dirs = []
@tweakers = [] @build_hooks = []
@varset[:exclude_builders] ||= [] @varset[:exclude_builders] ||= []
unless @varset[:exclude_builders] == :all unless @varset[:exclude_builders] == :all
exclude_builders = Set.new(@varset[:exclude_builders] || []) exclude_builders = Set.new(@varset[:exclude_builders] || [])
@ -43,7 +43,7 @@ module Rscons
# Make a copy of the Environment object. # Make a copy of the Environment object.
# The cloned environment will contain a copy of all environment options, # The cloned environment will contain a copy of all environment options,
# construction variables, builders, and build directories. It will not # 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 # If a block is given, the Environment object is yielded to the block and
# when the block returns, the {#process} method is automatically called. # when the block returns, the {#process} method is automatically called.
def clone(variables = {}) def clone(variables = {})
@ -72,9 +72,9 @@ module Rscons
end end
end end
# Add a tweaker block to the Environment. # Add a build hook to the Environment.
def add_tweaker(&block) def add_build_hook(&block)
@tweakers << block @build_hooks << block
end end
# Specify a build directory for this Environment. # Specify a build directory for this Environment.
@ -238,14 +238,14 @@ module Rscons
# Return the result of the builder's run() method. # Return the result of the builder's run() method.
def run_builder(builder, target, sources, cache, vars) def run_builder(builder, target, sources, cache, vars)
vars = @varset.merge(vars) vars = @varset.merge(vars)
@tweakers.each do |tweaker_block| @build_hooks.each do |build_hook_block|
build_operation = { build_operation = {
builder: builder, builder: builder,
target: target, target: target,
sources: sources, sources: sources,
vars: vars, vars: vars,
} }
tweaker_block.call(build_operation) build_hook_block.call(build_operation)
end end
builder.run(target, sources, cache, self, vars) builder.run(target, sources, cache, self, vars)
end end

View File

@ -283,25 +283,25 @@ EOF
`ar t lib.a`.should == "one.o\ntwo.o\n" `ar t lib.a`.should == "one.o\ntwo.o\n"
end end
it 'supports tweakers to override construction variables' do it 'supports build hooks to override construction variables' do
test_dir("build_dir") test_dir("build_dir")
Rscons::Environment.new(echo: :command) do |env| Rscons::Environment.new(echo: :command) do |env|
env.append('CPPPATH' => Dir['src/**/*/']) env.append('CPPPATH' => Dir['src/**/*/'])
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/') 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} if build_op[:target] =~ %r{build_one/.*\.o}
build_op[:vars]["CFLAGS"] << "-O1" build_op[:vars]["CFLAGS"] << "-O1"
elsif build_op[:target] =~ %r{build_two/.*\.o} elsif build_op[:target] =~ %r{build_two/.*\.o}
build_op[:vars]["CFLAGS"] << "-O2" build_op[:vars]["CFLAGS"] << "-O2"
end end
end end
env.Program('tweaker', Dir['src/**/*.c']) env.Program('build_hook', Dir['src/**/*.c'])
end end
`./tweaker`.should == "Hello from two()\n" `./build_hook`.should == "Hello from two()\n"
lines.should =~ [ 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_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 -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 end

View File

@ -246,9 +246,9 @@ module Rscons
end end
describe "#run_builder" do 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 = Environment.new
env.add_tweaker do |build_op| env.add_build_hook do |build_op|
if build_op[:sources].first =~ %r{src/special} if build_op[:sources].first =~ %r{src/special}
build_op[:vars]["CFLAGS"] += ["-O3", "-DSPECIAL"] build_op[:vars]["CFLAGS"] += ["-O3", "-DSPECIAL"]
end end