Write Cache to disk if an exception occurs while processing the Environment - fix #4

This commit is contained in:
Josh Holtrop 2014-04-15 14:20:30 -04:00
parent ea30b0b5ee
commit ee5aca275d
2 changed files with 36 additions and 19 deletions

View File

@ -176,29 +176,31 @@ module Rscons
cache.clear_checksum_cache!
targets_processed = {}
unless @targets.empty?
process_target = proc do |target|
targets_processed[target] ||= begin
@targets[target][:sources].each do |src|
if @targets.include?(src) and not targets_processed.include?(src)
process_target.call(src)
begin
process_target = proc do |target|
targets_processed[target] ||= begin
@targets[target][: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],
target,
@targets[target][:sources],
cache,
@targets[target][:vars] || {})
unless result
raise BuildError.new("Failed to build #{target}")
end
result
end
result = run_builder(@targets[target][:builder],
target,
@targets[target][:sources],
cache,
@targets[target][:vars] || {})
unless result
cache.write
raise BuildError.new("Failed to build #{target}")
end
result
end
@targets.each do |target, target_params|
process_target.call(target)
end
ensure
cache.write
end
@targets.each do |target, target_params|
process_target.call(target)
end
cache.write
end
end

View File

@ -176,6 +176,21 @@ module Rscons
expect { env.process }.to raise_error BuildError, /Failed.to.build.main.o/
end
it "writes the cache when the Builder raises an exception" do
env = Environment.new
env.Object("module.o", "module.c")
cache = "cache"
Cache.should_receive(:instance).and_return(cache)
cache.should_receive(:clear_checksum_cache!)
env.stub(:run_builder) do |builder, target, sources, cache, vars|
raise "Ruby exception thrown by builder"
end
cache.should_receive(:write)
expect { env.process }.to raise_error RuntimeError, /Ruby exception thrown by builder/
end
end
describe "#clear_targets" do