Cache: add :targets layer to hash

This commit is contained in:
Josh Holtrop 2013-07-22 20:30:24 -04:00
parent ad676ff138
commit 50ea3a501e

View File

@ -2,33 +2,37 @@ require 'yaml'
require 'fileutils'
require 'digest/md5'
require 'set'
require 'rscons/version'
module Rscons
# Example cache:
# {
# 'program' => {
# 'checksum' => 'A1B2C3D4',
# 'command' => ['gcc', '-o', 'program', 'program.o'],
# 'deps' => [
# {
# 'fname' => 'program.o',
# 'checksum' => '87654321',
# }
# ],
# }
# 'program.o' => {
# 'checksum' => '87654321',
# 'command' => ['gcc', '-c', '-o', 'program.o', 'program.c'],
# 'deps' => [
# {
# 'fname' => 'program.c',
# 'checksum' => '456789ABC',
# },
# {
# 'fname' => 'program.h',
# 'checksum' => '7979764643',
# }
# ]
# version: '1.2.3',
# targets: {
# 'program' => {
# 'checksum' => 'A1B2C3D4',
# 'command' => ['gcc', '-o', 'program', 'program.o'],
# 'deps' => [
# {
# 'fname' => 'program.o',
# 'checksum' => '87654321',
# }
# ],
# }
# 'program.o' => {
# 'checksum' => '87654321',
# 'command' => ['gcc', '-c', '-o', 'program.o', 'program.c'],
# 'deps' => [
# {
# 'fname' => 'program.c',
# 'checksum' => '456789ABC',
# },
# {
# 'fname' => 'program.h',
# 'checksum' => '7979764643',
# }
# ]
# }
# }
# }
class Cache
@ -42,7 +46,10 @@ module Rscons
# Instance Methods
def initialize
@cache = YAML.load(File.read(CACHE_FILE)) rescue {}
@cache = YAML.load(File.read(CACHE_FILE)) rescue {
targets: {},
version: VERSION,
}
@lookup_checksums = {}
end
@ -57,12 +64,12 @@ module Rscons
return false unless File.exists?(target)
# target must be registered in the cache
return false unless @cache.has_key?(target)
return false unless @cache[:targets].has_key?(target)
# command used to build target must be identical
return false unless @cache[target][:command] == command
return false unless @cache[:targets][target][:command] == command
cached_deps = @cache[target][:deps].map { |dc| dc[:fname] }
cached_deps = @cache[:targets][target][:deps].map { |dc| dc[:fname] }
if options[:strict_deps]
# depedencies passed in must exactly equal those in the cache
return false unless deps == cached_deps
@ -72,13 +79,13 @@ module Rscons
end
# all cached dependencies must have their checksums match
@cache[target][:deps].map do |dep_cache|
@cache[:targets][target][:deps].map do |dep_cache|
dep_cache[:checksum] == lookup_checksum(dep_cache[:fname])
end.all?
end
def register_build(target, command, deps)
@cache[target] = {
@cache[:targets][target] = {
command: command,
checksum: calculate_checksum(target),
deps: deps.map do |dep|