support registering multiple build targets with the same path - close #26

This commit is contained in:
Josh Holtrop 2015-01-28 17:10:36 -05:00
parent 02aff35222
commit 29a8684f90
3 changed files with 46 additions and 27 deletions

View File

@ -280,33 +280,35 @@ module Rscons
#
# @return [void]
def process
expand_paths!
while @targets.size > 0
expand_paths!
targets = @targets
@targets = {}
cache = Cache.instance
cache.clear_checksum_cache!
targets_processed = {}
targets_processed = Set.new
process_target = proc do |target|
targets_processed[target] ||= begin
targets[target][:sources].each do |src|
unless targets_processed.include?(target)
targets_processed << target
targets[target].each do |target_params|
target_params[: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],
result = run_builder(target_params[:builder],
target,
targets[target][:sources],
target_params[:sources],
cache,
targets[target][:vars] || {})
target_params[:vars] || {})
unless result
raise BuildError.new("Failed to build #{target}")
end
result
end
end
end
begin
targets.each do |target, target_params|
targets.each_key do |target|
process_target.call(target)
end
ensure
@ -404,7 +406,8 @@ module Rscons
#
# @return [void]
def add_target(target, builder, sources, vars, args)
@targets[target] = {
@targets[target] ||= []
@targets[target] << {
builder: builder,
sources: sources,
vars: vars,
@ -679,14 +682,16 @@ module Rscons
#
# @return [void]
def expand_paths!
@targets = @targets.reduce({}) do |result, (target, target_params)|
@targets = @targets.reduce({}) do |result, (target, target_params_list)|
target = expand_path(target) if @build_root
target = expand_varref(target)
result[target] = target_params_list.map do |target_params|
sources = target_params[:sources].map do |source|
source = expand_path(source) if @build_root
expand_varref(source)
end.flatten
target = expand_path(target) if @build_root
target = expand_varref(target)
result[target] = target_params.merge(sources: sources)
target_params.merge(sources: sources)
end
result
end
end

View File

@ -764,4 +764,18 @@ EOF
expect(`./simple`).to eq "This is a simple C program\n"
end
it "supports registering multiple build targets with the same target path" do
test_dir("build_dir")
Rscons::Environment.new do |env|
env["CPPPATH"] << "src/two"
env.Object("one.o", "src/one/one.c")
env.Object("one.o", "src/two/two.c")
end
expect(File.exists?("one.o")).to be_truthy
expect(lines).to eq([
"CC one.o",
"CC one.o",
])
end
end

View File

@ -305,10 +305,10 @@ module Rscons
env.Object("target.o", ["src1.c", "src2.c"], var: "val")
target = env.instance_variable_get(:@targets)["target.o"]
expect(target).to_not be_nil
expect(target[:builder].is_a?(Builder)).to be_truthy
expect(target[:sources]).to eq ["src1.c", "src2.c"]
expect(target[:vars]).to eq({var: "val"})
expect(target[:args]).to eq []
expect(target[0][:builder].is_a?(Builder)).to be_truthy
expect(target[0][:sources]).to eq ["src1.c", "src2.c"]
expect(target[0][:vars]).to eq({var: "val"})
expect(target[0][:args]).to eq []
end
it "raises an error when vars is not a Hash" do