Skip to content

Commit a46c304

Browse files
committed
build: cleanup go.mk and make tasks
GO is just an alias for go now and we use the tools go.mod to run the tool instead of using go build.
1 parent a62c0a2 commit a46c304

File tree

7 files changed

+42
-79
lines changed

7 files changed

+42
-79
lines changed

Makefile

+32-32
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GOTESTFLAGS?=-v
1414
GOMODFLAG?=-mod=readonly
1515

1616
PYTHON_ENV?=.
17-
PYTHON_VENV_DIR:=$(PYTHON_ENV)/build/ve/$(shell $(GO) env GOOS)
17+
PYTHON_VENV_DIR:=$(PYTHON_ENV)/build/ve/$(shell go env GOOS)
1818
PYTHON_BIN:=$(PYTHON_VENV_DIR)/bin
1919
PYTHON=$(PYTHON_BIN)/python
2020
CURRENT_DIR=$(shell dirname $(shell readlink -f $(firstword $(MAKEFILE_LIST))))
@@ -50,7 +50,7 @@ LDFLAGS := \
5050
.PHONY: $(APM_SERVER_BINARIES)
5151
$(APM_SERVER_BINARIES):
5252
env CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
53-
$(GO) build -o $@ -trimpath $(GOFLAGS) $(GOMODFLAG) -ldflags "$(LDFLAGS)" ./x-pack/apm-server
53+
go build -o $@ -trimpath $(GOFLAGS) $(GOMODFLAG) -ldflags "$(LDFLAGS)" ./x-pack/apm-server
5454

5555
build/apm-server-linux-%: GOOS=linux
5656
build/apm-server-darwin-%: GOOS=darwin
@@ -65,24 +65,24 @@ GOVERSIONINFO_FLAGS := \
6565

6666
build/apm-server-windows-amd64.exe: x-pack/apm-server/versioninfo_windows_amd64.syso
6767
x-pack/apm-server/versioninfo_windows_amd64.syso: GOVERSIONINFO_FLAGS+=-64
68-
x-pack/apm-server/versioninfo_%.syso: $(GOVERSIONINFO) $(GITREFFILE) packaging/versioninfo.json
69-
$(GOVERSIONINFO) -o $@ $(GOVERSIONINFO_FLAGS) packaging/versioninfo.json
68+
x-pack/apm-server/versioninfo_%.syso: $(GITREFFILE) packaging/versioninfo.json
69+
go run -modfile=tools/go.mod github.com/josephspurrier/goversioninfo/cmd/goversioninfo -o $@ $(GOVERSIONINFO_FLAGS) packaging/versioninfo.json
7070

7171
.PHONY: apm-server
72-
apm-server: build/apm-server-$(shell $(GO) env GOOS)-$(shell $(GO) env GOARCH)
72+
apm-server: build/apm-server-$(shell go env GOOS)-$(shell go env GOARCH)
7373
@cp $^ $@
7474

7575
.PHONY: apm-server-oss
7676
apm-server-oss:
77-
@$(GO) build $(GOMODFLAG) -o $@ ./cmd/apm-server
77+
@go build $(GOMODFLAG) -o $@ ./cmd/apm-server
7878

7979
.PHONY: test
8080
test:
81-
@$(GO) test $(GOMODFLAG) $(GOTESTFLAGS) ./...
81+
@go test $(GOMODFLAG) $(GOTESTFLAGS) ./...
8282

8383
.PHONY: system-test
8484
system-test:
85-
@(cd systemtest; $(GO) test $(GOMODFLAG) $(GOTESTFLAGS) -timeout=20m ./...)
85+
@(cd systemtest; go test $(GOMODFLAG) $(GOTESTFLAGS) -timeout=20m ./...)
8686

8787
.PHONY:
8888
clean:
@@ -97,7 +97,7 @@ check-full: update check staticcheck
9797

