oNaiPs / go-generate-fast

Enhanced version of go generate
MIT License
26 stars 0 forks source link

$GOFILE support? #21

Open MichaelSnowden opened 3 months ago

MichaelSnowden commented 3 months ago

As an alternative to https://github.com/temporalio/temporal/pull/5620, I was pointed to this tool as a way to cache and speed up go generate. However, I can't get it to work locally. It looks like it might be because of our usage of $GOFILE in our go:generate directives? For example:

# in temporalio/temporal
go-generate-fast common/archiver/archival_metadata.go
...
running "mockgen -copyright_file ../../LICENSE -package  -source  -destination archival_metadata_mock.go": exit status 1
common/archiver/archival_metadata.go: mockgen -copyright_file ../../LICENSE -package  -source  -destination archival_metadata_mock.go (error, 4ms)

As you can see, the -source argument has nothing after it.

Here's what the directive looks like in that file:

//go:generate go run ../../cmd/tools/mockgen/main.go -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination archival_metadata_mock.go

Am I right in suspecting that this is because $GOFILE replacements are not supported? If so, is there a plan to fix that any time soon? Thank you.

stasquatch commented 4 weeks ago

I don't have permissions to open a PR, but this can be fixed by moving line 196 - g.setEnv() - above where g.split(...) is called. The g.split(...) func depends on variables like $GOFILE to be available via g.getEnv() but currently isn't due to the ordering. You can see this in the original generate source code as well.