Skip to content

Commit 9c7fbd0

Browse files
Adding in cache testing
1 parent 98ea5ad commit 9c7fbd0

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

build/build.go

+4
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ func NewSession(options *Options) (*Session, error) {
802802
return s, nil
803803
}
804804

805+
func (s *Session) CacheCommonKey() string {
806+
return s.buildCache.CommonKey()
807+
}
808+
805809
// XContext returns the session's build context.
806810
func (s *Session) XContext() XContext { return s.xctx }
807811

build/cache/cache.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ func StatsString() string {
135135
sort.Strings(imports)
136136
fmt.Fprint(buf, "\ngn-filepaths: ")
137137
for _, im := range imports {
138-
fmt.Fprintf(buf, "{%s:", im)
138+
fmt.Fprintf(buf, "{%s: ", im)
139139
fp := FilePaths[im]
140140
if fp.StoreCount > 0 {
141141
fmt.Fprintf(buf, "%s (%d)", fp.StorePath, fp.StoreCount)
142142
}
143143
if fp.LoadCount > 0 {
144144
if fp.StorePath == fp.LoadPath {
145-
fmt.Fprintf(buf, "- \" (%d)", fp.LoadCount)
145+
fmt.Fprintf(buf, " - \" (%d)", fp.LoadCount)
146146
} else {
147-
fmt.Fprintf(buf, "- %s (%d)", fp.LoadPath, fp.LoadCount)
147+
fmt.Fprintf(buf, " - %s (%d)", fp.LoadPath, fp.LoadCount)
148148
}
149149
}
150150
fmt.Fprintf(buf, "}")
@@ -160,6 +160,9 @@ func recordStorePath(importPath, storePath string) {
160160
fp = &FilePathStats{}
161161
FilePaths[importPath] = fp
162162
}
163+
if strings.HasPrefix(storePath, cacheRoot) {
164+
storePath = storePath[len(cacheRoot):]
165+
}
163166
if fp.StorePath != "" && fp.StorePath != storePath {
164167
fmt.Printf("store path mismatch: %s, old %s, new: %s\n", importPath, fp.StorePath, storePath)
165168
}
@@ -173,6 +176,9 @@ func recordLoadPath(importPath, loadPath string) {
173176
fp = &FilePathStats{}
174177
FilePaths[importPath] = fp
175178
}
179+
if strings.HasPrefix(loadPath, cacheRoot) {
180+
loadPath = loadPath[len(cacheRoot):]
181+
}
176182
if fp.LoadPath != "" && fp.LoadPath != loadPath {
177183
fmt.Printf("load path mismatch: %s, old %s, new: %s\n", importPath, fp.LoadPath, loadPath)
178184
}
@@ -258,11 +264,11 @@ func (bc *BuildCache) LoadArchive(importPath string) *compiler.Archive {
258264

259265
// commonKey returns a part of the cache key common for all artifacts generated
260266
// under a given BuildCache configuration.
261-
func (bc *BuildCache) commonKey() string {
267+
func (bc *BuildCache) CommonKey() string {
262268
return fmt.Sprintf("%#v + %v", *bc, compiler.Version)
263269
}
264270

265271
// archiveKey returns a full cache key for a package's compiled archive.
266272
func (bc *BuildCache) archiveKey(importPath string) string {
267-
return path.Join("archive", bc.commonKey(), importPath)
273+
return path.Join("archive", bc.CommonKey(), importPath)
268274
}

tool.go

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ func main() {
476476
fmt.Println("---[build stats]---")
477477
fmt.Println(pkg.ImportPath)
478478
fmt.Println(tK.String())
479+
fmt.Printf("gn-cacheCommonKey: %s\n", s.CacheCommonKey())
479480
fmt.Println(cache.StatsString())
480481
fmt.Println("-------------------")
481482

0 commit comments

Comments
 (0)