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

View File

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