Skip to content

Commit df7f6fc

Browse files
Moving to use local binaries of required tools to ensure tool version is (open-telemetry#6974)
consistent across environment
1 parent c49279f commit df7f6fc

File tree

3 files changed

+54
-56
lines changed

3 files changed

+54
-56
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bin/
22
dist/
3+
.tools/
34

45
# GoLand IDEA
56
/.idea/

Makefile

+20-47
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
1515
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' )
1616

1717
CMD?=
18-
TOOLS_MOD_DIR := ./internal/tools
1918

2019
# TODO: Find a way to configure this in the generated code, currently no effect.
2120
BUILD_INFO_IMPORT_PATH=go.opentelemetry.io/collector/internal/version
@@ -27,11 +26,6 @@ CONTRIB_PATH=$(CURDIR)/../opentelemetry-collector-contrib
2726
COMP_REL_PATH=cmd/otelcorecol/components.go
2827
MOD_NAME=go.opentelemetry.io/collector
2928

30-
ADDLICENSE=addlicense
31-
GOCOVMERGE=gocovmerge
32-
MISSPELL=misspell -error
33-
MISSPELL_CORRECTION=misspell -w
34-
3529
# Function to execute a command. Note the empty line before endef to make sure each command
3630
# gets executed separately instead of concatenated with previous one.
3731
# Accepts command to execute as first parameter.
@@ -94,7 +88,7 @@ gogenerate:
9488
@$(MAKE) for-all-target TARGET="generate"
9589

9690
.PHONY: addlicense
97-
addlicense:
91+
addlicense: $(ADDLICENSE)
9892
@ADDLICENSEOUT=`$(ADDLICENSE) -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
9993
if [ "$$ADDLICENSEOUT" ]; then \
10094
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
@@ -105,7 +99,7 @@ addlicense:
10599
fi
106100

107101
.PHONY: checklicense
108-
checklicense:
102+
checklicense: $(ADDLICENSE)
109103
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
110104
if [ "$$ADDLICENSEOUT" ]; then \
111105
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
@@ -117,30 +111,12 @@ checklicense:
117111
fi
118112

119113
.PHONY: misspell
120-
misspell:
121-
$(MISSPELL) $(ALL_DOC)
114+
misspell: $(MISSPELL)
115+
$(MISSPELL) -error $(ALL_DOC)
122116

123117
.PHONY: misspell-correction
124-
misspell-correction:
125-
$(MISSPELL_CORRECTION) $(ALL_DOC)
126-
127-
.PHONY: install-tools
128-
install-tools:
129-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/client9/misspell/cmd/misspell
130-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint
131-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/google/addlicense
132-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/ory/go-acc
133-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/pavius/impi/cmd/impi
134-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/tcnksm/ghr
135-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/wadey/gocovmerge
136-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/checkdoc
137-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/chloggen
138-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/semconvgen
139-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install golang.org/x/exp/cmd/apidiff
140-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install golang.org/x/tools/cmd/goimports
141-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/jcchavezs/porto/cmd/porto
142-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/multimod
143-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/crosslink
118+
misspell-correction: $(MISSPELL)
119+
$(MISSPELL) -w $(ALL_DOC)
144120

145121
.PHONY: run
146122
run: otelcorecol
@@ -379,14 +355,14 @@ apidiff-compare:
379355
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/compare-apidiff.sh -p $(pkg)))
380356

381357
.PHONY: multimod-verify
382-
multimod-verify: install-tools
358+
multimod-verify: $(MULTIMOD)
383359
@echo "Validating versions.yaml"
384-
multimod verify
360+
$(MULTIMOD) verify
385361

386362
MODSET?=stable
387363
.PHONY: multimod-prerelease
388-
multimod-prerelease: install-tools
389-
multimod prerelease -s=true -b=false -v ./versions.yaml -m ${MODSET}
364+
multimod-prerelease: $(MULTIMOD)
365+
$(MULTIMOD) prerelease -s=true -b=false -v ./versions.yaml -m ${MODSET}
390366
$(MAKE) gotidy
391367

392368
COMMIT?=HEAD
@@ -459,27 +435,24 @@ checklinks:
459435
# error message "failed to sync logger: sync /dev/stderr: inappropriate ioctl for device"
460436
# is a known issue but does not affect function.
461437
.PHONY: crosslink
462-
crosslink:
438+
crosslink: $(CROSSLINK)
463439
@echo "Executing crosslink"
464-
crosslink --root=$(shell pwd) --prune
440+
$(CROSSLINK) --root=$(shell pwd) --prune
465441

466-
.PHONY: chlog-install
467-
chlog-install:
468-
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/chloggen
469442

470443
FILENAME?=$(shell git branch --show-current).yaml
471444
.PHONY: chlog-new
472-
chlog-new: chlog-install
473-
chloggen new --filename $(FILENAME)
445+
chlog-new: $(CHLOG)
446+
$(CHLOG) new --filename $(FILENAME)
474447

475448
.PHONY: chlog-validate
476-
chlog-validate: chlog-install
477-
chloggen validate
449+
chlog-validate: $(CHLOG)
450+
$(CHLOG) validate
478451

479452
.PHONY: chlog-preview
480-
chlog-preview: chlog-install
481-
chloggen update --dry
453+
chlog-preview: $(CHLOG)
454+
$(CHLOG) update --dry
482455

483456
.PHONY: chlog-update
484-
chlog-update: chlog-install
485-
chloggen update --version $(VERSION)
457+
chlog-update: $(CHLOG)
458+
$(CHLOG) update --version $(VERSION)

Makefile.Common

+33-9
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,70 @@ ALL_PKGS := $(sort $(shell go list ./...))
44
GOTEST_OPT?= -race -timeout 120s
55
GOCMD?= go
66
GOTEST=$(GOCMD) test
7-
GO_ACC=go-acc
8-
LINT=golangci-lint
9-
IMPI=impi
10-
117
GOOS := $(shell $(GOCMD) env GOOS)
128
GOARCH := $(shell $(GOCMD) env GOARCH)
9+
10+
TOOLS_MOD_DIR := $(PWD)/internal/tools
11+
TOOLS_BIN_DIR := $(PWD)/.tools
12+
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
13+
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"")
14+
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES)))
15+
16+
17+
.PHONY: install-tools
18+
install-tools: $(TOOLS_BIN_NAMES)
19+
20+
$(TOOLS_BIN_DIR):
21+
mkdir -p $@
22+
23+
$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
24+
cd $(TOOLS_MOD_DIR) && $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))
25+
26+
GO_ACC := $(TOOLS_BIN_DIR)/go-acc
27+
LINT := $(TOOLS_BIN_DIR)/golangci-lint
28+
IMPI := $(TOOLS_BIN_DIR)/impi
29+
ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense
30+
GOCOVMERGE := $(TOOLS_BIN_DIR)/gocovmerge
31+
MISSPELL := $(TOOLS_BIN_DIR)/misspell
32+
GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
33+
MULTIMOD := $(TOOLS_BIN_DIR)/multimod
34+
CROSSLINK := $(TOOLS_BIN_DIR)/crosslink
35+
CHLOG := $(TOOLS_BIN_DIR)/chloggen
36+
1337
GH := $(shell which gh)
1438

1539
.PHONY: test
1640
test:
1741
$(GOTEST) $(GOTEST_OPT) ./...
1842

1943
.PHONY: test-with-cover
20-
test-with-cover:
44+
test-with-cover: $(GO_ACC)
2145
$(GO_ACC) --output=coverage.out ./...
2246

2347
.PHONY: benchmark
2448
benchmark:
2549
$(GOTEST) -bench=. -run=notests ./...
2650

2751
.PHONY: fmt
28-
fmt:
52+
fmt: $(GOIMPORTS)
2953
gofmt -w -s ./
30-
goimports -w -local go.opentelemetry.io/collector ./
54+
$(GOIMPORTS) -w -local go.opentelemetry.io/collector ./
3155

3256
.PHONY: tidy
3357
tidy:
3458
rm -fr go.sum
3559
$(GOCMD) mod tidy -compat=1.18
3660

3761
.PHONY: lint
38-
lint:
62+
lint: $(LINT)
3963
$(LINT) run
4064

4165
.PHONY: generate
4266
generate:
4367
$(GOCMD) generate ./...
4468

4569
.PHONY: impi
46-
impi:
70+
impi: $(IMPI)
4771
@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal ./...
4872

4973
.PHONY: moddownload

0 commit comments

Comments
 (0)