From 5634b8856de22158d8da0f71ab315e3e51bc4be2 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 5 Jul 2013 11:07:02 -0400 Subject: [PATCH] add initial Cache class --- lib/rscons.rb | 1 + lib/rscons/cache.rb | 41 +++++++++++++++++++++++++++++++++++++++ lib/rscons/environment.rb | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 lib/rscons/cache.rb diff --git a/lib/rscons.rb b/lib/rscons.rb index c543e0d..90e4dba 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -1,4 +1,5 @@ require "rscons/builder" +require "rscons/cache" require "rscons/environment" require "rscons/version" diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb new file mode 100644 index 0000000..65ea184 --- /dev/null +++ b/lib/rscons/cache.rb @@ -0,0 +1,41 @@ +require 'yaml' +require 'fileutils' +require 'digest/md5' + +module Rscons + class Cache + # Constants + CACHE_FILE = '.rsconscache' + + # Class Methods + def self.clear + FileUtils.rm_f(CACHE_FILE) + end + + # Instance Methods + def initialize + @cache = YAML.load(File.read(CACHE_FILE)) rescue {} + end + + def write + File.open(CACHE_FILE, 'w') do |fh| + fh.puts(YAML.dump(@cache)) + end + end + + def up_to_date?(file, deps = nil) + # TODO + end + + def register_build(target, deps) + # TODO + end + + # Private Instance Methods + private + + def calculate_checksum(file) + Digest::MD5.hexdigest(File.read(file)).encode(__ENCODING__) + end + end +end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 750b13d..5098d6e 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -57,6 +57,8 @@ module Rscons end def process + cache = Cache.new + cache.write end alias_method :orig_method_missing, :method_missing