From 689c087317f3d7c89431f6633a226d3768b46948 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 19 Apr 2025 17:43:08 +0000 Subject: [PATCH 1/3] Revert "Fail when expected files are not produced by protoc (#4287)" This reverts commit 077f15fe11b9da6aa0e3271db1260929f04fef87. --- go/tools/builders/protoc.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/go/tools/builders/protoc.go b/go/tools/builders/protoc.go index 73beb95a9b..46a9f012d9 100644 --- a/go/tools/builders/protoc.go +++ b/go/tools/builders/protoc.go @@ -20,8 +20,6 @@ import ( "errors" "flag" "fmt" - "go/parser" - "go/token" "io/ioutil" "log" "os" @@ -38,7 +36,7 @@ type genFileInfo struct { created bool // Whether the file was created by protoc from *genFileInfo // The actual file protoc produced if not Path unique bool // True if this base name is unique in expected results - ambiguous bool // True if there were more than one possible outputs that matched this file + ambiguious bool // True if there were more than one possible outputs that matched this file } func run(args []string) error { @@ -172,8 +170,8 @@ func run(args []string) error { case !copyTo.unique: // not unique, no copy allowed case copyTo.from != nil: - copyTo.ambiguous = true - info.ambiguous = true + copyTo.ambiguious = true + info.ambiguious = true default: copyTo.from = info copyTo.created = true @@ -185,9 +183,15 @@ func run(args []string) error { for _, f := range files { switch { case f.expected && !f.created: - return fmt.Errorf("file %q expected from plugin %q but not created", f.path, *plugin) - case f.expected && f.ambiguous: - fmt.Fprintf(buf, "Ambiguous output %v.\n", f.path) + // Some plugins only create output files if the proto source files have + // have relevant definitions (e.g., services for grpc_gateway). Create + // trivial files that the compiler will ignore for missing outputs. + data := []byte("// +build ignore\n\npackage ignore") + if err := ioutil.WriteFile(abs(f.path), data, 0644); err != nil { + return err + } + case f.expected && f.ambiguious: + fmt.Fprintf(buf, "Ambiguious output %v.\n", f.path) case f.from != nil: data, err := ioutil.ReadFile(f.from.path) if err != nil { @@ -203,15 +207,6 @@ func run(args []string) error { fmt.Fprintf(buf, "Check that the go_package option is %q.", *importpath) return errors.New(buf.String()) } - - if filepath.Ext(f.path) != ".go" { - continue - } - // Additionally check that created files are valid, because invalid Go file causes cache poisoning. - _, err := parser.ParseFile(token.NewFileSet(), f.path, nil, parser.PackageClauseOnly) - if err != nil { - return fmt.Errorf("plugin %q created an invalid Go file %q: %v", *plugin, f.path, err) - } } return nil From 11e233ad765c66b943e1eefd8a4369c87c2c5f47 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 19 Apr 2025 18:18:15 +0000 Subject: [PATCH 2/3] preserve the fix to the typo --- go/tools/builders/protoc.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/go/tools/builders/protoc.go b/go/tools/builders/protoc.go index 46a9f012d9..f3d13c229e 100644 --- a/go/tools/builders/protoc.go +++ b/go/tools/builders/protoc.go @@ -36,7 +36,7 @@ type genFileInfo struct { created bool // Whether the file was created by protoc from *genFileInfo // The actual file protoc produced if not Path unique bool // True if this base name is unique in expected results - ambiguious bool // True if there were more than one possible outputs that matched this file + ambiguous bool // True if there were more than one possible outputs that matched this file } func run(args []string) error { @@ -170,8 +170,8 @@ func run(args []string) error { case !copyTo.unique: // not unique, no copy allowed case copyTo.from != nil: - copyTo.ambiguious = true - info.ambiguious = true + copyTo.ambiguous = true + info.ambiguous = true default: copyTo.from = info copyTo.created = true @@ -190,8 +190,8 @@ func run(args []string) error { if err := ioutil.WriteFile(abs(f.path), data, 0644); err != nil { return err } - case f.expected && f.ambiguious: - fmt.Fprintf(buf, "Ambiguious output %v.\n", f.path) + case f.expected && f.ambiguous: + fmt.Fprintf(buf, "ambiguous output %v.\n", f.path) case f.from != nil: data, err := ioutil.ReadFile(f.from.path) if err != nil { From c87038ef4afc430db87e3b53a76745ce4561b2bb Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 19 Apr 2025 13:29:31 -0700 Subject: [PATCH 3/3] remove duplicate word Co-authored-by: Fabian Meumertzheim --- go/tools/builders/protoc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/tools/builders/protoc.go b/go/tools/builders/protoc.go index f3d13c229e..d70a7acb2c 100644 --- a/go/tools/builders/protoc.go +++ b/go/tools/builders/protoc.go @@ -183,7 +183,7 @@ func run(args []string) error { for _, f := range files { switch { case f.expected && !f.created: - // Some plugins only create output files if the proto source files have + // Some plugins only create output files if the proto source files // have relevant definitions (e.g., services for grpc_gateway). Create // trivial files that the compiler will ignore for missing outputs. data := []byte("// +build ignore\n\npackage ignore")