aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-05-20 19:34:58 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-05-20 19:34:58 +0900
commit39e6240124f7ad246db7be5d335de45ec8aacaec (patch)
tree5a35f93360681baf6180f291b4711ffe47c9a50d
parenta9bda7a292633abc3488a2b931063b7af1b0a48a (diff)
downloadandroid_build_kati-39e6240124f7ad246db7be5d335de45ec8aacaec.tar.gz
android_build_kati-39e6240124f7ad246db7be5d335de45ec8aacaec.tar.bz2
android_build_kati-39e6240124f7ad246db7be5d335de45ec8aacaec.zip
Check the timestamp of cache
-rw-r--r--eval.go10
-rw-r--r--log.go6
-rw-r--r--main.go3
-rwxr-xr-xruntest.rb1
-rw-r--r--serialize.go31
-rwxr-xr-xtestcase/kati_cache.sh4
6 files changed, 32 insertions, 23 deletions
diff --git a/eval.go b/eval.go
index d23d470..71d9691 100644
--- a/eval.go
+++ b/eval.go
@@ -265,10 +265,16 @@ func (ev *Evaluator) evalIncludeFile(fname string, f *os.File) error {
func (ev *Evaluator) updateMakefileTimestamp(fn string, ts int64) {
ts2, present := ev.readMks[fn]
if present {
- if ts != ts2 {
- // Inconsistent.
+ if ts2 == -1 && ts != -1 {
+ Warn(ev.filename, ev.lineno, "%s was created after the previous read", fn)
+ ev.readMks[fn] = -2
+ } else if ts != -1 && ts == -1 {
+ Warn(ev.filename, ev.lineno, "%s was removed after the previous read", fn)
ev.readMks[fn] = -2
}
+ // Just keep old value otherwise. If the content has
+ // been changed, we can detect the change by the
+ // timestamp check.
} else {
ev.readMks[fn] = ts
}
diff --git a/log.go b/log.go
index b795ecc..2fb45ce 100644
--- a/log.go
+++ b/log.go
@@ -7,7 +7,7 @@ import (
"runtime/pprof"
)
-func log(f string, a ...interface{}) {
+func LogAlways(f string, a ...interface{}) {
var buf bytes.Buffer
buf.WriteString("*kati*: ")
buf.WriteString(f)
@@ -19,14 +19,14 @@ func LogStats(f string, a ...interface{}) {
if !katiLogFlag && !katiStatsFlag {
return
}
- log(f, a...)
+ LogAlways(f, a...)
}
func Log(f string, a ...interface{}) {
if !katiLogFlag {
return
}
- log(f, a...)
+ LogAlways(f, a...)
}
func Warn(filename string, lineno int, f string, a ...interface{}) {
diff --git a/main.go b/main.go
index 2a92a5a..d92456e 100644
--- a/main.go
+++ b/main.go
@@ -144,10 +144,7 @@ func getDepGraph(clvars []string, targets []string) *DepGraph {
if useCache {
g := LoadDepGraphCache(makefile, targets)
if g != nil {
- Log("Cache found!")
return g
- } else {
- Log("Cache not found")
}
}
diff --git a/runtest.rb b/runtest.rb
index 93b17c5..1dc451a 100755
--- a/runtest.rb
+++ b/runtest.rb
@@ -192,6 +192,7 @@ run_shell_test = proc do |sh|
if expected != output
puts "#{name}: FAIL"
+ puts `diff -u out.make out.kati`
failures << name
else
puts "#{name}: PASS"
diff --git a/serialize.go b/serialize.go
index b723f11..5e25e86 100644
--- a/serialize.go
+++ b/serialize.go
@@ -561,19 +561,24 @@ func LoadDepGraph(filename string) *DepGraph {
func LoadDepGraphCache(makefile string, roots []string) *DepGraph {
filename := GetCacheFilename(makefile, roots)
- if exists(filename) {
- g := LoadDepGraph(filename)
- for _, mk := range g.readMks {
- ts := getTimestamp(mk.Filename)
- if mk.Timestamp >= 0 && ts < 0 {
- return nil
- }
- if mk.Timestamp <= ts {
- return nil
- }
+ if !exists(filename) {
+ LogAlways("Cache not found")
+ return nil
+ }
+
+ g := LoadDepGraph(filename)
+ for _, mk := range g.readMks {
+ ts := getTimestamp(mk.Filename)
+ if mk.Timestamp >= 0 && ts < 0 {
+ LogAlways("Cache expired: %s", mk.Filename)
+ return nil
+ }
+ if mk.Timestamp <= ts {
+ LogAlways("Cache expired: %s", mk.Filename)
+ return nil
}
- g.isCached = true
- return g
}
- return nil
+ g.isCached = true
+ LogAlways("Cache found!")
+ return g
}
diff --git a/testcase/kati_cache.sh b/testcase/kati_cache.sh
index 0a03c00..ffb7785 100755
--- a/testcase/kati_cache.sh
+++ b/testcase/kati_cache.sh
@@ -36,7 +36,7 @@ EOF
"$@" | tee /tmp/log 2>&1
if [ -e .kati_cache.Makefile ]; then
- if ! grep '\*kati\*: Cache not found' /tmp/log; then
- echo 'Cache unexpectedly found'
+ if ! grep '\*kati\*: Cache expired' /tmp/log; then
+ echo 'Cache unexpectedly not expired'
fi
fi