Closed rwl closed 4 years ago
Good idea.
On 13 Apr 2016, at 06:53, Richard Lincoln notifications@github.com wrote:
To prevent a template file from being included in the build process a build tag can be added at the top:
// +build ignore
package foo Unfortunately, these aren't removed from the generated output. As a result the generated code is also not included in the build.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub
It may be better to recommend a generate
tag so that go generate
may still be used, e.g:
// +build generate
package foo
//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "Generic=int"
The output may then be generated using the command:
$ go generate -tags generate
I hit this the other day as well. I do like rwl's +build generate
vs just removing ignore directives.
Until something like this hits master we've taken the approach of having all our templates named as .genny
and placing all the go:generate
directives in either gen.go
or the most relevant package file.
If folks are adventurous you should be able to merge #21 into your copy of genny
and start using tags to control your builds.
Just removing // +build ignore
or any modification of build tags by default is too auto-magical.
I like falun's method since nothing changes for people who don't need this feature.
Has there been any movement on this? Here's my current workaround:
in template.go:
// +build never
In another file:
//go:generate sh -c "genny -in=template.go gen \"GenericType=Foo,Bar\" | sed \"/\\+build never/d\" > generic-$GOFILE"
Any movement on this? I'd love to see the PR merged
@ghostsquad There was a PR but it went stale. Do you fancy preparing one and I'll merge it in?
I'd love to
Months later... got distracted with other things.. and coming back to this. Sorry about that!
To prevent a template file from being included in the build process a build tag can be added at the top:
Unfortunately, these aren't removed from the generated output. As a result the generated code is also not included in the build.