expand target and sources for construction variable references before invoking builder

This commit is contained in:
Josh Holtrop 2014-05-09 09:45:29 -04:00
parent bd525e2742
commit 58b41df426
2 changed files with 39 additions and 10 deletions

View File

@ -351,18 +351,21 @@ module Rscons
private
# Expand certain paths that begin with ^/ to be relative to the
# Environment's build root, if present
# Expand target and source paths before invoking builders.
#
# This method expand construction variable references in the target and
# source file names before passing them to the builder. It also expands
# "^/" prefixes to the Environment's build root if a build root is defined.
def expand_paths!
if @build_root
new_targets = {}
@targets.each_pair do |target, target_params|
target_params[:sources].map! do |source|
expand_path(source)
@targets = @targets.reduce({}) do |result, (target, target_params)|
sources = target_params[:sources].map do |source|
source = expand_path(source) if @build_root
expand_varref(source)
end
new_targets[expand_path(target)] = target_params
end
@targets = new_targets
target = expand_path(target) if @build_root
target = expand_varref(target)
result[target] = target_params.merge(sources: sources)
result
end
end

View File

@ -498,4 +498,30 @@ EOF
env.TestBuilder("file")
end
end
it "expands construction variables in builder target and sources before invoking the builder" do
test_dir('custom_builder')
class MySource < Rscons::Builder
def run(target, sources, cache, env, vars)
File.open(target, 'w') do |fh|
fh.puts <<EOF
#define THE_VALUE 678
EOF
end
target
end
end
Rscons::Environment.new do |env|
env["hdr"] = "inc.h"
env["src"] = "program.c"
env.add_builder(MySource.new)
env.MySource('${hdr}')
env.Program('program', "${src}")
end
lines.should == ['CC program.o', 'LD program']
File.exists?('inc.h').should be_true
`./program`.should == "The value is 678\n"
end
end