From 38a18ebdfb1f0cef7d649f78f65fcbfb4a1311e1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Mon, 25 Mar 2024 11:03:04 +0800 Subject: [PATCH] gogen/packages/cache: pkgCache.hash (#417) * gogen/packages/cache: pkgCache.hash --- packages/cache/cache.go | 11 +++++++++-- packages/cache/cache_test.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/cache/cache.go b/packages/cache/cache.go index 57826bea..163cfc03 100644 --- a/packages/cache/cache.go +++ b/packages/cache/cache.go @@ -24,6 +24,11 @@ import ( "sync/atomic" ) +const ( + HashInvalid = "?" + HashSkip = "" +) + type depPkg struct { path string hash string // empty means dirty cache @@ -69,7 +74,9 @@ func (p *Impl) Prepare(dir string, pkgPath ...string) (err error) { deps := make([]depPkg, 0, len(v.deps)) pkg := &pkgCache{expfile: v.expfile, hash: h(v.path, true), deps: deps} for _, dep := range v.deps { - pkg.deps = append(pkg.deps, depPkg{dep, h(dep, false)}) + if hash := h(dep, false); hash != HashSkip { + pkg.deps = append(pkg.deps, depPkg{dep, hash}) + } } p.cache.Store(v.path, pkg) } @@ -93,7 +100,7 @@ func (p *Impl) Find(dir, pkgPath string) (expfile string, err error) { func isDirty(pkgPath string, val any, h PkgHash) bool { pkg := val.(*pkgCache) - if pkg.hash == "" || h(pkgPath, true) != pkg.hash { + if pkg.hash == HashInvalid || h(pkgPath, true) != pkg.hash { return true } for _, dep := range pkg.deps { diff --git a/packages/cache/cache_test.go b/packages/cache/cache_test.go index dcf19bbe..3e7c941e 100644 --- a/packages/cache/cache_test.go +++ b/packages/cache/cache_test.go @@ -23,7 +23,7 @@ import ( ) func dirtyPkgHash(pkgPath string, self bool) string { - return "" + return HashInvalid } func nodirtyPkgHash(pkgPath string, self bool) string {