}
h := cache.NewHash("moduleIndex")
+ // TODO(bcmills): Since modules in the index are checksummed, we could
+ // probably improve the cache hit rate by keying off of the module
+ // path@version (perhaps including the checksum?) instead of the module root
+ // directory.
fmt.Fprintf(h, "module index %s %s %v\n", runtime.Version(), indexVersion, modroot)
return h.Sum(), nil
}
// dirHash returns an ActionID corresponding to the state of the package
// located at filesystem path pkgdir.
-func dirHash(pkgdir string) (cache.ActionID, error) {
+func dirHash(modroot, pkgdir string) (cache.ActionID, error) {
h := cache.NewHash("moduleIndex")
+ fmt.Fprintf(h, "modroot %s\n", modroot)
fmt.Fprintf(h, "package %s %s %v\n", runtime.Version(), indexVersion, pkgdir)
entries, err := fsys.ReadDir(pkgdir)
if err != nil {
pkg *IndexPackage
err error
}
- r := pcache.Do(pkgdir, func() any {
- id, err := dirHash(pkgdir)
+ r := pcache.Do([2]string{modroot, pkgdir}, func() any {
+ id, err := dirHash(modroot, pkgdir)
if err != nil {
return result{nil, err}
}
--- /dev/null
+[short] skip # sleeps to make mtime cacheable
+
+go mod init example
+
+cd subdir
+go mod init example/subdir
+sleep 2s # allow go.mod mtime to be cached
+
+go list -f '{{.Dir}}: {{.ImportPath}}' ./pkg
+stdout $PWD${/}pkg': example/subdir/pkg$'
+
+rm go.mod # expose ../go.mod
+
+go list -f '{{.Dir}}: {{.ImportPath}}' ./pkg
+stdout $PWD${/}pkg': example/subdir/pkg$'
+
+-- subdir/pkg/pkg.go --
+package pkg