cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 127 forks source link

Remove `// +build ignore` tags from generated output #18

Closed rwl closed 4 years ago

rwl commented 8 years ago

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.

matryer commented 8 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

rwl commented 8 years ago

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
falun commented 8 years ago

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.

falun commented 8 years ago

If folks are adventurous you should be able to merge #21 into your copy of genny and start using tags to control your builds.

xiegeo commented 8 years ago

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.

golightlyb commented 5 years ago

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"
ghostsquad commented 4 years ago

Any movement on this? I'd love to see the PR merged

matryer commented 4 years ago

@ghostsquad There was a PR but it went stale. Do you fancy preparing one and I'll merge it in?

ghostsquad commented 4 years ago

I'd love to

ghostsquad commented 4 years ago

Months later... got distracted with other things.. and coming back to this. Sorry about that!