9898
.PHONY: check-approvals
9999
check-approvals:
100-
@$(GO) run -modfile=tools/go.mod github.com/elastic/apm-tools/cmd/check-approvals
100+
@go run -modfile=tools/go.mod github.com/elastic/apm-tools/cmd/check-approvals
101101

102102
check: check-fmt check-headers check-git-diff
103103

@@ -109,7 +109,7 @@ BENCH_BENCHTIME?=100ms
109109
BENCH_COUNT?=1
110110
.PHONY: bench
111111
bench:
112-
@$(GO) test -count=$(BENCH_COUNT) -benchmem -run=XXX -benchtime=$(BENCH_BENCHTIME) -bench='.*' ./...
112+
@go test -count=$(BENCH_COUNT) -benchmem -run=XXX -benchtime=$(BENCH_BENCHTIME) -bench='.*' ./...
113113

114114
##############################################################################
115115
# Rules for updating config files, etc.
@@ -125,13 +125,13 @@ apm-server.docker.yml: apm-server.yml
125125

126126
.PHONY: go-generate
127127
go-generate:
128-
@cd cmd/intake-receiver && APM_SERVER_VERSION=$(APM_SERVER_VERSION) $(GO) generate .
128+
@cd cmd/intake-receiver && APM_SERVER_VERSION=$(APM_SERVER_VERSION) go generate .
129129

130130
.PHONY: add-headers
131-
add-headers: $(GOLICENSER)
131+
add-headers:
132132
ifndef CHECK_HEADERS_DISABLED
133-
@$(GOLICENSER) -exclude x-pack
134-
@$(GOLICENSER) -license Elasticv2 x-pack
133+
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -exclude x-pack
134+
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -license Elasticv2 x-pack
135135
endif
136136

137137
## get-version : Get the apm server version
@@ -156,10 +156,10 @@ docs: tf-docs
156156
sh script/build_apm_docs.sh apm-server docs/index.asciidoc build
157157

