plutoo / protobuf-csharp-port

Automatically exported from code.google.com/p/protobuf-csharp-port
Other
0 stars 0 forks source link

Add protoc-gen-cs.exe to be used as protoc.exe plugin #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Protobuf compiler has a plugin API. All one needs to do is to add a executable, 
say, protoc-gen-cs.exe in the protoc.exe's path and add --out_cs parameter to 
protoc command line to generate C# files.

Works likes this: when one passes --out_xxx, protoc will search for 
protoc-gen-xxx.exe. It will invoke this binary passing a serialized 
CodeGeneratorRequest protobuf message.

More details can be found here: 
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobu
f.compiler.plugin.pb

It seems that all that's needed is a new C# project which contains all sources 
from ProtoGen, except Program.cs. There would be a new Program.cs which will 
read a CodeGeneratorRequest from stdin. Name should be protoc-gen-cs.exe, I'd 
say.

Original issue reported on code.google.com by igorga...@gmail.com on 24 Jul 2014 at 7:53

GoogleCodeExporter commented 9 years ago
I implemented this in my fork: 
https://github.com/igorgatis/protobuf-csharp-port/compare/master...issue90

Patch file attached.

Original comment by igorga...@gmail.com on 25 Jul 2014 at 4:02

Attachments:

GoogleCodeExporter commented 9 years ago
Updated patch with parameter parsing working.

Usage example:

protoc.exe --plugin=path\to\protoc-gen-cs.exe 
--cs_out="-generated_code_attributes=true umbrella_namespace=TutorialProto 
:output\path" --proto_path=.\protos\ protos\tutorial\addressbook.proto

Notice the required ":" separating the output path.

Original comment by igorga...@gmail.com on 25 Jul 2014 at 4:41

GoogleCodeExporter commented 9 years ago
Okay, I've had a quick skim and it makes a fair amount of sense.

It's been a while since I've looked at the protogen code, to be honest - am I 
right in saying your patch should have no visible effect on the normal protogen 
behaviour?

Original comment by jonathan.skeet on 29 Jul 2014 at 6:16

GoogleCodeExporter commented 9 years ago
Yes, it should not. In fact, I designed towards that goal.

I'll make a small cosmetic change in this patch. Then I'll double check 
ProtoGen is not affected.

Original comment by igorga...@gmail.com on 29 Jul 2014 at 6:18

GoogleCodeExporter commented 9 years ago
Changes done. Latest patch can be seen at 
https://github.com/igorgatis/protobuf-csharp-port/compare/master...issue90

Let me know if you need a .patch file.

Original comment by igorga...@gmail.com on 1 Aug 2014 at 8:53

GoogleCodeExporter commented 9 years ago
If you can easily create a .patch file, it would definitely make it simpler for 
me. If it's just as much effort for you as for me though, I can do it myself.

Original comment by jonathan.skeet on 1 Aug 2014 at 9:12

GoogleCodeExporter commented 9 years ago
Here it is.

Original comment by igorga...@gmail.com on 1 Aug 2014 at 10:59

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision fa9349a386b1.

Original comment by jonathan.skeet on 2 Aug 2014 at 8:58

GoogleCodeExporter commented 9 years ago
Done. I had to tweak a few things where the patch import was messed up, and I 
reverted some incidental changes (e.g. generated comment lines, whitespace etc).

Original comment by jonathan.skeet on 2 Aug 2014 at 8:58

GoogleCodeExporter commented 9 years ago
Great!

Original comment by igorga...@gmail.com on 2 Aug 2014 at 8:59