Skip to content

Commit f96a135

Browse files
authored
Revert "feat: migrate to tools directive" (#13899)
Reverts #13844 since it caused #13897 cc @dnaeon (no worries, we can accept your PR again once we are sure it won't cause further breakage)
1 parent 8658c56 commit f96a135

File tree

10 files changed

+195
-155
lines changed

10 files changed

+195
-155
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bin/
22
dist/
3+
.tools/
34
/local
45

56
# GoLand IDEA
@@ -36,3 +37,4 @@ go.work*
3637
# npm (used for markdown-link-check)
3738
node_modules/*
3839
package-lock.json
40+

Makefile

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
1313
-type f | sort)
1414

1515
# ALL_MODULES includes ./* dirs (excludes . dir)
16-
ALL_MODULES := $(shell find . -mindepth 2 \
17-
-type f \
18-
-name "go.mod" \
19-
-not -path "./internal/tools/*" \
20-
-exec dirname {} \; | sort )
16+
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | grep -E '^./' )
2117

2218
CMD?=
2319

@@ -65,8 +61,8 @@ gotest-with-junit:
6561
@$(MAKE) for-all-target TARGET="test-with-junit"
6662

6763
.PHONY: goporto
68-
goporto:
69-
$(GO_TOOL) porto -w --include-internal --skip-dirs "^cmd/mdatagen/third_party$$" ./
64+
goporto: $(PORTO)
65+
$(PORTO) -w --include-internal --skip-dirs "^cmd/mdatagen/third_party$$" ./
7066

7167
.PHONY: for-all
7268
for-all:
@@ -105,8 +101,8 @@ govulncheck:
105101
@$(MAKE) for-all-target TARGET="vulncheck"
106102

107103
.PHONY: addlicense
108-
addlicense:
109-
@ADDLICENSEOUT=`$(GO_TOOL) addlicense -s=only -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
104+
addlicense: $(ADDLICENSE)
105+
@ADDLICENSEOUT=`$(ADDLICENSE) -s=only -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
110106
if [ "$$ADDLICENSEOUT" ]; then \
111107
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
112108
echo "$$ADDLICENSEOUT\n"; \
@@ -116,7 +112,7 @@ addlicense:
116112
fi
117113

118114
.PHONY: checklicense
119-
checklicense:
115+
checklicense: $(ADDLICENSE)
120116
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*') ; do \
121117
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
122118
awk '/SPDX-License-Identifier: Apache-2.0|generated|GENERATED/ && NR<=4 { found=1; next } END { if (!found) print FILENAME }' $$f; \
@@ -127,12 +123,12 @@ checklicense:
127123
fi
128124

129125
.PHONY: misspell
130-
misspell:
131-
$(GO_TOOL) misspell -error $(ALL_DOC)
126+
misspell: $(MISSPELL)
127+
$(MISSPELL) -error $(ALL_DOC)
132128

133129
.PHONY: misspell-correction
134-
misspell-correction:
135-
$(GO_TOOL) misspell -w $(ALL_DOC)
130+
misspell-correction: $(MISSPELL)
131+
$(MISSPELL) -w $(ALL_DOC)
136132

137133
.PHONY: run
138134
run: otelcorecol
@@ -163,13 +159,13 @@ otelcorecol:
163159
pushd cmd/otelcorecol && CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelcorecol_$(GOOS)_$(GOARCH) -tags "grpcnotrace" ./... && popd
164160

165161
.PHONY: genotelcorecol
166-
genotelcorecol:
162+
genotelcorecol: install-tools
167163
pushd cmd/builder/ && $(GOCMD) run ./ --skip-compilation --config ../otelcorecol/builder-config.yaml --output-path ../otelcorecol && popd
168164
$(MAKE) -C cmd/otelcorecol fmt
169165

170166
.PHONY: actionlint
171-
actionlint:
172-
$(GO_TOOL) actionlint -config-file .github/actionlint.yaml -color .github/workflows/*.yml .github/workflows/*.yaml
167+
actionlint: $(ACTIONLINT)
168+
$(ACTIONLINT) -config-file .github/actionlint.yaml -color .github/workflows/*.yml .github/workflows/*.yaml
173169

174170
.PHONY: ocb
175171
ocb:
@@ -250,10 +246,13 @@ genproto_sub:
250246
@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/*
251247
@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/.* > /dev/null 2>&1 || true
252248

249+
remove-pdatagen:
250+
rm -f .tools/pdatagen
251+
253252
# Generate structs, functions and tests for pdata package. Must be used after any changes
254253
# to proto and after running `make genproto`
255-
genpdata:
256-
cd internal/cmd/pdatagen && $(GOCMD) run main.go -C $(SRC_ROOT)
254+
genpdata: remove-pdatagen $(PDATAGEN)
255+
$(PDATAGEN)
257256
$(MAKE) -C pdata fmt
258257

259258
INTERNAL_PROTO_SRC_DIRS := exporter/exporterhelper/internal/queue pdata/xpdata/request/internal
@@ -322,17 +321,17 @@ certs-dryrun:
322321
@internal/buildscripts/gen-certs.sh -d
323322

324323
.PHONY: checkapi
325-
checkapi:
326-
$(GO_TOOL) checkapi -folder . -config .checkapi.yaml
324+
checkapi: $(CHECKAPI)
325+
$(CHECKAPI) -folder . -config .checkapi.yaml
327326

328327
# Verify existence of READMEs for components specified as default components in the collector.
329328
.PHONY: checkdoc
330-
checkdoc:
331-
$(GO_TOOL) checkfile --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "README.md"
329+
checkdoc: $(CHECKFILE)
330+
$(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "README.md"
332331

333332
# Construct new API state snapshots
334333
.PHONY: apidiff-build
335-
apidiff-build:
334+
apidiff-build: $(APIDIFF)
336335
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/gen-apidiff.sh -p $(pkg)))
337336

338337
# If we are running in CI, change input directory
@@ -344,33 +343,33 @@ endif
344343

345344
# Compare API state snapshots
346345
.PHONY: apidiff-compare
347-
apidiff-compare:
346+
apidiff-compare: $(APIDIFF)
348347
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/compare-apidiff.sh -p $(pkg)))
349348

350349
.PHONY: multimod-verify
351-
multimod-verify:
350+
multimod-verify: $(MULTIMOD)
352351
@echo "Validating versions.yaml"
353-
$(GO_TOOL) multimod verify
352+
$(MULTIMOD) verify
354353

355354
MODSET?=stable
356355
.PHONY: multimod-prerelease
357-
multimod-prerelease:
358-
$(GO_TOOL) multimod prerelease -s=true -b=false -v ./versions.yaml -m ${MODSET}
356+
multimod-prerelease: $(MULTIMOD)
357+
$(MULTIMOD) prerelease -s=true -b=false -v ./versions.yaml -m ${MODSET}
359358
$(MAKE) gotidy
360359

361360
COMMIT?=HEAD
362361
REMOTE?[email protected]:open-telemetry/opentelemetry-collector.git
363362
.PHONY: push-tags
364-
push-tags:
365-
$(GO_TOOL) multimod verify
366-
set -e; for tag in `$(GO_TOOL) multimod tag -m ${MODSET} -c ${COMMIT} --print-tags | grep -v "Using" `; do \
363+
push-tags: $(MULTIMOD)
364+
$(MULTIMOD) verify
365+
set -e; for tag in `$(MULTIMOD) tag -m ${MODSET} -c ${COMMIT} --print-tags | grep -v "Using" `; do \
367366
echo "pushing tag $${tag}"; \
368367
git push ${REMOTE} $${tag}; \
369368
done;
370369

371370
.PHONY: check-changes
372-
check-changes:
373-
$(GO_TOOL) multimod diff -p $(PREVIOUS_VERSION) -m $(MODSET)
371+
check-changes: $(MULTIMOD)
372+
$(MULTIMOD) diff -p $(PREVIOUS_VERSION) -m $(MODSET)
374373

375374
.PHONY: prepare-release
376375
prepare-release:
@@ -430,29 +429,29 @@ checklinks:
430429
# error message "failed to sync logger: sync /dev/stderr: inappropriate ioctl for device"
431430
# is a known issue but does not affect function.
432431
.PHONY: crosslink
433-
crosslink:
432+
crosslink: $(CROSSLINK)
434433
@echo "Executing crosslink"
435-
$(GO_TOOL) crosslink --root=$(shell pwd) --prune
434+
$(CROSSLINK) --root=$(shell pwd) --prune
436435

437436
FILENAME?=$(shell git branch --show-current)
438437
.PHONY: chlog-new
439-
chlog-new:
440-
$(GO_TOOL) chloggen new --config $(CHLOGGEN_CONFIG) --filename $(FILENAME)
438+
chlog-new: $(CHLOGGEN)
439+
$(CHLOGGEN) new --config $(CHLOGGEN_CONFIG) --filename $(FILENAME)
441440

442441
.PHONY: chlog-validate
443-
chlog-validate:
444-
$(GO_TOOL) chloggen validate --config $(CHLOGGEN_CONFIG)
442+
chlog-validate: $(CHLOGGEN)
443+
$(CHLOGGEN) validate --config $(CHLOGGEN_CONFIG)
445444

446445
.PHONY: chlog-preview
447-
chlog-preview:
448-
$(GO_TOOL) chloggen update --config $(CHLOGGEN_CONFIG) --dry
446+
chlog-preview: $(CHLOGGEN)
447+
$(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --dry
449448

450449
.PHONY: chlog-update
451-
chlog-update:
452-
$(GO_TOOL) chloggen update --config $(CHLOGGEN_CONFIG) --version $(VERSION)
450+
chlog-update: $(CHLOGGEN)
451+
$(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --version $(VERSION)
453452

454453
.PHONY: builder-integration-test
455-
builder-integration-test:
454+
builder-integration-test: $(ENVSUBST)
456455
cd ./cmd/builder && ./test/test.sh
457456

458457
.PHONY: mdatagen-test
@@ -463,16 +462,16 @@ mdatagen-test:
463462
cd cmd/mdatagen && $(GOCMD) test ./...
464463

465464
.PHONY: generate-gh-issue-templates
466-
generate-gh-issue-templates:
467-
$(GO_TOOL) githubgen issue-templates
465+
generate-gh-issue-templates: $(GITHUBGEN)
466+
$(GITHUBGEN) issue-templates
468467

469468
.PHONY: generate-codeowners
470-
generate-codeowners:
471-
$(GO_TOOL) githubgen --default-codeowner "open-telemetry/collector-approvers" codeowners
469+
generate-codeowners: $(GITHUBGEN)
470+
$(GITHUBGEN) --default-codeowner "open-telemetry/collector-approvers" codeowners
472471

473472
.PHONY: gengithub
474-
gengithub: generate-codeowners generate-gh-issue-templates
473+
gengithub: $(GITHUBGEN) generate-codeowners generate-gh-issue-templates
475474

476475
.PHONY: gendistributions
477-
gendistributions:
478-
$(GO_TOOL) githubgen distributions
476+
gendistributions: $(GITHUBGEN)
477+
$(GITHUBGEN) distributions

Makefile.Common

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,101 @@ GOTEST_OPT?= -timeout $(GOTEST_TIMEOUT) $(if $(and $(filter windows,$(GOOS)), $(
1717
SRC_ROOT := $(shell git rev-parse --show-toplevel)
1818

1919
TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
20-
TOOLS_MOD_FILE := $(TOOLS_MOD_DIR)/go.mod
21-
GO_TOOL := $(GOCMD) tool -modfile $(TOOLS_MOD_FILE)
20+
TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
21+
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
22+
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$')
23+
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES))))
2224
CHLOGGEN_CONFIG := .chloggen/config.yaml
2325
# no trailing slash
2426
JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults
2527

28+
ACTIONLINT := $(TOOLS_BIN_DIR)/actionlint
29+
ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense
30+
APIDIFF := $(TOOLS_BIN_DIR)/apidiff
31+
CHECKAPI := $(TOOLS_BIN_DIR)/checkapi
32+
CHECKFILE := $(TOOLS_BIN_DIR)/checkfile
33+
CHLOGGEN := $(TOOLS_BIN_DIR)/chloggen
34+
CROSSLINK := $(TOOLS_BIN_DIR)/crosslink
35+
ENVSUBST := $(TOOLS_BIN_DIR)/envsubst
36+
GITHUBGEN := $(TOOLS_BIN_DIR)/githubgen
37+
GOFUMPT := $(TOOLS_BIN_DIR)/gofumpt
38+
GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
39+
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
40+
LINT := $(TOOLS_BIN_DIR)/golangci-lint
41+
PDATAGEN := $(TOOLS_BIN_DIR)/pdatagen
42+
IMPI := $(TOOLS_BIN_DIR)/impi
43+
MISSPELL := $(TOOLS_BIN_DIR)/misspell
44+
MULTIMOD := $(TOOLS_BIN_DIR)/multimod
45+
PORTO := $(TOOLS_BIN_DIR)/porto
46+
GOTESTSUM := $(TOOLS_BIN_DIR)/gotestsum
47+
MODERNIZE := $(TOOLS_BIN_DIR)/modernize
48+
49+
.PHONY: install-tools
50+
install-tools: $(TOOLS_BIN_NAMES)
51+
52+
$(TOOLS_BIN_DIR):
53+
mkdir -p $@
54+
55+
$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
56+
cd $(TOOLS_MOD_DIR) && GOOS="" GOARCH="" $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))
57+
2658
.PHONY: test
27-
test:
28-
$(GO_TOOL) gotestsum --packages="./..." -- $(GOTEST_OPT)
59+
test: $(GOTESTSUM)
60+
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT)
2961

3062
.PHONY: test-with-cover
31-
test-with-cover:
63+
test-with-cover: $(GOTESTSUM)
3264
mkdir -p $(PWD)/coverage/unit
33-
$(GO_TOOL) gotestsum \
34-
--packages="./..." -- \
35-
$(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"
65+
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"
3666

3767
.PHONY: test-with-junit
38-
test-with-junit:
68+
test-with-junit: $(GOTESTSUM)
3969
mkdir -p $(JUNIT_OUT_DIR)
40-
$(GO_TOOL) gotestsum \
41-
--packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- \
42-
$(GOTEST_OPT) ./...
70+
$(GOTESTSUM) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./...
4371

4472
.PHONY: benchmark
45-
benchmark:
46-
$(GO_TOOL) gotestsum \
47-
--packages="$(ALL_PKGS)" -- \
48-
-bench=. -run=notests ./... | tee benchmark.txt
73+
benchmark: $(GOTESTSUM)
74+
$(GOTESTSUM) --packages="$(ALL_PKGS)" -- -bench=. -run=notests ./... | tee benchmark.txt
4975

5076
.PHONY: fmt
5177
fmt: common/gofmt common/goimports common/gofumpt
5278

53-
# `modernize' cannot be installed as a Go tool via `go get -tool'.
54-
#
55-
# See [1] for more details.
56-
#
57-
# [1]: https://github.com/golang/go/issues/73279
5879
.PHONY: modernize
59-
modernize:
60-
$(GOCMD) run \
61-
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest \
62-
-fix -test -v ./...
80+
modernize: $(MODERNIZE)
81+
$(MODERNIZE) -fix -test -v ./...
6382

6483
.PHONY: tidy
6584
tidy:
6685
rm -fr go.sum
6786
$(GOCMD) mod tidy -compat=1.24.0
6887

6988
.PHONY: lint
70-
lint:
71-
$(GO_TOOL) golangci-lint run
89+
lint: $(LINT)
90+
$(LINT) run
7291

7392
.PHONY: common/gofmt
7493
common/gofmt:
7594
gofmt -w -s ./
7695

7796
.PHONY: common/goimports
78-
common/goimports:
79-
$(GO_TOOL) goimports -w -local go.opentelemetry.io/collector ./
97+
common/goimports: $(GOIMPORTS)
98+
$(GOIMPORTS) -w -local go.opentelemetry.io/collector ./
8099

81100
.PHONY: common/gofumpt
82-
common/gofumpt:
83-
$(GO_TOOL) gofumpt -l -w -extra .
101+
common/gofumpt: $(GOFUMPT)
102+
$(GOFUMPT) -l -w -extra .
84103

85104
.PHONY: vulncheck
86-
vulncheck:
87-
$(GO_TOOL) govulncheck ./...
105+
vulncheck: $(GOVULNCHECK)
106+
$(GOVULNCHECK) ./...
88107

89108
.PHONY: generate
90109
generate:
91110
$(GOCMD) generate ./...
92111

93112
.PHONY: impi
94-
impi:
95-
$(GO_TOOL) impi \
96-
--local go.opentelemetry.io/collector \
97-
--scheme stdThirdPartyLocal ./...
113+
impi: $(IMPI)
114+
@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal ./...
98115

99116
.PHONY: moddownload
100117
moddownload:

cmd/builder/test/test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ test_build_config() {
3333
echo "Starting test '${test}' at $(date)" >> "${out}/test.log"
3434

3535
final_build_config=$(basename "${build_config}")
36-
go tool -modfile "${WORKSPACE_DIR}/internal/tools/go.mod" envsubst \
37-
-o "${out}/${final_build_config}" -i <(cat "$build_config" "$replaces")
36+
"${WORKSPACE_DIR}/.tools/envsubst" -o "${out}/${final_build_config}" -i <(cat "$build_config" "$replaces")
3837
if ! go run . --config "${out}/${final_build_config}" --output-path "${out}" > "${out}/builder.log" 2>&1; then
3938
echo "❌ FAIL ${test}. Failed to compile the test ${test}. Build logs:"
4039
cat "${out}/builder.log"

0 commit comments

Comments
 (0)