Debian Codegraph @

Makefile

raw
1 include ./Makefile.Common
2
3 # This is the code that we want to run lint, etc.
4 ALL_SRC := $(shell find . -name '*.go' \
5 -not -path './internal/tools/*' \
6 -not -path '*/third_party/*' \
7 -not -path './pdata/internal/data/protogen/*' \
8 -not -path './service/internal/zpages/tmplgen/*' \
9 -type f | sort)
10
11 # All source code and documents. Used in spell check.
12 ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
13 -type f | sort)
14
15 # 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 )
21
22 CMD?=
23
24 RUN_CONFIG?=examples/local/otel-config.yaml
25 CONTRIB_PATH=$(CURDIR)/../opentelemetry-collector-contrib
26 COMP_REL_PATH=cmd/otelcorecol/components.go
27 MOD_NAME=go.opentelemetry.io/collector
28
29 # Function to execute a command. Note the empty line before endef to make sure each command
30 # gets executed separately instead of concatenated with previous one.
31 # Accepts command to execute as first parameter.
32 define exec-command
33 $(1)
34
35 endef
36
37 .DEFAULT_GOAL := all
38
39 .PHONY: all
40 all: checklicense checkdoc misspell goimpi goporto multimod-verify golint gotest
41
42 all-modules:
43 @echo $(ALL_MODULES) | tr ' ' '\n' | sort
44
45 .PHONY: gomoddownload
46 gomoddownload:
47 @$(MAKE) for-all-target TARGET="moddownload"
48
49 .PHONY: gotest
50 gotest:
51 @$(MAKE) for-all-target TARGET="test"
52
53 .PHONY: gobenchmark
54 gobenchmark:
55 @$(MAKE) for-all-target TARGET="benchmark"
56 cat `find . -name benchmark.txt` > benchmarks.txt
57
58 .PHONY: gotest-with-cover
59 gotest-with-cover:
60 @$(MAKE) for-all-target TARGET="test-with-cover"
61 $(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
62
63 .PHONY: gotest-with-junit
64 gotest-with-junit:
65 @$(MAKE) for-all-target TARGET="test-with-junit"
66
67 .PHONY: goporto
68 goporto:
69 $(GO_TOOL) porto -w --include-internal --skip-dirs "^cmd/mdatagen/third_party$$" ./
70
71 .PHONY: for-all
72 for-all:
73 @echo "running $${CMD} in root"
74 @$${CMD}
75 @set -e; for dir in $(GOMODULES); do \
76 (cd "$${dir}" && \
77 echo "running $${CMD} in $${dir}" && \
78 $${CMD} ); \
79 done
80
81 .PHONY: golint
82 golint:
83 @$(MAKE) for-all-target TARGET="lint"
84
85 .PHONY: goimpi
86 goimpi:
87 @$(MAKE) for-all-target TARGET="impi"
88
89 .PHONY: gofmt
90 gofmt:
91 @$(MAKE) for-all-target TARGET="fmt"
92
93 .PHONY: gotidy
94 gotidy:
95 @$(MAKE) for-all-target TARGET="tidy"
96
97 .PHONY: gogenerate
98 gogenerate:
99 cd cmd/mdatagen && $(GOCMD) install .
100 @$(MAKE) for-all-target TARGET="generate"
101 $(MAKE) fmt
102
103 .PHONY: govulncheck
104 govulncheck:
105 @$(MAKE) for-all-target TARGET="vulncheck"
106
107 .PHONY: addlicense
108 addlicense:
109 @ADDLICENSEOUT=`$(GO_TOOL) addlicense -s=only -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
110 if [ "$$ADDLICENSEOUT" ]; then \
111 echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
112 echo "$$ADDLICENSEOUT\n"; \
113 exit 1; \
114 else \
115 echo "Add License finished successfully"; \
116 fi
117
118 .PHONY: checklicense
119 checklicense:
120 @licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*') ; do \
121 awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
122 awk '/SPDX-License-Identifier: Apache-2.0|generated|GENERATED/ && NR<=4 { found=1; next } END { if (!found) print FILENAME }' $$f; \
123 done); \
124 if [ -n "$${licRes}" ]; then \
125 echo "license header checking failed:"; echo "$${licRes}"; \
126 exit 1; \
127 fi
128
129 .PHONY: misspell
130 misspell:
131 $(GO_TOOL) misspell -error $(ALL_DOC)
132
133 .PHONY: misspell-correction
134 misspell-correction:
135 $(GO_TOOL) misspell -w $(ALL_DOC)
136
137 .PHONY: run
138 run: otelcorecol
139 ./bin/otelcorecol_$(GOOS)_$(GOARCH) --config ${RUN_CONFIG} ${RUN_ARGS}
140
141 # Append root module to all modules
142 GOMODULES = $(ALL_MODULES) $(PWD)
143
144 # Define a delegation target for each module
145 .PHONY: $(GOMODULES)
146 $(GOMODULES):
147 @echo "Running target '$(TARGET)' in module '$@'"
148 $(MAKE) -C $@ $(TARGET)
149
150 # Triggers each module's delegation target
151 .PHONY: for-all-target
152 for-all-target: $(GOMODULES)
153
154 .PHONY: check-component
155 check-component:
156 ifndef COMPONENT
157 $(error COMPONENT variable was not defined)
158 endif
159
160 # Build the Collector executable.
161 .PHONY: otelcorecol
162 otelcorecol:
163 pushd cmd/otelcorecol && CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelcorecol_$(GOOS)_$(GOARCH) -tags "grpcnotrace" ./... && popd
164
165 .PHONY: genotelcorecol
166 genotelcorecol:
167 pushd cmd/builder/ && $(GOCMD) run ./ --skip-compilation --config ../otelcorecol/builder-config.yaml --output-path ../otelcorecol && popd
168 $(MAKE) -C cmd/otelcorecol fmt
169
170 .PHONY: actionlint
171 actionlint:
172 $(GO_TOOL) actionlint -config-file .github/actionlint.yaml -color .github/workflows/*.yml .github/workflows/*.yaml
173
174 .PHONY: ocb
175 ocb:
176 $(MAKE) -C cmd/builder config
177 $(MAKE) -C cmd/builder ocb
178
179 # Generate structs, functions and tests for pdata package.
180 genpdata:
181 cd internal/cmd/pdatagen && $(GOCMD) run main.go -C $(SRC_ROOT)
182 $(MAKE) -C pdata fmt
183
184 DOCKERCMD ?= docker
185 DOCKER_PROTOBUF ?= otel/build-protobuf:0.23.0
186
187 PROTO_SRC_DIRS := exporter/exporterhelper/internal/queue
188 PROTO_FILES := $(foreach dir,$(PROTO_SRC_DIRS),$(wildcard $(dir)/*.proto))
189 PROTOC := $(DOCKERCMD) run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${DOCKER_PROTOBUF} --proto_path=${PWD} --go_out=plugins=grpc,paths=source_relative:.
190
191 .PHONY: genproto
192 genproto:
193 @echo "Generating Go code for proto files"
194 @echo "Found proto files: $(PROTO_FILES)"
195 $(foreach file,$(PROTO_FILES),$(call exec-command,$(PROTOC) $(file)))
196 $(MAKE) fmt
197
198 ALL_MOD_PATHS := "" $(ALL_MODULES:.%=%)
199
200 .PHONY: prepare-contrib
201 prepare-contrib:
202 @echo Setting contrib at $(CONTRIB_PATH) to use this core checkout
203 @$(MAKE) -j2 -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit \
204 $(addprefix -replace ,$(join $(ALL_MOD_PATHS:%=go.opentelemetry.io/collector%=),$(ALL_MOD_PATHS:%=$(CURDIR)%)))"
205 @$(MAKE) -j2 -C $(CONTRIB_PATH) gotidy
206
207 @$(MAKE) generate-contrib
208
209 # Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles
210 # against the current version of this repo.
211 .PHONY: check-contrib
212 check-contrib:
213 @echo -e "\nRunning tests"
214 @$(MAKE) -C $(CONTRIB_PATH) gotest
215
216 @if [ -z "$(SKIP_RESTORE_CONTRIB)" ]; then \
217 $(MAKE) restore-contrib; \
218 fi
219
220 .PHONY: generate-contrib
221 generate-contrib:
222 @echo -e "\nGenerating files in contrib"
223 $(MAKE) -C $(CONTRIB_PATH) -B install-tools
224 $(MAKE) -C $(CONTRIB_PATH) generate GROUP=all
225
226 # Restores contrib to its original state after running check-contrib.
227 .PHONY: restore-contrib
228 restore-contrib:
229 @echo -e "\nRestoring contrib at $(CONTRIB_PATH) to its original state"
230 @$(MAKE) -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit \
231 $(addprefix -dropreplace ,$(ALL_MOD_PATHS:%=go.opentelemetry.io/collector%))"
232 @$(MAKE) -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod tidy"
233
234 # List of directories where certificates are stored for unit tests.
235 CERT_DIRS := localhost|""|config/configgrpc/testdata \
236 localhost|""|config/confighttp/testdata \
237 example1|"-1"|config/configtls/testdata \
238 example2|"-2"|config/configtls/testdata
239 cert-domain = $(firstword $(subst |, ,$1))
240 cert-suffix = $(word 2,$(subst |, ,$1))
241 cert-dir = $(word 3,$(subst |, ,$1))
242
243 # Generate certificates for unit tests relying on certificates.
244 .PHONY: certs
245 certs:
246 $(foreach dir, $(CERT_DIRS), $(call exec-command, @internal/buildscripts/gen-certs.sh -o $(call cert-dir,$(dir)) -s $(call cert-suffix,$(dir)) -m $(call cert-domain,$(dir))))
247
248 # Generate certificates for unit tests relying on certificates without copying certs to specific test directories.
249 .PHONY: certs-dryrun
250 certs-dryrun:
251 @internal/buildscripts/gen-certs.sh -d
252
253 .PHONY: checkapi
254 checkapi:
255 $(GO_TOOL) checkapi -folder . -config .checkapi.yaml
256
257 # Verify existence of READMEs for components specified as default components in the collector.
258 .PHONY: checkdoc
259 checkdoc:
260 $(GO_TOOL) checkfile --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "README.md"
261
262 # Construct new API state snapshots
263 .PHONY: apidiff-build
264 apidiff-build:
265 @$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/gen-apidiff.sh -p $(pkg)))
266
267 # If we are running in CI, change input directory
268 ifeq ($(CI), true)
269 APICOMPARE_OPTS=$(COMPARE_OPTS)
270 else
271 APICOMPARE_OPTS=-d "./internal/data/apidiff"
272 endif
273
274 # Compare API state snapshots
275 .PHONY: apidiff-compare
276 apidiff-compare:
277 @$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/compare-apidiff.sh -p $(pkg)))
278
279 .PHONY: multimod-verify
280 multimod-verify:
281 @echo "Validating versions.yaml"
282 $(GO_TOOL) multimod verify
283
284 MODSET?=stable
285 .PHONY: multimod-prerelease
286 multimod-prerelease:
287 $(GO_TOOL) multimod prerelease -s=true -b=false -v ./versions.yaml -m ${MODSET}
288 $(MAKE) gotidy
289
290 COMMIT?=HEAD
291 [email protected]:open-telemetry/opentelemetry-collector.git
292 .PHONY: push-tags
293 push-tags:
294 $(GO_TOOL) multimod verify
295 set -e; for tag in `$(GO_TOOL) multimod tag -m ${MODSET} -c ${COMMIT} --print-tags | grep -v "Using" `; do \
296 echo "pushing tag $${tag}"; \
297 git push ${REMOTE} $${tag}; \
298 done;
299
300 .PHONY: check-changes
301 check-changes:
302 $(GO_TOOL) multimod diff -p $(PREVIOUS_VERSION) -m $(MODSET)
303
304 .PHONY: prepare-release
305 prepare-release:
306 ifndef MODSET
307 @echo "MODSET not defined"
308 @echo "usage: make prepare-release RELEASE_CANDIDATE=<version eg 0.53.0> PREVIOUS_VERSION=<version eg 0.52.0> MODSET=beta"
309 exit 1
310 endif
311 ifdef PREVIOUS_VERSION
312 @echo "Previous version $(PREVIOUS_VERSION)"
313 else
314 @echo "PREVIOUS_VERSION not defined"
315 @echo "usage: make prepare-release RELEASE_CANDIDATE=<version eg 0.53.0> PREVIOUS_VERSION=<version eg 0.52.0> MODSET=beta"
316 exit 1
317 endif
318 ifdef RELEASE_CANDIDATE
319 @echo "Preparing ${MODSET} release $(RELEASE_CANDIDATE)"
320 else
321 @echo "RELEASE_CANDIDATE not defined"
322 @echo "usage: make prepare-release RELEASE_CANDIDATE=<version eg 0.53.0> PREVIOUS_VERSION=<version eg 0.52.0> MODSET=beta"
323 exit 1
324 endif
325 # ensure a clean branch
326 git diff -s --exit-code || (echo "local repository not clean"; exit 1)
327 # update files with new version
328 sed -i.bak 's/$(PREVIOUS_VERSION)/$(RELEASE_CANDIDATE)/g' versions.yaml
329 sed -i.bak 's/$(PREVIOUS_VERSION)/$(RELEASE_CANDIDATE)/g' ./cmd/builder/internal/builder/config.go
330 sed -i.bak 's/$(PREVIOUS_VERSION)/$(RELEASE_CANDIDATE)/g' ./cmd/builder/test/core.builder.yaml
331 sed -i.bak 's/$(PREVIOUS_VERSION)/$(RELEASE_CANDIDATE)/g' ./cmd/otelcorecol/builder-config.yaml
332 sed -i.bak 's/$(PREVIOUS_VERSION)/$(RELEASE_CANDIDATE)/g' examples/k8s/otel-config.yaml
333 find . -name "*.bak" -type f -delete
334 # commit changes before running multimod
335 git add .
336 git commit -m "prepare release $(RELEASE_CANDIDATE)"
337 $(MAKE) multimod-prerelease
338 # regenerate files
339 $(MAKE) -C cmd/builder config
340 $(MAKE) genotelcorecol
341 git add .
342 git commit -m "add multimod changes $(RELEASE_CANDIDATE)" || (echo "no multimod changes to commit")
343
344 .PHONY: clean
345 clean:
346 test -d bin && $(RM) bin/*
347
348 .PHONY: checklinks
349 checklinks:
350 command -v $(DOCKERCMD) >/dev/null 2>&1 || { echo >&2 "$(DOCKERCMD) not installed. Install before continuing"; exit 1; }
351 $(DOCKERCMD) run -w /home/repo --rm \
352 --mount 'type=bind,source='$(PWD)',target=/home/repo' \
353 lycheeverse/lychee \
354 --config .github/lychee.toml \
355 --root-dir /home/repo \
356 -v \
357 --no-progress './**/*.md'
358
359 # error message "failed to sync logger: sync /dev/stderr: inappropriate ioctl for device"
360 # is a known issue but does not affect function.
361 .PHONY: crosslink
362 crosslink:
363 @echo "Executing crosslink"
364 $(GO_TOOL) crosslink --root=$(shell pwd) --prune
365
366 FILENAME?=$(shell git branch --show-current)
367 .PHONY: chlog-new
368 chlog-new:
369 $(GO_TOOL) chloggen new --config $(CHLOGGEN_CONFIG) --filename $(FILENAME)
370
371 .PHONY: chlog-validate
372 chlog-validate:
373 $(GO_TOOL) chloggen validate --config $(CHLOGGEN_CONFIG)
374
375 .PHONY: chlog-preview
376 chlog-preview:
377 $(GO_TOOL) chloggen update --config $(CHLOGGEN_CONFIG) --dry
378
379 .PHONY: chlog-update
380 chlog-update:
381 $(GO_TOOL) chloggen update --config $(CHLOGGEN_CONFIG) --version $(VERSION)
382
383 .PHONY: builder-integration-test
384 builder-integration-test:
385 cd ./cmd/builder && ./test/test.sh
386
387 .PHONY: mdatagen-test
388 mdatagen-test:
389 cd cmd/mdatagen && $(GOCMD) install .
390 cd cmd/mdatagen && $(GOCMD) generate ./...
391 cd cmd/mdatagen && $(MAKE) fmt
392 cd cmd/mdatagen && $(GOCMD) test ./...
393
394 GITHUBGEN_ARGS ?= -skipgithub
395 GITHUBGEN := $(GO_TOOL) githubgen $(GITHUBGEN_ARGS)
396
397 .PHONY: generate-gh-issue-templates
398 generate-gh-issue-templates:
399 $(GITHUBGEN) issue-templates
400
401 .PHONY: generate-codeowners
402 generate-codeowners:
403 $(GITHUBGEN) --default-codeowner "open-telemetry/collector-approvers" codeowners
404
405 .PHONY: gengithub
406 gengithub: generate-codeowners generate-gh-issue-templates
407
408 .PHONY: gendistributions
409 gendistributions:
410 $(GITHUBGEN) distributions
411
412 .PHONY: generate-chloggen-components
413 generate-chloggen-components:
414 $(GITHUBGEN) chloggen-components