Skip to content
Merged
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
21 changes: 8 additions & 13 deletions go/tools/builders/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"errors"
"flag"
"fmt"
"go/parser"
"go/token"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -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)
// 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")
if err := ioutil.WriteFile(abs(f.path), data, 0644); err != nil {
return err
}
case f.expected && f.ambiguous:
fmt.Fprintf(buf, "Ambiguous output %v.\n", f.path)
fmt.Fprintf(buf, "ambiguous output %v.\n", f.path)
case f.from != nil:
data, err := ioutil.ReadFile(f.from.path)
if err != nil {
Expand All @@ -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
Expand Down