158158
.PHONY: tf-docs
159-
tf-docs: $(TERRAFORMDOCS) $(addsuffix /README.md,$(wildcard testing/infra/terraform/modules/*))
159+
tf-docs: $(addsuffix /README.md,$(wildcard testing/infra/terraform/modules/*))
160160

161161
testing/infra/terraform/modules/%/README.md: .FORCE
162-
$(TERRAFORMDOCS) markdown --hide-empty --header-from header.md --output-file=README.md --output-mode replace $(subst README.md,,$@)
162+
go run -modfile=tools/go.mod github.com/terraform-docs/terraform-docs markdown --hide-empty --header-from header.md --output-file=README.md --output-mode replace $(subst README.md,,$@)
163163

164164
.PHONY: .FORCE
165165
.FORCE:
@@ -169,8 +169,8 @@ testing/infra/terraform/modules/%/README.md: .FORCE
169169
# TODO in the future we should probably trigger the updates from apm-data,
170170
# and just keep the JSON Schema there.
171171
docs/spec: go.mod
172-
@$(GO) mod download github.com/elastic/apm-data
173-
rsync -v --delete --filter='P spec/openapi/' --chmod=Du+rwx,go+rx --chmod=Fu+rw,go+r -r $$($(GO) list -m -f {{.Dir}} github.com/elastic/apm-data)/input/elasticapm/docs/spec ./docs
172+
@go mod download github.com/elastic/apm-data
173+
rsync -v --delete --filter='P spec/openapi/' --chmod=Du+rwx,go+rx --chmod=Fu+rw,go+r -r $$(go list -m -f {{.Dir}} github.com/elastic/apm-data)/input/elasticapm/docs/spec ./docs
174174

175175
##############################################################################
176176
# Beats synchronisation.
@@ -181,11 +181,11 @@ BEATS_MODULE:=github.com/elastic/beats/v7
181181

182182
.PHONY: update-beats
183183
update-beats: update-beats-module update
184-
@echo --- Use this commit message: Update to elastic/beats@$(shell $(GO) list -m -f {{.Version}} $(BEATS_MODULE) | cut -d- -f3)
184+
@echo --- Use this commit message: Update to elastic/beats@$(shell go list -m -f {{.Version}} $(BEATS_MODULE) | cut -d- -f3)
185185

186186
.PHONY: update-beats-module
187187
update-beats-module:
188-
$(GO) get -d $(BEATS_MODULE)@$(BEATS_VERSION) && $(GO) mod tidy
188+
go get -d $(BEATS_MODULE)@$(BEATS_VERSION) && go mod tidy
189189

190190
##############################################################################
191191
# Linting, style-checking, license header checks, etc.
@@ -198,14 +198,14 @@ update-beats-module:
198198
STATICCHECK_CHECKS?=all,-ST1000
199199

200200
.PHONY: staticcheck
201-
staticcheck: $(STATICCHECK)
202-
$(STATICCHECK) -checks=$(STATICCHECK_CHECKS) ./...
201+
staticcheck:
202+
go run -modfile=tools/go.mod honnef.co/go/tools/cmd/staticcheck -checks=$(STATICCHECK_CHECKS) ./...
203203

204204
.PHONY: check-headers
205-
check-headers: $(GOLICENSER)
205+
check-headers:
206206
ifndef CHECK_HEADERS_DISABLED
207-
@$(GOLICENSER) -d -exclude build -exclude x-pack
208-
@$(GOLICENSER) -d -exclude build -license Elasticv2 x-pack
207+
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -d -exclude build -exclude x-pack
208+
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -d -exclude build -license Elasticv2 x-pack
209209
endif
210210

211211
.PHONY: check-docker-compose
@@ -215,23 +215,23 @@ check-docker-compose:
215215
.PHONY: check-gofmt gofmt
216216
check-fmt: check-gofmt
217217
fmt: gofmt
218-
check-gofmt: $(GOIMPORTS)
219-
@PATH=$(GOOSBUILD):$(PATH) sh script/check_goimports.sh
220-
gofmt: $(GOIMPORTS) add-headers
218+
check-gofmt:
219+
@sh script/check_goimports.sh
220+
gofmt: add-headers
221221
@echo "fmt - goimports: Formatting Go code"
222-
@PATH=$(GOOSBUILD):$(PATH) GOIMPORTSFLAGS=-w sh script/goimports.sh
222+
@GOIMPORTSFLAGS=-w sh script/goimports.sh
223223

224224
##############################################################################
225225
# NOTICE.txt & dependencies.csv generation.
226226
##############################################################################
227227

228228
MODULE_DEPS=$(sort $(shell \
229-
$(GO) list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./x-pack/apm-server))
229+
go list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./x-pack/apm-server))
230230

231231
notice: NOTICE.txt
232232
NOTICE.txt build/dependencies-$(APM_SERVER_VERSION).csv: go.mod tools/go.mod
233233
mkdir -p build/
234-
$(GO) list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
234+
go list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
235235
-includeIndirect \
236236
-overrides tools/notice/overrides.json \
237237
-rules tools/notice/rules.json \
@@ -281,7 +281,7 @@ $(PYTHON_BIN)/esrally: $(PYTHON_BIN)
281281
.PHONY: testing/rally/corpora
282282
testing/rally/corpora:
283283
@rm -fr testing/rally/corpora && mkdir testing/rally/corpora
284-
@cd systemtest/cmd/gencorpora && $(GO) run . -write-dir $(CURRENT_DIR)/testing/rally/corpora/ -replay-count $(RALLY_GENCORPORA_REPLAY_COUNT)
284+
@cd systemtest/cmd/gencorpora && go run . -write-dir $(CURRENT_DIR)/testing/rally/corpora/ -replay-count $(RALLY_GENCORPORA_REPLAY_COUNT)
285285

286286
##############################################################################
287287
# Smoke tests -- Basic smoke tests for APM Server.

go.mk

+1-38
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,8 @@ GITCOMMITTIMESTAMPUNIX ?= $(shell git log -1 --pretty=%ct)
55
GITREFFILE ?= $(GITDIR)/$(shell git rev-parse --symbolic-full-name HEAD)
66
GITROOT ?= $(shell git rev-parse --show-toplevel)
77

8-
GOROOT?=$(go env GOROOT)
98
GOLANG_VERSION=$(shell cat $(GITROOT)/.go-version)
10-
GO:=go
11-
GOARCH:=$(shell $(GO) env GOARCH)
12-
export PATH:=$(GOROOT)/bin:$(PATH)
13-
14-
GOOSBUILD:=$(GITROOT)/build/$(shell $(GO) env GOOS)
15-
GOIMPORTS=$(GOOSBUILD)/goimports
16-
GOLICENSER=$(GOOSBUILD)/go-licenser
17-
STATICCHECK=$(GOOSBUILD)/staticcheck
18-
TERRAFORMDOCS=$(GOOSBUILD)/terraform-docs
19-
GOBENCH=$(GOOSBUILD)/gobench
20-
GOVERSIONINFO=$(GOOSBUILD)/goversioninfo
21-
NFPM=$(GOOSBUILD)/nfpm
9+
GOARCH:=$(shell go env GOARCH)
2210

2311
APM_SERVER_VERSION=$(shell grep "const Version" $(GITROOT)/internal/version/version.go | cut -d'=' -f2 | tr -d '" ')
2412
APM_SERVER_VERSION_MAJORMINOR=$(shell echo $(APM_SERVER_VERSION) | sed 's/\(.*\..*\)\..*/\1/')
25-
26-
##############################################################################
27-
# Rules for creating and installing build tools.
28-
##############################################################################
29-
30-
$(GOIMPORTS): $(GITROOT)/go.mod
31-
$(GO) build -o $@ golang.org/x/tools/cmd/goimports
32-
33-
$(STATICCHECK): $(GITROOT)/tools/go.mod
34-
$(GO) build -o $@ -modfile=$< honnef.co/go/tools/cmd/staticcheck
35-
36-
$(GOLICENSER): $(GITROOT)/tools/go.mod
37-
$(GO) build -o $@ -modfile=$< github.com/elastic/go-licenser
38-
39-
$(TERRAFORMDOCS): $(GITROOT)/tools/go.mod
40-
$(GO) build -o $@ -modfile=$< github.com/terraform-docs/terraform-docs
41-
42-
$(GOBENCH): $(GITROOT)/tools/go.mod
43-
$(GO) build -o $@ -modfile=$< github.com/elastic/gobench
44-
45-
$(GOVERSIONINFO): $(GITROOT)/tools/go.mod
46-
$(GO) build -o $@ -modfile=$< github.com/josephspurrier/goversioninfo/cmd/goversioninfo
47-
48-
$(NFPM): $(GITROOT)/tools/go.mod
49-
$(GO) build -o $@ -modfile=$< github.com/goreleaser/nfpm/v2/cmd/nfpm

packaging.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ RPMS += $(patsubst %, $(DISTDIR)/apm-server-$(APM_SERVER_VERSION)-SNAPSHOT-%.rpm
141141
RPMS_AMD64 := $(filter %-x86_64.rpm, $(RPMS))
142142
RPMS_ARM64 := $(filter %-aarch64.rpm, $(RPMS))
143143

144-
$(DEBS_ARM64) $(RPMS_ARM64): $(NFPM) $(COMMON_PACKAGE_FILES) build/apm-server-linux-arm64 build/nfpm-arm64.yml
145-
$(DEBS_AMD64) $(RPMS_AMD64): $(NFPM) $(COMMON_PACKAGE_FILES) build/apm-server-linux-amd64 build/nfpm-amd64.yml
144+
$(DEBS_ARM64) $(RPMS_ARM64): $(COMMON_PACKAGE_FILES) build/apm-server-linux-arm64 build/nfpm-arm64.yml
145+
$(DEBS_AMD64) $(RPMS_AMD64): $(COMMON_PACKAGE_FILES) build/apm-server-linux-amd64 build/nfpm-amd64.yml
146146

147147
%.deb %.rpm:
148148
@mkdir -p $(DISTDIR)
149-
@$(NFPM) package -f $(filter build/nfpm-%.yml, $^) -t $@
149+
@go run -modfile=tools/go.mod github.com/goreleaser/nfpm/v2/cmd/nfpm package -f $(filter build/nfpm-%.yml, $^) -t $@
150150

151151
# Archive directories. These are the contents of tarball and zip artifacts.
152152
#

script/goimports.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

33
dirs=$(find . -maxdepth 1 -type d \! \( -name '.*' -or -name build \))
4-
exec goimports $GOIMPORTSFLAGS -local github.com/elastic $dirs
4+
exec go run -modfile=tools/go.mod golang.org/x/tools/cmd/goimports $GOIMPORTSFLAGS -local github.com/elastic $dirs

testing/apmsoak/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use-production:
1919
.PHONY: apmsoak
2020
apmsoak:
2121
@echo "-> Building apmsoak..."
22-
@cd $(APMSOAK_PATH) && GOOS=$(APMSOAK_GOOS) GOARCH=$(APMSOAK_GOARCH) $(GO) build .
22+
@cd $(APMSOAK_PATH) && GOOS=$(APMSOAK_GOOS) GOARCH=$(APMSOAK_GOARCH) go build .
2323

2424
.PHONY: init
2525
init:

testing/benchmark/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ terraform.tfvars:
6565
.PHONY: apmbench
6666
apmbench:
6767
@echo "-> Building apmbench..."
68-
@cd $(APMBENCH_PATH) && CGO_ENABLED=0 GOOS=$(APMBENCH_GOOS) GOARCH=$(APMBENCH_GOARCH) $(GO) build .
68+
@cd $(APMBENCH_PATH) && CGO_ENABLED=0 GOOS=$(APMBENCH_GOOS) GOARCH=$(APMBENCH_GOARCH) go build .
6969

7070
.PHONY: init
7171
init:
@@ -104,8 +104,8 @@ run-benchmark-autotuned:
104104
@ $(MAKE) run-benchmark BENCHMARK_AGENTS=$(shell echo $$(( $(BENCHMARK_AGENTS) * $(APM_SERVER_SIZE) )) )
105105

106106
.PHONY: index-benchmark-results
107-
index-benchmark-results: $(GOBENCH) _default-gobench-vars
108-
@cat $(BENCHMARK_RESULT) | $(GOBENCH) -es $(GOBENCH_HOST) -es-username $(GOBENCH_USERNAME) -es-password $(GOBENCH_PASSWORD) \
107+
index-benchmark-results: _default-gobench-vars
108+
@cat $(BENCHMARK_RESULT) | go run -modfile=tools/go.mod github.com/elastic/gobench -es $(GOBENCH_HOST) -es-username $(GOBENCH_USERNAME) -es-password $(GOBENCH_PASSWORD) \
109109
-index $(GOBENCH_INDEX) -tag "$(GOBENCH_DEFAULT_TAGS),$(GOBENCH_TAGS)"
110110

111111
.PHONY: _default-gobench-vars

testing/rally-cloud/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ destroy:
3434
.PHONY: rally/corpora
3535
rally/corpora:
3636
@rm -fr $(ROOT_DIR)/testing/rally/corpora && mkdir $(ROOT_DIR)/testing/rally/corpora
37-
@cd ../../systemtest/cmd/gencorpora && $(GO) run . \
37+
@cd ../../systemtest/cmd/gencorpora && go run . \
3838
-write-dir $(ROOT_DIR)/testing/rally/corpora/ \
3939
-replay-count $(RALLY_GENCORPORA_REPLAY_COUNT) \
4040
-override-meta-source-rootdir /home/rally/rally/corpora

0 commit comments

Comments
 (0)