Skip to content

Commit

Permalink
gogen/packages/cache: pkgCache.hash (#417)
Browse files Browse the repository at this point in the history
* gogen/packages/cache: pkgCache.hash
  • Loading branch information
xushiwei authored Mar 25, 2024
1 parent 9bf1e39 commit 38a18eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"sync/atomic"
)

const (
HashInvalid = "?"
HashSkip = ""
)

type depPkg struct {
path string
hash string // empty means dirty cache
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func dirtyPkgHash(pkgPath string, self bool) string {
return ""
return HashInvalid
}

func nodirtyPkgHash(pkgPath string, self bool) string {
Expand Down

0 comments on commit 38a18eb

Please sign in to comment.