Implemented SimpleBuilder and updated Environment#add_builder method to support it

This commit is contained in:
Michael D. Lowis authored and Josh Holtrop committed 2014-10-16 16:37:37 -04:00
1 parent e279959d79
commit 92d4dd8396
8 files changed
+129 -2

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
module Rscons
module Builders
# A Generic builder class whose name and operation is defined at
# instantiation.
class SimpleBuilder < Builder
# The name of this builder when registered in an environment
attr_reader :name
# Create a new builder with the given name and action.
#
# @param name [String,Symbol] The name of the builder when registered.
# @param block [Block]
# The action to perform when the builder is processed. The provided
# block must return the target file on success or false on failure.
# The provided block should have the same signature as {Builder#run}.
def initialize(name, &block)
@name = name.to_s
@block = block
end
# Run the builder to produce a build target.
#
# @param target [String] Target file name.
# @param sources [Array<String>] Source file name(s).
# @param cache [Cache] The Cache object.
# @param env [Environment] The Environment executing the builder.
# @param vars [Hash,VarSet] Extra construction variables.
#
# @return [String,false]
# Name of the target file on success or false on failure.
def run(target, sources, cache, env, vars)
@block.call(target, sources, cache, env, vars)
end
end
end
end
+18 -2
View File
@@ -120,10 +120,26 @@ module Rscons
# Add a {Builder} object to the Environment.
#
# @param builder [Builder] The {Builder} object to add.
# @overload add_builder(builder)
# Registers a builder with the environment
# @param builder [Builder] An instance of the builder to register.
#
# @overload add_builder(builder,&action)
# Register a new {Builders::SimpleBuilder} with the environment.
#
# @param builder [String,Symbol]
# The name of the builder to add.
#
# @param action [Block]
# A block that will be called when the builder is executed to generate
# a target file. The provided block should have the same prototype as
# {Rscons::Builder#run}
#
# @return [void]
def add_builder(builder)
def add_builder(builder, &action)
if not builder.is_a? Rscons::Builder
builder = Rscons::Builders::SimpleBuilder.new(builder, &action)
end
@builders[builder.name] = builder
var_defs = builder.default_variables(self)
if var_defs