Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
273 lines (228 loc) · 11.7 KB
/
Copy pathMakefile
File metadata and controls
273 lines (228 loc) · 11.7 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# force makefile to use bash instead of sh.
SHELL := /usr/bin/env bash
.PHONY: all
all: revad reva test-go lint gen-doc ## Build revad and reva, run the unit tests and the linter, generate the docs
HELP_COLORS = if [ -t 1 ] && [ -z "$$NO_COLOR" ]; then h=$$'\e[1;36m' n=$$'\e[1;32m' v=$$'\e[33m' r=$$'\e[0m'; fi
# help lists the targets that have a "## description", grouped under the
# titles of the section banners below.
.PHONY: help
help: ## Show this help
@$(HELP_COLORS); \
awk -v h="$$h" -v n="$$n" -v r="$$r" -v test="$(TEST)" ' \
BEGIN { printf "%sUsage:%s\n make <target>\n\n%sTargets:%s\n", h, r, h, r } \
/^####/ { banner = 1; next } \
banner && /^# / { section = substr($$0, 3) } \
{ banner = 0 } \
match($$0, /^[a-zA-Z0-9_$$().-]+:/) && index($$0, " ## ") { \
name = substr($$0, 1, RLENGTH - 1); sub(/\$$\(TEST\)/, test, name); \
if (section != "") { printf "\n%s%s:%s\n", h, section, r; section = "" } \
printf " %s%-26s%s %s\n", n, name, r, substr($$0, index($$0, " ## ") + 4) \
} \
END { printf "\nUse \"make help-<target>\" for more information about a target.\n" }' $(MAKEFILE_LIST)
# help-<target> prints the description of a target, the comment block
# right above it and its prerequisites. Write the details and the variables
# of a target in that comment block.
help-%:
@$(HELP_COLORS); \
awk -v h="$$h" -v n="$$n" -v v="$$v" -v r="$$r" -v test="$(TEST)" -v want="$*" ' \
/^#/ && !/^####/ { line = $$0; sub(/^# ?/, "", line); block[nb++] = line; next } \
/^\.PHONY:/ { next } \
match($$0, /^[a-zA-Z0-9_$$().-]+:/) && index($$0, " ## ") { \
name = substr($$0, 1, RLENGTH - 1); sub(/\$$\(TEST\)/, test, name); \
if (index(" " name " ", " " want " ")) { \
d = index($$0, " ## "); deps = substr($$0, RLENGTH + 1, d - RLENGTH - 1); gsub(/^ +| +$$/, "", deps); \
printf "%s%s%s: %s\n", n, want, r, substr($$0, d + 4); \
if (nb) printf "\n"; \
for (i = 0; i < nb; i++) { \
l = block[i]; \
if (l ~ /^[A-Z][A-Za-z ()]*:$$/) l = h l r; \
else if (match(l, /^ [A-Z_]+/)) l = " " v substr(l, 3, RLENGTH - 2) r substr(l, RLENGTH + 1); \
print l \
} \
if (deps != "") printf "\n%sDepends on:%s %s\n", h, r, deps; \
found = 1; exit \
} \
} \
{ nb = 0 } \
END { if (!found) { print "No help for \"" want "\". Run \"make help\" to list the targets." > "/dev/stderr"; exit 1 } }' $(MAKEFILE_LIST)
################################################################################
# Toolchain
################################################################################
TOOLCHAIN ?= $(CURDIR)/toolchain
CALENS ?= $(TOOLCHAIN)/calens
CALENS_DIR := $(shell mktemp -d)
$(CALENS):
@mkdir -p $(@D)
CALENS_DIR=`mktemp -d`
git clone --depth 1 --branch v0.2.0 -c advice.detachedHead=false https://github.com/restic/calens.git $(CALENS_DIR)
cd $(CALENS_DIR) && GOBIN=$(@D) go install
rm -rf $(CALENS_DIR)
################################################################################
# Build
################################################################################
GIT_COMMIT ?= `git rev-parse --short HEAD`
VERSION ?= `git describe --always`
GO_VERSION ?= `go version | awk '{print $$3}'`
BUILD_DATE = `date +%FT%T%z`
BUILD_FLAGS = -X github.com/cs3org/reva/v3/cmd/revad.gitCommit=$(GIT_COMMIT) -X github.com/cs3org/reva/v3/cmd/revad.version=$(VERSION) -X github.com/cs3org/reva/v3/cmd/revad.goVersion=$(GO_VERSION) -X github.com/cs3org/reva/v3/cmd/revad.buildDate=$(BUILD_DATE)
.PHONY: revad
revad: ## Build revad
go build -ldflags "$(BUILD_FLAGS)" -o ./cmd/revad/revad ./cmd/revad/main
.PHONY: revad-static
revad-static: ## Build a static revad
go build -tags "sqlite_omit_load_extension" -ldflags "-extldflags=-static $(BUILD_FLAGS)" -o ./cmd/revad/revad ./cmd/revad/main
.PHONY: revad-static-musl
revad-static-musl: ## Build a static revad with musl
@command -v musl-gcc >/dev/null 2>&1 || { echo "Error: musl-gcc not found. Install with: sudo apt install musl-tools"; exit 1; }
CGO_ENABLED=1 CC=musl-gcc go build -tags "sqlite_omit_load_extension" -ldflags "-extldflags '-static' $(BUILD_FLAGS)" -o ./cmd/revad/revad ./cmd/revad/main
.PHONY: gaia
gaia: ## Install the gaia build tool
go install github.com/cs3org/gaia@latest
# Build cmd/revad/revad with gaia, with the plugins of
# github.com/cernbox/reva-plugins and this checkout of reva.
.PHONY: cernbox-revad
cernbox-revad: gaia ## Build revad with the CERNBox plugins
gaia build --with github.com/cernbox/reva-plugins --with github.com/cs3org/reva/v3=$(shell pwd) --debug -o ./cmd/revad/revad
# Like cernbox-revad, but take the plugins from your checkout in
# ../reva-plugins instead of the published module.
.PHONY: cernbox-revad-local
cernbox-revad-local: gaia ## Build revad with the CERNBox plugins from ../reva-plugins
gaia build --with github.com/cernbox/reva-plugins=$(shell pwd)/../reva-plugins --with github.com/cs3org/reva/v3=$(shell pwd) --debug -o ./cmd/revad/revad
# Like cernbox-revad, with the ceph build tag. It writes
# cmd/revad/revad-ceph (and cmd/revad/revad, from cernbox-revad).
.PHONY: cernbox-revad-ceph
cernbox-revad-ceph: cernbox-revad ## Build revad with the CERNBox plugins and Ceph
gaia build --tags ceph --with github.com/cernbox/reva-plugins --with github.com/cs3org/reva/v3=$(shell pwd) --debug -o ./cmd/revad/revad-ceph
# Like cernbox-revad-local, with the ceph build tag. It writes
# cmd/revad/revad-ceph.
.PHONY: cernbox-revad-ceph-local
cernbox-revad-ceph-local: gaia ## Build revad with the CERNBox plugins from ../reva-plugins and Ceph
gaia build --tags ceph --with github.com/cernbox/reva-plugins=$(shell pwd)/../reva-plugins --with github.com/cs3org/reva/v3=$(shell pwd) --debug -o ./cmd/revad/revad-ceph
.PHONY: revad-ceph
revad-ceph: ## Build revad with Ceph
go build -ldflags "$(BUILD_FLAGS)" -tags ceph -o ./cmd/revad/revad ./cmd/revad/main
.PHONY: reva
reva: ## Build the reva CLI
go build -ldflags "-extldflags=-static -X main.gitCommit=$(GIT_COMMIT) -X main.version=$(VERSION) -X main.goVersion=$(GO_VERSION) -X main.buildDate=$(BUILD_DATE)" -o ./cmd/reva/reva ./cmd/reva
# Regenerate the reva-owned Admin API (pkg/admin/adminpb) and control channel
# (pkg/control/controlpb) stubs from their protos. Needs protoc plus protoc-gen-go and
# protoc-gen-go-grpc on PATH.
.PHONY: protobuf
protobuf: ## Regenerate the admin and control channel gRPC stubs
protoc --proto_path=pkg/admin/proto \
--go_out=. --go_opt=module=github.com/cs3org/reva/v3 \
--go-grpc_out=. --go-grpc_opt=module=github.com/cs3org/reva/v3 \
pkg/admin/proto/admin.proto
protoc --proto_path=pkg/control/proto \
--go_out=. --go_opt=module=github.com/cs3org/reva/v3 \
--go-grpc_out=. --go-grpc_opt=module=github.com/cs3org/reva/v3 \
pkg/control/proto/control.proto
.PHONY: docker-reva
docker-reva: ## Build the reva docker image
docker build -f docker/Dockerfile.reva -t reva --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .
.PHONY: docker-revad
docker-revad: ## Build the revad docker image
docker build -f docker/Dockerfile.revad -t revad --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .
.PHONY: docker-revad-ceph
docker-revad-ceph: ## Build the revad docker image with Ceph
docker build -f docker/Dockerfile.revad-ceph -t revad-ceph --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .
.PHONY: docker-revad-eos
docker-revad-eos: ## Build the revad docker image for EOS
docker build -f docker/Dockerfile.revad-eos -t revad-eos --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .
.PHONY: docker-eos-full-tests
docker-eos-full-tests: ## Build the EOS docker image for the litmus tests
docker build -f tests/docker/eos-storage/Dockerfile -t eos-full tests/docker/eos-storage
################################################################################
# Test
################################################################################
TEST = litmus-1 litmus-2
export REVAD_IMAGE ?= revad-eos
export EOS_FULL_IMAGE ?= eos-full
export PARTS ?= 1
export PART ?= 1
# Build the EOS and revad images, then run the litmus WebDAV tests with
# docker compose (tests/docker/docker-compose.yml).
#
# Variables:
# EOS_FULL_IMAGE the EOS image to test against (default eos-full)
.PHONY: $(TEST)
$(TEST): docker-eos-full-tests docker-revad-eos ## Run the litmus WebDAV tests in docker
docker compose -f ./tests/docker/docker-compose.yml up --force-recreate --always-recreate-deps --build --abort-on-container-exit -V --remove-orphans --exit-code-from $@ $@
# Run the unit tests with the race detector. The tests in tests/integration
# are left out: use test-integration for them.
#
# Variables:
# COVER_PROFILE write a coverage profile to this file
.PHONY: test-go
test-go: ## Run the unit tests
go test $$([[ -z "$(COVER_PROFILE)" ]] && echo "" || echo "-coverprofile=$(COVER_PROFILE)") -race $$(go list ./... | grep -v /tests/integration)
# Build revad, then run the gRPC integration tests in tests/integration.
# They need a Redis and a MySQL server.
#
# Variables (environment):
# REDIS_ADDRESS address of Redis, for example localhost:6379
# SQL_USERNAME MySQL user
# SQL_PASSWORD MySQL password
# SQL_ADDRESS address of MySQL, for example localhost:3306
# SQL_DBNAME MySQL database
.PHONY: test-integration
test-integration: revad ## Run the integration tests (needs Redis and MySQL)
go test -race ./tests/integration/...
# Run the reva CLI tests in tests/integration/reva-cli with judo
# (npm install -g @intuit/judo). Build reva first and start revad with
# tests/integration/reva-cli/config/revad-localfs.toml: see
# .github/workflows/test-reva-cli.yml for the setup.
.PHONY: test-reva-cli
test-reva-cli: ## Run the reva CLI tests with judo (needs a running revad)
@if ! command -v judo >/dev/null 2>&1; then \
echo "Error: judo not found. Install with: npm install -g @intuit/judo"; \
exit 1; \
fi
judo tests/integration/reva-cli/file-operations.yaml
judo tests/integration/reva-cli/versions-recycle.yaml
judo tests/integration/reva-cli/grants.yaml
# Check that the unreleased changelog has an entry that links the pull
# request. CI runs it on every pull request.
#
# Variables:
# PR number of the pull request (required)
.PHONY: check-changelog
check-changelog: $(CALENS) ## Check the changelog entry of PR=<number>
ifndef PR
$(error PR is not defined)
else
$(CALENS) | sed -n '/^Changelog for reva unreleased (UNRELEASED)/,/^Details/p' | \
grep -E '^ \* [[:alpha:]]{3} #$(PR): '
endif
.PHONY: lint
lint: ## Run go vet
go vet ./...
################################################################################
# Release
################################################################################
.PHONY: gen-doc
gen-doc: ## Generate the config reference of the docs
go run tools/generate-documentation/main.go
dist: gen-doc ## Build the release artifacts
go run tools/create-artifacts/main.go -version $(VERSION) -commit $(GIT_COMMIT) -goversion $(GO_VERSION)
# Run make all, move changelog/unreleased into changelog/<version>_<date>,
# regenerate CHANGELOG.md and write VERSION and RELEASE_DATE. Then commit
# and tag the release.
#
# Variables:
# NEWVER the version to release, for example 3.14.1 (required)
release: gen-doc ## Prepare a release (NEWVER=3.x.y)
go run tools/prepare-release/main.go -version $(NEWVER) -commit -tag
################################################################################
# Clean
################################################################################
.PHONY: toolchain-clean
toolchain-clean: ## Remove the downloaded tools
rm -rf $(TOOLCHAIN)
.PHONY: docker-clean
docker-clean: ## Remove the docker test containers and images
docker compose -f ./tests/docker/docker-compose.yml down --rmi local -v --remove-orphans
.PHONY: clean
clean: toolchain-clean docker-clean ## Remove the build and test outputs
rm -rf dist
rm -rf tmp