protobuf
protobuf copied to clipboard
What is best practice to prevent overwriting generated .pb.go using older protoc-gen-go
I work with (a steady stream of new) students on various projects using protobuf, and more often than not they don't pay attention to the version of their installed protoc compiler, protoc-gen-go and protoc-gen-go-grpc plugins. This often results in overwriting existing .pb.go files with files generated by older versions in their pull requests that I then need to explicitly tell them about.
I could imagine that the plugin could check the version of the .pb.go files being overwritten and stop if being overwritten by an older version. As far as I know, there is currently no such check, but do tell me if there is... To intensionally overwrite with an older version, the user should delete the file first.
Another option that I'm considering is to add manual checks in the Makefile and run as part of CI tests.
Is there a best practice for dealing with this issue? Any other ideas?
I don’t think there is any way to do this, and if we were to someway implement it now, it would not be available in the older versions, which are the very ones that you’re trying to keep from overwriting the files. 😔
If you’re using some sort of build tool, like a Makefile or something, you would probably need to figure out something that does it there, and refuses to run the build tool if the version is not new enough.
You are right of course. I guess adding such a feature now would at least help people in the future.
Another solution could be to add a flag --overwrite_only_newer (tentatively named). Thus, if my Makefile use this flag, older versions would fail to execute because of the unknown flag, causing the developer (student) to take action. In fact, one of my students recently got an error Missing value for flag: --fatal_warnings; he was running with libprotoc 3.6.1.
This issue should be handled at the build system level, for example by verifying the the correct protoc version is installed.