-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathMakefile
More file actions
242 lines (186 loc) · 6.36 KB
/
Copy pathMakefile
File metadata and controls
242 lines (186 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Copyright The containerd Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO_CMD := go
GO_BUILD := $(GO_CMD) build
GO_INSTALL := $(GO_CMD) install
GO_TEST := $(GO_CMD) test
GO_LINT := golint -set_exit_status
GO_FMT := gofmt
GO_VET := $(GO_CMD) vet
GO_BUILD_FLAGS ?=
GO_MODULES := $(shell $(GO_CMD) list ./...)
GOLANG_CILINT := golangci-lint
GINKGO := ginkgo
RESOLVED_PWD := $(shell realpath $(shell pwd))
BUILD_PATH := $(RESOLVED_PWD)/build
BIN_PATH := $(BUILD_PATH)/bin
TOOLS_PATH := $(BUILD_PATH)/tools
PROTOC_PATH := $(TOOLS_PATH)/protoc
COVERAGE_PATH := $(BUILD_PATH)/coverage
PROTOBUF_VERSION = 3.20.1
PROTO_SOURCES = $(shell find pkg -name '*.proto' | grep -v /vendor/)
PROTO_INCLUDE = -I $(PWD) -I$(PROTOC_PATH)/include
PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \
--go_opt=paths=source_relative --go_out=. \
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=. \
--go-plugin_opt=paths=source_relative,disable_pb_gen=true --go-plugin_out=.
PROTO_COMPILE = PATH=$(PROTOC_PATH)/bin protoc $(PROTO_OPTIONS)
PLUGINS := \
$(BIN_PATH)/logger \
$(BIN_PATH)/device-injector \
$(BIN_PATH)/hook-injector \
$(BIN_PATH)/differ \
$(BIN_PATH)/ulimit-adjuster \
$(BIN_PATH)/v010-adapter \
$(BIN_PATH)/template \
$(BIN_PATH)/wasm \
$(BIN_PATH)/network-device-injector \
$(BIN_PATH)/network-logger \
$(BIN_PATH)/rdt \
$(BIN_PATH)/writable-cgroups
ifneq ($(V),1)
Q := @
endif
#
# top-level targets
#
all: build build-plugins
build: build-proto build-check
clean: clean-plugins
allclean: clean clean-cache
test: test-gopkgs
FORCE:
#
# build targets
#
build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies build-protoc-gen-strip build-protoc-gen-owners
for src in $(PROTO_SOURCES); do \
$(PROTO_COMPILE) \
--plugin=protoc-gen-strip=$(abspath $(BIN_PATH)/protoc-gen-strip) \
--strip_out=pkg/api \
--strip_opt=file=strip.go \
--plugin=protoc-gen-owners=$(abspath $(BIN_PATH)/protoc-gen-owners) \
--owners_out=pkg/api \
--owners_opt=file=owners_generated.go \
$$src; \
done
sed -i '1s;^;//go:build !wasip1\n\n;' pkg/api/api_ttrpc.pb.go
.PHONY: build-proto-dockerized
build-proto-dockerized:
$(Q)docker build --build-arg ARTIFACTS="$(dir $(PROTO_SOURCES))" --target final \
--output type=local,dest=$(RESOLVED_PWD) \
-f hack/Dockerfile.buildproto .
$(Q)tar xf artifacts.tgz && rm -f artifacts.tgz
build-plugins: go-generate $(PLUGINS)
build-check:
$(Q)$(GO_BUILD) -v $(GO_MODULES)
mod-tidy:
$(Q)$(GO_CMD) mod tidy
$(Q)./scripts/go-mod-tidy
go-generate:
$(Q)$(GO_CMD) generate ./...
#
# clean targets
#
clean-plugins:
$(Q)rm -f $(PLUGINS)
clean-cache:
$(Q)$(GO_CMD) clean -cache -testcache
#
# plugins build targets
#
.PHONY: build-protoc-gen-owners
build-protoc-gen-owners:
$(Q)echo "Building build/bin/protoc-gen-owners..."; \
$(GO_BUILD) -C tools/protoc-gen-owners -o $(abspath $(BIN_PATH)/protoc-gen-owners) $(GO_BUILD_FLAGS) .
.PHONY: build-protoc-gen-strip
build-protoc-gen-strip:
$(Q)echo "Building build/bin/protoc-gen-strip..."; \
$(GO_BUILD) -C tools/protoc-gen-strip -o $(abspath $(BIN_PATH)/protoc-gen-strip) $(GO_BUILD_FLAGS) .
$(BIN_PATH)/% build/bin/%: FORCE
$(Q)echo "Building $@..."; \
$(GO_BUILD) -C plugins/$* -o $(abspath $@) $(GO_BUILD_FLAGS) .
$(BIN_PATH)/wasm build/bin/wasm: FORCE
$(Q)echo "Building $@..."; \
mkdir -p $(BIN_PATH) && \
GOOS=wasip1 GOARCH=wasm $(GO_BUILD) -C plugins/wasm -o $(abspath $@) $(GO_BUILD_FLAGS) -buildmode=c-shared .
#
# test targets
#
test-gopkgs: go-generate ginkgo-tests test-ulimits test-rdt test-hook-injector test-writable-cgroups
SKIPPED_PKGS="ulimit-adjuster,device-injector,rdt,hook-injector,writable-cgroups"
ginkgo-tests:
$(Q)$(GINKGO) run \
--race \
--trace \
--cover \
--covermode atomic \
--output-dir $(COVERAGE_PATH) \
--junit-report junit.xml \
--coverprofile coverprofile \
--succinct \
--skip-package $(SKIPPED_PKGS) \
-r && \
$(GO_CMD) tool cover -html=$(COVERAGE_PATH)/coverprofile -o $(COVERAGE_PATH)/coverage.html
test-ulimits:
$(Q)cd ./plugins/ulimit-adjuster && $(GO_TEST) -v
test-device-injector:
$(Q)cd ./plugins/device-injector && $(GO_TEST) -v
test-rdt:
$(Q)cd ./plugins/rdt && $(GO_TEST) -v
test-hook-injector:
$(Q)cd ./plugins/hook-injector && $(GO_TEST) -v
test-writable-cgroups:
$(Q)cd ./plugins/writable-cgroups && $(GO_TEST) -v
codecov: SHELL := $(shell which bash)
codecov:
bash <(curl -s https://codecov.io/bash) -f $(COVERAGE_PATH)/coverprofile
#
# other validation targets
#
fmt format:
$(Q)$(GO_FMT) -s -d -e .
lint:
$(Q)$(GO_LINT) -set_exit_status ./...
vet:
$(Q)$(GO_VET) ./...
golangci-lint:
$(Q)$(GOLANG_CILINT) run
validate-repo-no-changes:
$(Q)test -z "$$(git status --short | tee /dev/stderr)" || { \
echo "Repository has changes."; \
echo "Please make sure to commit all changes, including generated files."; \
exit 1; \
}
#
# targets for installing dependencies
#
check-protoc:
$(Q)found_proto=$(shell $(PROTO_COMPILE) --version 2> /dev/null | awk '{print $$2}'); \
if [ "$$found_proto" != "$(PROTOBUF_VERSION)" ]; then \
echo "installing protoc version $(PROTOBUF_VERSION) (found: $$found_proto)"; \
make clean-protoc; \
make install-protoc; \
else \
echo "protoc version $$found_proto found."; \
fi
install-protoc install-protobuf:
$(Q)PROTOBUF_VERSION=$(PROTOBUF_VERSION) INSTALL_DIR=$(PROTOC_PATH) ./scripts/install-protobuf
clean-protoc:
$(Q)rm -rf $(PROTOC_PATH)
install-ttrpc-plugin:
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc
install-wasm-plugin:
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin
install-protoc-dependencies:
$(Q)GOBIN="$(PROTOC_PATH)/bin" $(GO_INSTALL) google.golang.org/protobuf/cmd/protoc-gen-go
install-ginkgo:
$(Q)$(GO_INSTALL) -mod=mod github.com/onsi/ginkgo/v2/ginkgo