add Environment#add_target and use it from Environment#method_missing

This commit is contained in:
Josh Holtrop 2014-03-26 11:29:02 -04:00
parent 92a9982988
commit b2c970c9ca
2 changed files with 15 additions and 11 deletions

View File

@ -175,14 +175,14 @@ module Rscons
targets_processed = {}
process_target = proc do |target|
targets_processed[target] ||= begin
@targets[target][:source].each do |src|
@targets[target][:sources].each do |src|
if @targets.include?(src) and not targets_processed.include?(src)
process_target.call(src)
end
end
result = run_builder(@targets[target][:builder],
target,
@targets[target][:source],
@targets[target][:sources],
cache,
@targets[target][:vars] || {})
unless result
@ -248,22 +248,26 @@ module Rscons
def method_missing(method, *args)
if @builders.has_key?(method.to_s)
target, source, vars, *rest = args
target, sources, vars, *rest = args
unless vars.nil? or vars.is_a?(Hash) or vars.is_a?(VarSet)
raise "Unexpected construction variable set: #{vars.inspect}"
end
source = [source] unless source.is_a?(Array)
@targets[target] = {
builder: @builders[method.to_s],
source: source,
vars: vars,
args: rest,
}
sources = [sources] unless sources.is_a?(Array)
add_target(target, @builders[method.to_s], sources, vars, rest)
else
super
end
end
def add_target(target, builder, sources, vars, args)
@targets[target] = {
builder: builder,
sources: sources,
vars: vars,
args: args,
}
end
# Manually record a given target as depending on the specified
# dependency files.
def depends(target, *user_deps)

View File

@ -259,7 +259,7 @@ module Rscons
target = env.instance_variable_get(:@targets)["target"]
target.should_not be_nil
target[:builder].is_a?(Builder).should be_true
target[:source].should == ["src1", "src2"]
target[:sources].should == ["src1", "src2"]
target[:vars].should == {var: "val"}
target[:args].should == []
end