-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
222 lines (163 loc) · 5.39 KB
/
Makefile
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
##
## Config
##
GO ?= go
GOPATH ?= $(HOME)/go
GO_TAGS ?= -tags ""
GO_TEST_OPTS ?= -test.timeout=300s -race -cover -coverprofile=coverage.txt -covermode=atomic $(GO_TAGS)
GO_TEST_PATH ?= ./...
GO_TEST_ENV ?=
CI ?= false
BUILD_DATE ?= `date +%s`
VCS_REF ?= `git rev-parse --short HEAD`
VERSION ?= `go run github.com/mdomke/git-semver/v5`
LDFLAGS ?= -ldflags="-X berty.tech/weshnet/internal/bertyversion.VcsRef=$(VCS_REF) -X berty.tech/weshnet/internal/bertyversion.Version=$(VERSION)"
# @FIXME(gfanton): on macOS Monterey (12.0.x) we currently need to set the
# environment variable `MallocNanoZone` to 0 to avoid a SIGABRT or SIGSEGV
# see https://github.com/golang/go/issues/49138
MACOS_VERSION=$(shell defaults read /System/Library/CoreServices/SystemVersion.plist 'ProductVersion' 2>/dev/null | sed 's/\.[0-9]$$//')
ifeq ($(MACOS_VERSION),12.0)
GO_TEST_ENV := MallocNanoZone=0 $(GO_TEST_ENV)
endif
ifeq ($(MACOS_VERSION),12.1)
GO_TEST_ENV := MallocNanoZone=0 $(GO_TEST_ENV)
endif
##
## General rules
##
all: help
.PHONY: all
help:
@echo "Available make commands:"
@cat Makefile | grep '^[a-z]' | grep -v '=' | cut -d: -f1 | sort | sed 's/^/ /'
.PHONY: help
test: unittest lint tidy
.PHONY: test
unittest: go.unittest
.PHONY: unittest
generate: pb.generate docs.generate
.PHONY: generate
regenerate: gen.clean docs.clean generate docs.generate
.PHONY: regenerate
clean: gen.clean docs.clean
rm -rf out/
.PHONY: clean
re: clean generate
.PHONY: re
tidy: go.tidy
.PHONY: tidy
lint: go.lint
.PHONY: lint
lint.fix: go.fmt
.PHONY: lint.fix
##
## Other rules
##
check-program = $(foreach exec,$(1),$(if $(shell PATH="$(PATH)" which $(exec)),,$(error "No $(exec) in PATH")))
go.tidy: pb.generate
$(call check-program, $(GO))
GO111MODULE=on $(GO) mod tidy
.PHONY: go.tidy
go.lint: pb.generate
$(call check-program, golangci-lint)
golangci-lint run --timeout=5m $(if $(filter $(CI), false), --verbose) ./...
.PHONY: go.lint
go.unittest: pb.generate
$(call check-program, $(GO))
$(GO_TEST_ENV) GO111MODULE=on $(GO) test $(GO_TEST_OPTS) $(GO_TEST_PATH)
.PHONY: go.unittest
go.flappy-tests: pb.generate
TEST_STABILITY=flappy go run moul.io/testman test -v -test.v -timeout=600s -retry=10 -run ^TestFlappy ./
TEST_STABILITY=flappy go run moul.io/testman test -v -test.v -timeout=600s -retry=10 -run ^TestScenario_ ./
TEST_STABILITY=flappy go run moul.io/testman test -v -test.v -timeout=600s -retry=10 -run ^TestFlappy ./pkg/tinder
# FIXME: run on other packages too
.PHONY: go.flappy-tests
go.broken-tests: pb.generate
TEST_STABILITY=broken go run moul.io/testman test -continue-on-error -timeout=1200s -test.timeout=60s -retry=5 -run ^TestScenario_ ./
.PHONY: go.broken-tests
print-%:
@echo $* = $($*)
minimum_go_minor_version = 14
validate-go-version:
@if [ ! "x`$(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1`" = "x1" ]; then \
echo "error: Golang version should be \"1.x\". Please use 1.$(minimum_go_minor_version) or more recent."; \
exit 1; \
fi
@if [ `$(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2` -lt $(minimum_go_minor_version) ]; then \
echo "error: Golang version is not supported. Please use 1.$(minimum_go_minor_version) or more recent."; \
exit 1; \
fi
.PHONY: validate-go-version
##
## Code gen
##
protos_src := $(wildcard ../api/*.proto) $(wildcard ../api/go-internal/*.proto)
gen_src := $(protos_src) Makefile
gen_sum := gen.sum
protoc_opts := -I ../api:`go list -m -mod=mod -f {{.Dir}} github.com/grpc-ecosystem/grpc-gateway`/third_party/googleapis:`go list -m -mod=mod -f {{.Dir}} github.com/gogo/protobuf`:/protobuf
pb.generate: gen.sum validate-go-version
$(gen_sum): $(gen_src)
$(call check-program, shasum docker $(GO))
@shasum $(gen_src) | sort -k 2 > $(gen_sum).tmp
@diff -q $(gen_sum).tmp $(gen_sum) || ( \
uid=`id -u`; \
set -xe; \
$(GO) mod download; \
docker run \
--user="$$uid" \
--volume="`go env GOPATH`/pkg/mod:/go/pkg/mod" \
--volume="$(PWD):/go/src/berty.tech/weshnet" \
--workdir="/go/src/berty.tech/weshnet" \
--entrypoint="sh" \
--rm \
bertytech/buf:5 \
-xec 'make generate_local'; \
$(MAKE) tidy \
)
.PHONY: pb.generate
generate_local:
go version
$(call check-program, shasum buf)
buf generate api/go-internal;
buf generate api/protocol;
buf generate --template buf.gen.tag.yaml api/go-internal;
buf generate --template buf.gen.tag.yaml api/protocol;
$(MAKE) go.fmt
shasum $(gen_src) | sort -k 2 > $(gen_sum).tmp
mv $(gen_sum).tmp $(gen_sum)
.PHONY: generate_local
go.fmt:
go run github.com/daixiang0/gci write . \
--skip-generated -s 'standard,default,prefix(berty.tech)'
go run mvdan.cc/gofumpt -w .
.PHONY: go.fmt
pkger.generate:
$(GO) run github.com/markbates/pkger/cmd/pkger -o go/pkg/assets/
.PHONY: pkger.generate
gen.clean:
rm -f gen.sum $(wildcard */*/*.pb.go) $(wildcard */*/*pb_test.go) $(wildcard */*/*pb.gw.go)
.PHONY: gen.clean
pb.push:
buf push api/protocol
##
## Docs gen
##
docs.generate:
cd docs; $(MAKE) generate
.PHONY: docs.generate
docs.clean:
cd docs; $(MAKE) clean
.PHONY: docs.generate
asdf.install_plugins:
$(call check-program, asdf)
@echo "Installing asdf plugins..."
@set -e; \
for PLUGIN in $$(cut -d' ' -f1 .tool-versions | grep "^[^\#]"); do \
asdf plugin add $$PLUGIN || [ $$?==2 ] || exit 1; \
done
.PHONY: asdf.install_plugins
asdf.install_tools: asdf.install_plugins
$(call check-program, asdf)
@echo "Installing asdf tools..."
@asdf install
.PHONY: asdf.install_tools