add "tweakers" functionality

tweakers allow the user to modify construction variables before any build is performed
This commit is contained in:
josh committed 2013-10-15 16:15:37 -04:00
1 parent 4a2997feec
commit 446fef931f
3 files changed
+46 -8

No files matched your search

+17 -1
View File
@@ -22,6 +22,7 @@ module Rscons
@targets = {}
@builders = {}
@build_dirs = []
@tweakers = []
@varset[:exclude_builders] ||= []
unless @varset[:exclude_builders] == :all
exclude_builders = Set.new(@varset[:exclude_builders] || [])
@@ -45,7 +46,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.
# contain a copy of the targets or tweakers.
# 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 = {})
@@ -74,6 +75,11 @@ module Rscons
end
end
# Add a tweaker block to the Environment.
def add_tweaker(&block)
@tweakers << block
end
# Specify a build directory for this Environment.
# Source files from src_dir will produce object files under obj_dir.
def build_dir(src_dir, obj_dir)
@@ -268,6 +274,16 @@ module Rscons
# @param vars [Hash] Extra variables to pass to the builder.
# 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_operation = {
builder: builder,
target: target,
sources: sources,
vars: vars,
}
tweaker_block.call(build_operation)
end
builder.run(target, sources, cache, self, vars)
end
end