From 243eb9a4ab98837b835bf9958fa78748f3b0a865 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 6 Nov 2013 13:32:56 -0500 Subject: [PATCH] rename "tweakers" to "build hooks" --- README.md | 6 +++--- lib/rscons/environment.rb | 14 +++++++------- spec/build_tests_spec.rb | 10 +++++----- spec/rscons/environment_spec.rb | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4362798..34fb08f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index a98f97e..84a4a5a 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 4f27600..b3735c8 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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 diff --git a/spec/rscons/environment_spec.rb b/spec/rscons/environment_spec.rb index 9635c27..c90fdc5 100644 --- a/spec/rscons/environment_spec.rb +++ b/spec/rscons/environment_spec.rb @@ -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