Cache: add :targets layer to hash
This commit is contained in:
parent
ad676ff138
commit
50ea3a501e
@ -2,10 +2,13 @@ require 'yaml'
|
||||
require 'fileutils'
|
||||
require 'digest/md5'
|
||||
require 'set'
|
||||
require 'rscons/version'
|
||||
|
||||
module Rscons
|
||||
# Example cache:
|
||||
# {
|
||||
# version: '1.2.3',
|
||||
# targets: {
|
||||
# 'program' => {
|
||||
# 'checksum' => 'A1B2C3D4',
|
||||
# 'command' => ['gcc', '-o', 'program', 'program.o'],
|
||||
@ -31,6 +34,7 @@ module Rscons
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
class Cache
|
||||
# Constants
|
||||
CACHE_FILE = '.rsconscache'
|
||||
@ -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|
|
||||
|
Loading…
x
Reference in New Issue
Block a user