Debian Codegraph @

Makefile.Common

raw
1 SHELL = /bin/bash
2 # ALL_PKGS is the list of all packages where ALL_SRC files reside.
3 ALL_PKGS := $(sort $(shell go list ./...))
4 # COVER_PKGS is the list of packages to include in the coverage
5 COVER_PKGS := $(shell go list ./... | tr "\n" ",")
6
7 CURR_MOD := $(shell go list -m | tr '/' '-' )
8
9 GOCMD?= go
10 GOOS := $(shell $(GOCMD) env GOOS)
11 GOARCH := $(shell $(GOCMD) env GOARCH)
12 GOTEST_TIMEOUT?=240s
13 # -race is not supported on windows arm64
14 GOTEST_OPT?= -timeout $(GOTEST_TIMEOUT) $(if $(and $(filter windows,$(GOOS)), $(filter arm64,$(GOARCH))),, -race)
15
16 # SRC_ROOT is the top of the source tree.
17 SRC_ROOT := $(shell git rev-parse --show-toplevel)
18
19 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)
22 CHLOGGEN_CONFIG := .chloggen/config.yaml
23 # no trailing slash
24 JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults
25
26 .PHONY: test
27 test:
28 $(GO_TOOL) gotestsum --packages="./..." -- $(GOTEST_OPT)
29
30 .PHONY: test-with-cover
31 test-with-cover:
32 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"
36
37 .PHONY: test-with-junit
38 test-with-junit:
39 mkdir -p $(JUNIT_OUT_DIR)
40 $(GO_TOOL) gotestsum \
41 --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- \
42 $(GOTEST_OPT) ./...
43
44 .PHONY: benchmark
45 benchmark:
46 MEMBENCH=yes $(GO_TOOL) gotestsum \
47 --packages="$(ALL_PKGS)" -- \
48 -bench=. -run=notests ./... | tee benchmark.txt
49
50 .PHONY: fmt
51 fmt: common/gofmt common/goimports common/gofumpt
52
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
58 .PHONY: modernize
59 modernize:
60 $(GOCMD) run \
61 golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest \
62 -fix -test -v ./...
63
64 .PHONY: tidy
65 tidy:
66 rm -fr go.sum
67 $(GOCMD) mod tidy -compat=1.24.0
68
69 .PHONY: lint
70 lint:
71 $(GO_TOOL) golangci-lint run
72
73 .PHONY: common/gofmt
74 common/gofmt:
75 gofmt -w -s ./
76
77 .PHONY: common/goimports
78 common/goimports:
79 $(GO_TOOL) goimports -w -local go.opentelemetry.io/collector ./
80
81 .PHONY: common/gofumpt
82 common/gofumpt:
83 $(GO_TOOL) gofumpt -l -w -extra .
84
85 .PHONY: vulncheck
86 vulncheck:
87 $(GO_TOOL) govulncheck ./...
88
89 .PHONY: generate
90 generate:
91 $(GOCMD) generate ./...
92
93 .PHONY: impi
94 impi:
95 $(GO_TOOL) impi \
96 --local go.opentelemetry.io/collector \
97 --scheme stdThirdPartyLocal ./...
98
99 .PHONY: moddownload
100 moddownload:
101 $(GOCMD) mod download
102
103 timebenchmark:
104 go test -bench=. -benchtime=1s ./...