expand ^/ in target paths to be relative to the build root
This commit is contained in:
parent
4818fd10fe
commit
1fe2c6401d
@ -171,6 +171,7 @@ module Rscons
|
|||||||
# When a block is passed to Environment.new, this method is automatically
|
# When a block is passed to Environment.new, this method is automatically
|
||||||
# called after the block returns.
|
# called after the block returns.
|
||||||
def process
|
def process
|
||||||
|
clean_target_paths!
|
||||||
cache = Cache.new
|
cache = Cache.new
|
||||||
targets_processed = {}
|
targets_processed = {}
|
||||||
process_target = proc do |target|
|
process_target = proc do |target|
|
||||||
@ -192,7 +193,7 @@ module Rscons
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@targets.each do |target, info|
|
@targets.each do |target, target_params|
|
||||||
process_target.call(target)
|
process_target.call(target)
|
||||||
end
|
end
|
||||||
cache.write
|
cache.write
|
||||||
@ -331,6 +332,27 @@ module Rscons
|
|||||||
builder.run(target, sources, cache, self, vars)
|
builder.run(target, sources, cache, self, vars)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Expand all target paths that begin with ^/ to be relative to the
|
||||||
|
# Environment's build root, if present
|
||||||
|
def clean_target_paths!
|
||||||
|
if @build_root
|
||||||
|
expand = lambda do |path|
|
||||||
|
path.sub(%r{^\^(?=[\\/])}, @build_root)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_targets = {}
|
||||||
|
@targets.each_pair do |target, target_params|
|
||||||
|
target_params[:sources].map! do |source|
|
||||||
|
expand[source]
|
||||||
|
end
|
||||||
|
new_targets[expand[target]] = target_params
|
||||||
|
end
|
||||||
|
@targets = new_targets
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Parse dependencies for a given target from a Makefile.
|
# Parse dependencies for a given target from a Makefile.
|
||||||
# This method is used internally by Rscons builders.
|
# This method is used internally by Rscons builders.
|
||||||
# @param mf_fname [String] File name of the Makefile to read.
|
# @param mf_fname [String] File name of the Makefile to read.
|
||||||
|
@ -180,6 +180,23 @@ describe Rscons do
|
|||||||
lines.should == ["CC build_root/src/one/one.o", "CC build_root/src/two/two.o", "LD build_dir"]
|
lines.should == ["CC build_root/src/one/one.o", "CC build_root/src/two/two.o", "LD build_dir"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "expands target and source paths starting with ^/ to be relative to the build root" do
|
||||||
|
test_dir('build_dir')
|
||||||
|
Rscons::Environment.new(echo: :command) do |env|
|
||||||
|
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||||
|
env.build_root = "build_root"
|
||||||
|
FileUtils.mkdir_p(env.build_root)
|
||||||
|
FileUtils.mv("src/one/one.c", "build_root")
|
||||||
|
env.Object("^/one.o", "^/one.c")
|
||||||
|
env.Program('build_dir', Dir['src/**/*.c'] + ["^/one.o"])
|
||||||
|
end
|
||||||
|
lines.should == [
|
||||||
|
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -Isrc/one/ -Isrc/two/ build_root/one.c},
|
||||||
|
%q{gcc -c -o build_root/src/two/two.o -MMD -MF build_root/src/two/two.mf -Isrc/one/ -Isrc/two/ src/two/two.c},
|
||||||
|
%q{gcc -o build_dir build_root/src/two/two.o build_root/one.o},
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
it 'cleans built files' do
|
it 'cleans built files' do
|
||||||
test_dir('build_dir')
|
test_dir('build_dir')
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user