bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.35k stars 635 forks source link

Proposal: Fail protoc code gen on missing expected output files #3949

Open r-hang opened 1 month ago

r-hang commented 1 month ago

The go_proto_compile rule currently generates trivial files to substitute for expected files that are missing from the output of the protoc code generation action (ref: https://github.com/bazelbuild/rules_go/pull/1394)

We've been facing some cache poisoning issues where under certain conditions, the go_proto_compile rule will not generate a file when it should. Currently, the action succeeds and the trivial file will be cached as the output of the Bazel action, which fails subsequent downstream actions because a trivial file has substituted for Go file contents that should have been generated.

The go_proto_compile rule should fail if an output that is expected is not generated instead of generating a trivial file. One benefit is that this prevents bad outputs from being cached. I believe it should be the onus of the code generator to do the extra work of generating predictable outputs instead of allowing for the go_proto_compile rule to fill the gaps.

Because go_proto_compile currently creates a trivial file when an expected file is not generated, we can't tell easily distinguish between situations where the code generator intentionally generates a blank file to comply with Bazel's restrictions on expected outputs or where the protoc action erronously didn't generate an expected file.

I believe we should error when expected output files are not produced in the go protoc builder https://github.com/bazelbuild/rules_go/blob/master/go/tools/builders/protoc.go#L189