Skip to content

Commit 4bb2ff1

Browse files
committed
remove FASTGOGENERATE_ENABLED env
1 parent a7986a3 commit 4bb2ff1

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

Makefile

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ $Q echo "building $(or $(2), $(notdir $(1))) from internal/tools/go.mod..."
159159
$Q cd internal/tools; go build -mod=readonly -o ../../$(BIN)/$(or $(2), $(notdir $(1))) $(1)
160160
endef
161161

162-
# fastgogenerated tool uses the folder to store cache
163-
# absolute path is needed to be sure that the cache is not stored in multiple folders
164-
export FASTGOGENERATE_CACHE_PATH := $(shell pwd)/$(BUILD)/.fastgogenerate_cache
165-
166-
# does what go_build_tool does however uses another name of binary - <binary>.bin
167-
# instead of original binary, it install fastgogenerate tool with the same name as the tool
168-
# that is being built. Instead of use of original binaries, go generate will use a fastgogenerate tool
169-
# that cashes the results of go-generate executions and reuses them to speed up go-generate command
170-
define go_build_fastgogenerated_tool
171-
$Q echo "building fastgogenerated $(or $(2), $(notdir $(1))) from internal/tools/go.mod..."
172-
$Q go build -mod=readonly -ldflags="-X main.PluginName=$(or $(2), $(notdir $(1)))" -o $(BIN)/$(or $(2), $(notdir $(1))) ./cmd/tools/fastgogenerate
173-
$Q (cd internal/tools && go build -mod=readonly -o ../../$(BIN)/$(or $(2), $(notdir $(1))).bin $(1))
174-
endef
175-
176-
# if FASTGOGENERATE_ENABLED is not set, use go_build_tool, otherwise use go_build_fastgogenerated_tool
177-
define go_build_tool_or_fastgogenerated_tool
178-
$Q $(if $(FASTGOGENERATE_ENABLED),$(call go_build_fastgogenerated_tool,$1,$2),$(call go_build_tool,$1,$2))
179-
endef
180-
181162
# same as go_build_tool, but uses our main module file, not the tools one.
182163
# this is necessary / useful for tools that we are already importing in the repo, e.g. yarpc.
183164
# versions here are checked to make sure the tools version matches the service version.
@@ -202,7 +183,7 @@ $(BIN)/thriftrw-plugin-yarpc: go.mod go.work
202183
$(call go_mod_build_tool,go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc)
203184

204185
$(BIN)/mockgen: internal/tools/go.mod go.work
205-
$(call go_build_tool_or_fastgogenerated_tool,go.uber.org/mock/mockgen)
186+
$(call go_build_tool,go.uber.org/mock/mockgen)
206187

207188
$(BIN)/mockery: internal/tools/go.mod go.work
208189
$(call go_build_tool,github.com/vektra/mockery/v2,mockery)
@@ -219,7 +200,7 @@ $(BIN)/goimports: internal/tools/go.mod go.work
219200
$(call go_build_tool,golang.org/x/tools/cmd/goimports)
220201

221202
$(BIN)/gowrap: go.mod go.work
222-
$(call go_build_tool_or_fastgogenerated_tool,github.com/hexdigest/gowrap/cmd/gowrap)
203+
$(call go_build_tool,github.com/hexdigest/gowrap/cmd/gowrap)
223204

224205
$(BIN)/revive: internal/tools/go.mod go.work
225206
$(call go_build_tool,github.com/mgechev/revive)
@@ -235,6 +216,30 @@ $(BUILD)/go_mod_check: go.mod internal/tools/go.mod go.work
235216
$Q ./scripts/check-gomod-version.sh github.com/golang/mock/gomock $(if $(verbose),-v)
236217
$Q touch $@
237218

219+
220+
# fastgogenerated tool uses the folder to store cache
221+
# absolute path is needed to be sure that the cache is not stored in multiple folders
222+
export FASTGOGENERATE_CACHE_PATH := $(shell pwd)/$(BUILD)/.fastgogenerate_cache
223+
224+
# does what go_build_tool does however uses another name of binary - <binary>.bin
225+
# instead of original binary, it install fastgogenerate tool with the same name as the tool
226+
# that is being built. Instead of use of original binaries, go generate will use a fastgogenerate tool
227+
# that cashes the results of go-generate executions and reuses them to speed up go-generate command
228+
define go_build_fastgogenerated_tool
229+
$Q echo "building fastgogenerated $(or $(2), $(notdir $(1))) from internal/tools/go.mod..."
230+
$Q go build -mod=readonly -ldflags="-X main.PluginName=$(or $(2), $(notdir $(1)))" -o $(BIN)/$(or $(2), $(notdir $(1))) ./cmd/tools/fastgogenerate
231+
$Q (cd internal/tools && go build -mod=readonly -o ../../$(BIN)/$(or $(2), $(notdir $(1))).bin $(1))
232+
endef
233+
234+
# This target installs fastgogenerated tools that cache their results
235+
# to speed up go generate commands. It's useful when you want to optimize the
236+
# performance of code generation during development.
237+
# The tools are installed with both their original binary and a fast version
238+
# that caches results for reuse.
239+
install-fastgogenerated-tools:
240+
$(call go_build_fastgogenerated_tool,go.uber.org/mock/mockgen)
241+
$(call go_build_fastgogenerated_tool,github.com/hexdigest/gowrap/cmd/gowrap)
242+
238243
# copyright header checker/writer. only requires stdlib, so no other dependencies are needed.
239244
# $(BIN)/copyright: cmd/tools/copyright/licensegen.go
240245
# $Q go build -o $@ ./cmd/tools/copyright/licensegen.go

tools/fastgogenerate/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ FastGoGenerate is an experimental tool and is not enabled by default.
5858

5959
To enable FastGoGenerate, follow these steps:
6060
1. Run `make clean` to delete all binaries and caches
61-
2. Run `FASTGOGENERATE_ENABLED=true make pr` or `FASTGOGENERATE_ENABLED=true make go-generate` to invoke go-generation. This will install the proper binaries by default
62-
3. The first run will take the same amount of time as without caching, but subsequent runs should be faster
61+
2. Run `make install-fastgogenerated-tools` to install fastgogenerated tools
62+
3. Run `make pr` or `make go-generate` to run the code generation with FastGoGenerate
63+
4. The first run will take the same amount of time as without caching, but subsequent runs should be faster
6364

6465
#### How to Disable FastGoGenerate
6566

6667
To disable FastGoGenerate, follow these steps:
6768
1. Run `make clean` to delete all binaries and caches
68-
2. Run `make pr` or `make go-generate` to install original binaries
69+
2. Run `make pr` or `make go-generate` to install original binaries and run the code generation with original binaries
6970

7071
#### How It Works
7172

72-
* When `FASTGOGENERATE_ENABLED=true` is set, the Makefile builds a fastgogenerate binary with a built-in plugin name that replaces the original plugin binary
73+
* When `make install-fastgogenerated-tools` is run, the Makefile builds a fastgogenerate binary with a built-in plugin name that replaces the original plugin binary
7374
* The original plugin binary is stored with the same name plus `.bin` suffix
7475
* The Makefile sets `FASTGOGENERATE_CACHE_PATH` to `$(shell pwd)/$(BUILD)/.fastgogenerate_cache` to ensure that the cache can be easily removed with `make clean`
7576

0 commit comments

Comments
 (0)