Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions compiler/compiler-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,17 +946,15 @@ func (o *compilerCacheKeyOwner) keyedGoMod(file string, data []byte) []byte {

// sharedIdentity digests the schema, the compiler identity and the request.
// Override directories count by content, which decides the override facts the
// parity check reads.
// parity check reads. Protobuf binding roots count only through the bindings
// each package reads (protobufSideInputs): a root outside every module would
// key by its path from the request directory, which differs per build
// directory, so programs that share packages would share no artifact.
func (o *compilerCacheKeyOwner) sharedIdentity() string {
var b strings.Builder
writeKeyField(&b, "schema", compilerCacheSchema)
writeCompilerIdentity(&b)
req := o.req
if req.ProtobufTypeScriptBinding {
for _, root := range req.AdditionalBindingRoots {
writeKeyField(&b, "protobuf-binding-root", o.keyPath(root))
}
}
for _, flag := range goScriptBuildFlags(req.BuildFlags) {
writeKeyField(&b, "build-flag", flag)
}
Expand Down
21 changes: 12 additions & 9 deletions compiler/compiler-cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,26 @@ func TestCompilePackagesCacheReplaysAcrossCheckouts(t *testing.T) {

// TestCompilePackagesCacheReplaysAcrossReplacedCheckouts pins that a go.mod
// replacing a module with an absolute directory keys that directory by its
// module, so a generated module in a second checkout still replays.
// module, so a generated module in a second checkout still replays. The second
// module sits deeper, as a build tool's per platform directory does, and both
// name a protobuf binding root that holds no package of the graph.
func TestCompilePackagesCacheReplaysAcrossReplacedCheckouts(t *testing.T) {
cacheRoot := filepath.Join(t.TempDir(), "cache")
checkout := func(outputName string) {
config := Config{ProtobufTypeScriptBinding: true, AdditionalBindingRoots: []string{t.TempDir()}}
checkout := func(outputName, appPath string) {
root := writePackageGraphFixture(t, map[string]string{
"lib/go.mod": "module example.test/lib\n\ngo 1.25.3\n",
"lib/lib.go": "package lib\nconst Name = \"lib\"\n",
"app/main.go": "package main\n\nimport \"example.test/lib\"\n\nfunc main() { println(lib.Name) }\n",
"lib/go.mod": "module example.test/lib\n\ngo 1.25.3\n",
"lib/lib.go": "package lib\nconst Name = \"lib\"\n",
appPath + "/main.go": "package main\n\nimport \"example.test/lib\"\n\nfunc main() { println(lib.Name) }\n",
})
appDir := filepath.Join(root, "app")
appDir := filepath.Join(root, appPath)
writeFixtureFile(t, appDir, "go.mod", "module example.test/app\n\ngo 1.25.3\n\nrequire example.test/lib v0.0.0\n\nreplace example.test/lib => "+filepath.Join(root, "lib")+"\n")
compileCacheFixture(t, appDir, filepath.Join(t.TempDir(), outputName), cacheRoot)
compileCacheFixtureConfig(t, config, appDir, filepath.Join(t.TempDir(), outputName), cacheRoot)
}
checkout("first")
checkout("first", "app")
manifests := countCacheManifests(t, cacheRoot)

checkout("second")
checkout("second", "web/js/app")
if got := countCacheManifests(t, cacheRoot); got != manifests {
t.Fatalf("cache manifests after second checkout = %d, want %d", got, manifests)
}
Expand Down
Loading