Environment: rework process()

- improve efficiency
- give errors for the dependency that failed instead of the top-level target
This commit is contained in:
Josh Holtrop 2013-11-05 12:43:50 -05:00
parent 7ce5a8f9d9
commit e863c9a564
2 changed files with 33 additions and 17 deletions

View File

@ -125,26 +125,28 @@ module Rscons
# called after the block returns. # called after the block returns.
def process def process
cache = Cache.new cache = Cache.new
targets_processed = Set.new targets_processed = {}
process_target = proc do |target| process_target = proc do |target|
if @targets[target][:source].map do |src| targets_processed[target] ||= begin
targets_processed.include?(src) or not @targets.include?(src) or process_target.call(src) @targets[target][:source].each do |src|
end.all? if @targets.include?(src) and not targets_processed.include?(src)
run_builder(@targets[target][:builder], process_target.call(src)
target, end
@targets[target][:source], end
cache, result = run_builder(@targets[target][:builder],
@targets[target][:vars] || {}) target,
else @targets[target][:source],
false cache,
@targets[target][:vars] || {})
unless result
cache.write
raise BuildError.new("Failed to build #{target}")
end
result
end end
end end
@targets.each do |target, info| @targets.each do |target, info|
next if targets_processed.include?(target) process_target.call(target)
unless process_target.call(target)
cache.write
raise BuildError.new("Failed to build #{target}")
end
end end
cache.write cache.write
end end

View File

@ -113,6 +113,20 @@ module Rscons
env.process env.process
end end
it "builds dependent targets first" do
env = Environment.new
env.Program("a.out", "main.o")
env.Object("main.o", "other.cc")
cache = "cache"
Cache.should_receive(:new).and_return(cache)
env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return("main.o")
env.should_receive(:run_builder).with(anything, "a.out", ["main.o"], cache, {}).and_return("a.out")
cache.should_receive(:write)
env.process
end
it "raises a BuildError when building fails" do it "raises a BuildError when building fails" do
env = Environment.new env = Environment.new
env.Program("a.out", "main.o") env.Program("a.out", "main.o")
@ -123,7 +137,7 @@ module Rscons
env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return(false) env.should_receive(:run_builder).with(anything, "main.o", ["other.cc"], cache, {}).and_return(false)
cache.should_receive(:write) cache.should_receive(:write)
expect { env.process }.to raise_error BuildError, /Failed.to.build.a\.out/ expect { env.process }.to raise_error BuildError, /Failed.to.build.main.o/
end end
end end