Issue #7 - store MD5 of build command instead of the full command in the cache
This commit is contained in:
parent
c61380b354
commit
fdc5c8773c
@ -13,7 +13,7 @@ module Rscons
|
|||||||
# "targets" => {
|
# "targets" => {
|
||||||
# "program" => {
|
# "program" => {
|
||||||
# "checksum" => "A1B2C3D4",
|
# "checksum" => "A1B2C3D4",
|
||||||
# "command" => ["gcc", "-o", "program", "program.o"],
|
# "command" => "13543518FE",
|
||||||
# "deps" => [
|
# "deps" => [
|
||||||
# {
|
# {
|
||||||
# "fname" => "program.o",
|
# "fname" => "program.o",
|
||||||
@ -29,7 +29,7 @@ module Rscons
|
|||||||
# },
|
# },
|
||||||
# "program.o" => {
|
# "program.o" => {
|
||||||
# "checksum" => "87654321",
|
# "checksum" => "87654321",
|
||||||
# "command" => ["gcc", "-c", "-o", "program.o", "program.c"],
|
# "command" => "98765ABCD",
|
||||||
# "deps" => [
|
# "deps" => [
|
||||||
# {
|
# {
|
||||||
# "fname" => "program.c",
|
# "fname" => "program.c",
|
||||||
@ -118,7 +118,7 @@ module Rscons
|
|||||||
return false unless @cache["targets"][target]["checksum"] == lookup_checksum(target)
|
return false unless @cache["targets"][target]["checksum"] == lookup_checksum(target)
|
||||||
|
|
||||||
# command used to build target must be identical
|
# 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 = @cache["targets"][target]["deps"] || []
|
||||||
cached_deps_fnames = cached_deps.map { |dc| dc["fname"] }
|
cached_deps_fnames = cached_deps.map { |dc| dc["fname"] }
|
||||||
@ -153,7 +153,7 @@ module Rscons
|
|||||||
def register_build(targets, command, deps, env)
|
def register_build(targets, command, deps, env)
|
||||||
Array(targets).each do |target|
|
Array(targets).each do |target|
|
||||||
@cache["targets"][target.encode(__ENCODING__)] = {
|
@cache["targets"][target.encode(__ENCODING__)] = {
|
||||||
"command" => command,
|
"command" => Digest::MD5.hexdigest(command.inspect),
|
||||||
"checksum" => calculate_checksum(target),
|
"checksum" => calculate_checksum(target),
|
||||||
"deps" => deps.map do |dep|
|
"deps" => deps.map do |dep|
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when the build command has changed" do
|
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)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
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
|
it "returns false when there is a new dependency" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1"}]}}}
|
"deps" => [{"fname" => "dep.1"}]}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
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
|
it "returns false when a dependency's checksum has changed" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1",
|
"deps" => [{"fname" => "dep.1",
|
||||||
"checksum" => "dep.1.chk"},
|
"checksum" => "dep.1.chk"},
|
||||||
{"fname" => "dep.2",
|
{"fname" => "dep.2",
|
||||||
@ -99,7 +99,7 @@ module Rscons
|
|||||||
|
|
||||||
it "returns false with strict_deps=true when cache has an extra dependency" do
|
it "returns false with strict_deps=true when cache has an extra dependency" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1",
|
"deps" => [{"fname" => "dep.1",
|
||||||
"checksum" => "dep.1.chk"},
|
"checksum" => "dep.1.chk"},
|
||||||
{"fname" => "dep.2",
|
{"fname" => "dep.2",
|
||||||
@ -115,7 +115,7 @@ module Rscons
|
|||||||
|
|
||||||
it "returns false when there is a new user dependency" do
|
it "returns false when there is a new user dependency" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1"}],
|
"deps" => [{"fname" => "dep.1"}],
|
||||||
"user_deps" => []}}}
|
"user_deps" => []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
@ -128,7 +128,7 @@ module Rscons
|
|||||||
|
|
||||||
it "returns false when a user dependency checksum has changed" do
|
it "returns false when a user dependency checksum has changed" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1",
|
"deps" => [{"fname" => "dep.1",
|
||||||
"checksum" => "dep.1.chk"},
|
"checksum" => "dep.1.chk"},
|
||||||
{"fname" => "dep.2",
|
{"fname" => "dep.2",
|
||||||
@ -151,7 +151,7 @@ module Rscons
|
|||||||
|
|
||||||
it "returns true when no condition for false is met" do
|
it "returns true when no condition for false is met" do
|
||||||
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
_cache = {"targets" => {"target" => {"checksum" => "abc",
|
||||||
"command" => "command",
|
"command" => Digest::MD5.hexdigest("command".inspect),
|
||||||
"deps" => [{"fname" => "dep.1",
|
"deps" => [{"fname" => "dep.1",
|
||||||
"checksum" => "dep.1.chk"},
|
"checksum" => "dep.1.chk"},
|
||||||
{"fname" => "dep.2",
|
{"fname" => "dep.2",
|
||||||
@ -182,7 +182,7 @@ module Rscons
|
|||||||
cache.register_build("the target", "the command", ["dep 1", "dep 2"], env)
|
cache.register_build("the target", "the command", ["dep 1", "dep 2"], env)
|
||||||
cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"]
|
cached_target = cache.instance_variable_get(:@cache)["targets"]["the target"]
|
||||||
cached_target.should_not be_nil
|
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["checksum"].should == "the checksum"
|
||||||
cached_target["deps"].should == [
|
cached_target["deps"].should == [
|
||||||
{"fname" => "dep 1", "checksum" => "dep 1 checksum"},
|
{"fname" => "dep 1", "checksum" => "dep 1 checksum"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user