awalterschulze / goderive

Derives and generates mundane golang functions that you do not want to maintain yourself
Apache License 2.0
1.23k stars 44 forks source link

Provide a way to add build comment lines in generated files #42

Open stephane-martin opened 6 years ago

stephane-martin commented 6 years ago

Hi,

thank you for this great project!

I need some generated files to be compiled only on Linux. Usually I'd drop a "// +build linux" line on top of such file. Obviously I don't want to manually add that on generated files. I could automate that with a Makefile, but Makefiles come with their own problem when you want to support both Linux and Macos (different make command, different sed command).

So maybe goderive could copy build comment lines from the source file to the generated file, when such comment line is present ? Or another more clever mechanism you could imagine...

awalterschulze commented 6 years ago

I think this sounds like a good feature. Basically I don't want goderive to generate code that is not used. This means that if code is generated from a file that will only be used in linux then the generated functions should only be available to the linux code.

This means that goderive should be able to generate multiple files for a single package and add the appropriate build tags to each, if they are necessary.

I don't know if I'll have time to build this feature, but I will provide support for a pull request.

awalterschulze commented 6 years ago

As a temporary work around you could always write a little go program (cross platform) to add the lines for you. I needed to do this for gogoprotobuf. Here is my very lame example https://github.com/gogo/protobuf/blob/master/gogoreplace/main.go