I wonder what is the best practice for protocol buffer regarding source repository (eg git) :
Do I have to put ONLY the .proto file in the repository and let anyone else who uses the source code to regenerate classes code with protoc compiler ? or is it a best pratice to put both .proto files AND source code generated by protoc compiler ?
You should never check in generated code if you can avoid it.
If you check in generated code, you take on multiple risks, such as:
.proto
file but forget to update the generated code. Their changes won't actually "take effect" until someone else later on regenerates the generated code for some other reason -- and then all of the sudden they see side effects they weren't expecting. If for some reason you absolutely have to check in generated code, I highly recommend creating an automated test that checks if the checked-in code matches what protoc
would generate if run fresh. (For example, the protobuf repository itself contains checked-in copies of generated code for descriptor.proto
because this code is needed to compile protoc
, creating a circular dependency. But there is a unit test that checks that the checked-in code matches what protoc
would generate.)
If your project is commonly used in its source code form (eg a library or a program every user is supposed to compile himself), I would make available release packages that have the generated files.
But I wouldn't put the generated files into the repository directly. And if most users will use a compiled binary, it is not that important to provide easy-to-compile source packages either. The protobuf generator then becomes just another build dependency.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.