Environment: rework process()
- improve efficiency - give errors for the dependency that failed instead of the top-level target
This commit is contained in:
parent
7ce5a8f9d9
commit
e863c9a564
@ -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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
result = run_builder(@targets[target][:builder],
|
||||||
target,
|
target,
|
||||||
@targets[target][:source],
|
@targets[target][:source],
|
||||||
cache,
|
cache,
|
||||||
@targets[target][:vars] || {})
|
@targets[target][:vars] || {})
|
||||||
else
|
unless result
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@targets.each do |target, info|
|
|
||||||
next if targets_processed.include?(target)
|
|
||||||
unless process_target.call(target)
|
|
||||||
cache.write
|
cache.write
|
||||||
raise BuildError.new("Failed to build #{target}")
|
raise BuildError.new("Failed to build #{target}")
|
||||||
end
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@targets.each do |target, info|
|
||||||
|
process_target.call(target)
|
||||||
end
|
end
|
||||||
cache.write
|
cache.write
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user