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