diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-05-20 19:34:58 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-05-20 19:34:58 +0900 |
commit | 39e6240124f7ad246db7be5d335de45ec8aacaec (patch) | |
tree | 5a35f93360681baf6180f291b4711ffe47c9a50d | |
parent | a9bda7a292633abc3488a2b931063b7af1b0a48a (diff) | |
download | android_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.go | 10 | ||||
-rw-r--r-- | log.go | 6 | ||||
-rw-r--r-- | main.go | 3 | ||||
-rwxr-xr-x | runtest.rb | 1 | ||||
-rw-r--r-- | serialize.go | 31 | ||||
-rwxr-xr-x | testcase/kati_cache.sh | 4 |
6 files changed, 32 insertions, 23 deletions
@@ -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 } @@ -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{}) { @@ -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") } } @@ -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 |