From fdc5c8773cd929f189595157badb1736b21412ee Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 14 Apr 2014 17:17:54 -0400 Subject: [PATCH] Issue #7 - store MD5 of build command instead of the full command in the cache --- lib/rscons/cache.rb | 8 ++++---- spec/rscons/cache_spec.rb | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index d9d3e0b..0fc0da9 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -13,7 +13,7 @@ module Rscons # "targets" => { # "program" => { # "checksum" => "A1B2C3D4", - # "command" => ["gcc", "-o", "program", "program.o"], + # "command" => "13543518FE", # "deps" => [ # { # "fname" => "program.o", @@ -29,7 +29,7 @@ module Rscons # }, # "program.o" => { # "checksum" => "87654321", - # "command" => ["gcc", "-c", "-o", "program.o", "program.c"], + # "command" => "98765ABCD", # "deps" => [ # { # "fname" => "program.c", @@ -118,7 +118,7 @@ module Rscons return false unless @cache["targets"][target]["checksum"] == lookup_checksum(target) # command used to build target must be identical - return false unless @cache["targets"][target]["command"] == command + return false unless @cache["targets"][target]["command"] == Digest::MD5.hexdigest(command.inspect) cached_deps = @cache["targets"][target]["deps"] || [] cached_deps_fnames = cached_deps.map { |dc| dc["fname"] } @@ -153,7 +153,7 @@ module Rscons def register_build(targets, command, deps, env) Array(targets).each do |target| @cache["targets"][target.encode(__ENCODING__)] = { - "command" => command, + "command" => Digest::MD5.hexdigest(command.inspect), "checksum" => calculate_checksum(target), "deps" => deps.map do |dep| { diff --git a/spec/rscons/cache_spec.rb b/spec/rscons/cache_spec.rb index 6a48d1f..a87e674 100644 --- a/spec/rscons/cache_spec.rb +++ b/spec/rscons/cache_spec.rb @@ -62,7 +62,7 @@ module Rscons end it "returns false when the build command has changed" do - _cache = {"targets" => {"target" => {"checksum" => "abc", "command" => "old command"}}} + _cache = {"targets" => {"target" => {"checksum" => "abc", "command" => Digest::MD5.hexdigest("old command".inspect)}}} cache = build_from(_cache) File.should_receive(:exists?).with("target").and_return(true) cache.should_receive(:calculate_checksum).with("target").and_return("abc") @@ -71,7 +71,7 @@ module Rscons it "returns false when there is a new dependency" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1"}]}}} cache = build_from(_cache) File.should_receive(:exists?).with("target").and_return(true) @@ -81,7 +81,7 @@ module Rscons it "returns false when a dependency's checksum has changed" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1", "checksum" => "dep.1.chk"}, {"fname" => "dep.2", @@ -99,7 +99,7 @@ module Rscons it "returns false with strict_deps=true when cache has an extra dependency" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1", "checksum" => "dep.1.chk"}, {"fname" => "dep.2", @@ -115,7 +115,7 @@ module Rscons it "returns false when there is a new user dependency" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1"}], "user_deps" => []}}} cache = build_from(_cache) @@ -128,7 +128,7 @@ module Rscons it "returns false when a user dependency checksum has changed" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1", "checksum" => "dep.1.chk"}, {"fname" => "dep.2", @@ -151,7 +151,7 @@ module Rscons it "returns true when no condition for false is met" do _cache = {"targets" => {"target" => {"checksum" => "abc", - "command" => "command", + "command" => Digest::MD5.hexdigest("command".inspect), "deps" => [{"fname" => "dep.1", "checksum" => "dep.1.chk"}, {"fname" => "dep.2", @@ -182,7 +182,7 @@ module Rscons cache.register_build("the target", "the command", ["dep 1", "dep 2"], env) cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"] cached_target.should_not be_nil - cached_target["command"].should == "the command" + cached_target["command"].should == Digest::MD5.hexdigest("the command".inspect) cached_target["checksum"].should == "the checksum" cached_target["deps"].should == [ {"fname" => "dep 1", "checksum" => "dep 1 checksum"},