Debian Codegraph @

Makefile

raw
1 # Copyright The containerd Authors.
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6
7 # http://www.apache.org/licenses/LICENSE-2.0
8
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Default commands and binaries used for builds, testing, etc.
16 GO ?= go
17 GOTEST ?= $(GO) test
18 GOBUILD ?= $(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS}
19 GOINSTALL ?= $(GO) install
20 INSTALL ?= install
21
22 # Go build tags.
23 ifdef BUILDTAGS
24 GO_BUILDTAGS = ${BUILDTAGS}
25 endif
26
27 GO_BUILDTAGS ?=
28 GO_TAGS = $(if $(GO_BUILDTAGS),-tags "$(strip $(GO_BUILDTAGS))",)
29
30 # Go build and test flags.
31 GO_BUILD_FLAGS =
32 TESTFLAGS_RACE =
33 TESTFLAGS ?= $(TESTFLAGS_RACE) $(EXTRA_TESTFLAGS)
34 TESTFLAGS_PARALLEL ?= 8
35
36 # See Golang issue re: '-trimpath': https://github.com/golang/go/issues/13809
37 GOPATHS = $(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n")
38 GO_GCFLAGS= $(shell \
39 set -- ${GOPATHS}; \
40 echo "-gcflags=-trimpath=$${1}/src";)
41
42 # Project packages.
43 PACKAGES ?= $(shell \
44 $(GO) list ${GO_TAGS} ./... | \
45 grep -v /example)
46
47 # Packages to $(GOTEST).
48 TESTPACKAGES ?= $(shell \
49 $(GO) list ${GO_TAGS} ./... | \
50 grep -v /cmd | grep -v /integration | grep -v /example)
51
52 define BUILD_BINARY
53 $(call WHALE_TARGET); \
54 $(GOBUILD) -o $@ ${GO_TAGS} ./$<
55 endef
56
57 SUBPACKAGES ?= $(shell \
58 find . -name go.mod | tr -s ' ' '\n' | \
59 grep -v '\./go.mod' | grep -v /example | \
60 sed 's:/go.mod::g')
61
62 define WHALE_TARGET
63 $(if $(SUBPKG),echo "$(WHALE) $@ $(SUBPKG)",echo "$(WHALE) $@")
64 endef
65
66 WHALE := "🇩"
67 ONI := "👹"
68
69 # Do quiet builds by default. Override with V=1 or Q=
70 ifeq ($(V),1)
71 Q =
72 else
73 Q = @
74 endif
75
76 all: build
77
78 showvar:
79 $(Q)echo $(VAR)=$($(VAR))
80
81 lint: ## run all linters
82 $(Q)echo "$(WHALE) $@"; \
83 GOGC=75 golangci-lint run;
84
85 build: ## build the go packages
86 $(Q)echo "$(WHALE) $@"; \
87 $(GOBUILD) -v ${PACKAGES};
88
89 test: ## run tests
90 $(Q)echo "$(WHALE) $@"; \
91 $(GOTEST) ${TESTFLAGS} ${TESTPACKAGES};
92
93 coverage: ## generate coverprofiles from the unit tests, except tests that require root
94 $(Q)echo "$(WHALE) $@"; \
95 rm -f coverage.txt; \
96 $(GOTEST) ${TESTFLAGS} ${TESTPACKAGES} 2> /dev/null; \
97 for pkg in ${PACKAGES}; do \
98 $(GOTEST) ${TESTFLAGS} \
99 -cover \
100 -coverprofile=profile.out \
101 -covermode=atomic $$pkg || exit; \
102 if [ -f profile.out ]; then \
103 cat profile.out >> coverage.txt.raw; \
104 rm profile.out; \
105 fi; \
106 done; \
107 sort -u coverage.txt.raw > coverage.txt; \
108 rm coverage.txt.raw;
109
110 vendor: ## ensure that all the go.mod/go.sum files are up-to-date
111 $(Q)echo "$(WHALE) $@"; \
112 $(GO) mod tidy && \
113 $(GO) mod verify
114
115 verify-vendor: vendor ## verify if all the go.mod/go.sum files are up-to-date
116 $(Q)echo "$(WHALE) $@"; \
117 test -z "$$(git status --short | grep "go.sum" | tee /dev/stderr)" || \
118 ((git diff | cat) && \
119 (echo "$(ONI) make sure to checkin changes after go mod tidy" && false))
120
121 help: ## this help
122 $(Q)awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
123
124 .PHONY: lint build test coverage vendor verify-vendor help
125
126 .DEFAULT: default