expand target and sources for construction variable references before invoking builder
This commit is contained in:
parent
bd525e2742
commit
58b41df426
@ -351,18 +351,21 @@ module Rscons
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Expand certain paths that begin with ^/ to be relative to the
|
# Expand target and source paths before invoking builders.
|
||||||
# Environment's build root, if present
|
#
|
||||||
|
# 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!
|
def expand_paths!
|
||||||
if @build_root
|
@targets = @targets.reduce({}) do |result, (target, target_params)|
|
||||||
new_targets = {}
|
sources = target_params[:sources].map do |source|
|
||||||
@targets.each_pair do |target, target_params|
|
source = expand_path(source) if @build_root
|
||||||
target_params[:sources].map! do |source|
|
expand_varref(source)
|
||||||
expand_path(source)
|
|
||||||
end
|
|
||||||
new_targets[expand_path(target)] = target_params
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -498,4 +498,30 @@ EOF
|
|||||||
env.TestBuilder("file")
|
env.TestBuilder("file")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user