goderive icon indicating copy to clipboard operation
goderive copied to clipboard

Provide a way to add build comment lines in generated files

Open stephane-martin opened this issue 8 years ago • 2 comments

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...

stephane-martin avatar Oct 01 '17 23:10 stephane-martin

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 avatar Oct 02 '17 08:10 awalterschulze

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

awalterschulze avatar Oct 02 '17 08:10 awalterschulze