forked from algorand/go-algorand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
316 lines (236 loc) · 10.8 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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
export GOPATH := $(shell go env GOPATH)
GOPATH1 := $(firstword $(subst :, ,$(GOPATH)))
export GO111MODULE := on
export GOPROXY := https://gocenter.io
UNAME := $(shell uname)
SRCPATH := $(shell pwd)
ARCH := $(shell ./scripts/archtype.sh)
OS_TYPE := $(shell ./scripts/ostype.sh)
# If build number already set, use it - to ensure same build number across multiple platforms being built
BUILDNUMBER ?= $(shell ./scripts/compute_build_number.sh)
COMMITHASH := $(shell ./scripts/compute_build_commit.sh)
BUILDBRANCH ?= $(shell ./scripts/compute_branch.sh)
BUILDCHANNEL ?= $(shell ./scripts/compute_branch_channel.sh $(BUILDBRANCH))
DEFAULTNETWORK ?= $(shell ./scripts/compute_branch_network.sh $(BUILDBRANCH))
DEFAULT_DEADLOCK ?= $(shell ./scripts/compute_branch_deadlock_default.sh $(BUILDBRANCH))
GOTAGSLIST := sqlite_unlock_notify sqlite_omit_load_extension
ifeq ($(UNAME), Linux)
EXTLDFLAGS := -static-libstdc++ -static-libgcc
ifeq ($(ARCH), amd64)
# the following predicate is abit misleading; it tests if we're not in centos.
ifeq (,$(wildcard /etc/centos-release))
EXTLDFLAGS += -static
endif
GOTAGSLIST += osusergo netgo static_build
GOBUILDMODE := -buildmode pie
endif
ifeq ($(ARCH), arm)
ifneq ("$(wildcard /etc/alpine-release)","")
EXTLDFLAGS += -static
GOTAGSLIST += osusergo netgo static_build
GOBUILDMODE := -buildmode pie
endif
endif
endif
GOTAGS := --tags "$(GOTAGSLIST)"
GOTRIMPATH := $(shell go help build | grep -q .-trimpath && echo -trimpath)
GOLDFLAGS_BASE := -X github.com/algorand/go-algorand/config.BuildNumber=$(BUILDNUMBER) \
-X github.com/algorand/go-algorand/config.CommitHash=$(COMMITHASH) \
-X github.com/algorand/go-algorand/config.Branch=$(BUILDBRANCH) \
-X github.com/algorand/go-algorand/config.DefaultDeadlock=$(DEFAULT_DEADLOCK) \
-extldflags \"$(EXTLDFLAGS)\"
GOLDFLAGS := $(GOLDFLAGS_BASE) \
-X github.com/algorand/go-algorand/config.Channel=$(BUILDCHANNEL)
UNIT_TEST_SOURCES := $(sort $(shell GO111MODULE=off go list ./... | grep -v /go-algorand/test/ ))
ALGOD_API_PACKAGES := $(sort $(shell GO111MODULE=off cd daemon/algod/api; go list ./... ))
MSGP_GENERATE := ./protocol ./crypto ./data/basics ./data/transactions ./data/committee ./data/bookkeeping ./data/hashable ./auction ./agreement ./rpcs ./node
default: build
# tools
fmt:
go fmt ./...
fix: build
$(GOPATH1)/bin/algofix */
fixcheck: build
$(GOPATH1)/bin/algofix -error */
lint: deps
$(GOPATH1)/bin/golint ./...
vet:
go vet ./...
check_license:
./scripts/check_license.sh
check_shell:
find . -type f -name "*.sh" -exec shellcheck {} +
sanity: vet fix lint fmt check_license
cover:
go test $(GOTAGS) -coverprofile=cover.out $(UNIT_TEST_SOURCES)
prof:
cd node && go test $(GOTAGS) -cpuprofile=cpu.out -memprofile=mem.out -mutexprofile=mutex.out
generate: deps
PATH=$(GOPATH1)/bin:$$PATH go generate ./...
msgp: $(patsubst %,%/msgp_gen.go,$(MSGP_GENERATE))
%/msgp_gen.go: deps ALWAYS
$(GOPATH1)/bin/msgp -file ./$(@D) -o $@ -warnmask github.com/algorand/go-algorand
ALWAYS:
# build our fork of libsodium, placing artifacts into crypto/lib/ and crypto/include/
crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a:
mkdir -p crypto/copies/$(OS_TYPE)/$(ARCH)
cp -R crypto/libsodium-fork crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork
cd crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork && \
./autogen.sh --prefix $(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH) && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH)" && \
$(MAKE) && \
$(MAKE) install
deps:
./scripts/check_deps.sh
# artifacts
# Regenerate algod swagger spec files
ALGOD_API_SWAGGER_SPEC := daemon/algod/api/swagger.json
ALGOD_API_FILES := $(shell find daemon/algod/api/server/common daemon/algod/api/server/v1 daemon/algod/api/spec/v1 -type f) \
daemon/algod/api/server/router.go
ALGOD_API_SWAGGER_INJECT := daemon/algod/api/server/lib/bundledSpecInject.go
# Note that swagger.json requires the go-swagger dep.
$(ALGOD_API_SWAGGER_SPEC): $(ALGOD_API_FILES) crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a
cd daemon/algod/api && \
PATH=$(GOPATH1)/bin:$$PATH \
go generate ./...
$(ALGOD_API_SWAGGER_INJECT): $(ALGOD_API_SWAGGER_SPEC) $(ALGOD_API_SWAGGER_SPEC).validated
./daemon/algod/api/server/lib/bundle_swagger_json.sh
# Regenerate kmd swagger spec files
KMD_API_SWAGGER_SPEC := daemon/kmd/api/swagger.json
KMD_API_FILES := $(shell find daemon/kmd/api/ -type f | grep -v $(KMD_API_SWAGGER_SPEC))
KMD_API_SWAGGER_WRAPPER := kmdSwaggerWrappers.go
KMD_API_SWAGGER_INJECT := daemon/kmd/lib/kmdapi/bundledSpecInject.go
$(KMD_API_SWAGGER_SPEC): $(KMD_API_FILES) crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a
cd daemon/kmd/lib/kmdapi && \
python genSwaggerWrappers.py $(KMD_API_SWAGGER_WRAPPER)
cd daemon/kmd && \
PATH=$(GOPATH1)/bin:$$PATH \
go generate ./...
rm daemon/kmd/lib/kmdapi/$(KMD_API_SWAGGER_WRAPPER)
%/swagger.json.validated: %/swagger.json
@problem=$$(cat $< | jq -c '.definitions[].properties | select(. != null) | with_entries(select(.value.type=="array" and .value.items.format=="uint8")) | select(. != {}) | keys[]'); \
if [ "$${problem}" != "" ]; then \
echo "detected uint8 array in $<:\n$${problem}\nDid you mean to use \"type: string, format: byte\"?"; \
echo "you will need to fix these swagger problems to allow build to proceed"; \
exit 1; \
else \
touch $@; \
fi
$(KMD_API_SWAGGER_INJECT): $(KMD_API_SWAGGER_SPEC) $(KMD_API_SWAGGER_SPEC).validated
./daemon/kmd/lib/kmdapi/bundle_swagger_json.sh
# develop
build: buildsrc gen
buildsrc: crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a node_exporter NONGO_BIN deps $(ALGOD_API_SWAGGER_INJECT) $(KMD_API_SWAGGER_INJECT)
go install $(GOTRIMPATH) $(GOTAGS) $(GOBUILDMODE) -ldflags="$(GOLDFLAGS)" ./...
SOURCES_RACE := github.com/algorand/go-algorand/cmd/kmd
## Build binaries with the race detector enabled in them.
## This allows us to run e2e tests with race detection.
## We overwrite bin-race/kmd with a non -race version due to
## the incredible performance impact of -race on Scrypt.
build-race: build
@mkdir -p $(GOPATH1)/bin-race
GOBIN=$(GOPATH1)/bin-race go install $(GOTRIMPATH) $(GOTAGS) -race -ldflags="$(GOLDFLAGS)" ./...
GOBIN=$(GOPATH1)/bin-race go install $(GOTRIMPATH) $(GOTAGS) -ldflags="$(GOLDFLAGS)" $(SOURCES_RACE)
go vet ./...
NONGO_BIN_FILES=$(GOPATH1)/bin/find-nodes.sh $(GOPATH1)/bin/update.sh $(GOPATH1)/bin/COPYING $(GOPATH1)/bin/ddconfig.sh
NONGO_BIN: $(NONGO_BIN_FILES)
$(GOPATH1)/bin/find-nodes.sh: scripts/find-nodes.sh
$(GOPATH1)/bin/update.sh: cmd/updater/update.sh
$(GOPATH1)/bin/COPYING: COPYING
$(GOPATH1)/bin/ddconfig.sh: scripts/ddconfig.sh
$(GOPATH1)/bin/%:
cp -f $< $@
test: build
go test $(GOTAGS) -race $(UNIT_TEST_SOURCES) -timeout 3600s
ci-test: ci-build
ifeq ($(ARCH), amd64)
RACE=-race
else
RACE=
endif
for PACKAGE_DIRECTORY in $(UNIT_TEST_SOURCES) ; do \
go test $(GOTAGS) -timeout 2000s $(RACE) $$PACKAGE_DIRECTORY; \
done
fulltest: build-race
for PACKAGE_DIRECTORY in $(UNIT_TEST_SOURCES) ; do \
go test $(GOTAGS) -timeout 2000s -race $$PACKAGE_DIRECTORY; \
done
shorttest: build-race $(addprefix short_test_target_, $(UNIT_TEST_SOURCES))
$(addprefix short_test_target_, $(UNIT_TEST_SOURCES)): build
@go test $(GOTAGS) -short -timeout 2000s -race $(subst short_test_target_,,$@)
integration: build-race
./test/scripts/run_integration_tests.sh
ci-integration:
ifeq ($(ARCH), amd64)
export NODEBINDIR=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/bin && \
export PATH=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/bin:$$PATH && \
export PATH=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/test-utils:$$PATH && \
export SRCROOT=$(SRCPATH) && \
./test/scripts/e2e_go_tests.sh
else
export NODEBINDIR=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/bin && \
export PATH=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/bin:$$PATH && \
export PATH=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH)/dev/$(OS_TYPE)-$(ARCH)/test-utils:$$PATH && \
export SRCROOT=$(SRCPATH) && \
./test/scripts/e2e_go_tests.sh -norace
endif
testall: fulltest integration
# generated files we should make sure we clean
GENERATED_FILES := daemon/algod/api/bundledSpecInject.go \
daemon/algod/api/lib/bundledSpecInject.go \
daemon/kmd/lib/kmdapi/bundledSpecInject.go \
$(ALGOD_API_SWAGGER_SPEC) $(ALGOD_API_SWAGGER_SPEC).validated \
$(KMD_API_SWAGGER_SPEC) $(KMD_API_SWAGGER_SPEC).validated
clean:
go clean -i ./...
rm -f $(GOPATH1)/bin/node_exporter
rm -f $(GENERATED_FILES)
cd crypto/libsodium-fork && \
test ! -e Makefile || make clean
rm -rf crypto/lib
rm -rf crypto/libs
rm -rf crypto/copies
# clean without crypto
cleango:
go clean -i ./...
rm -f $(GOPATH1)/bin/node_exporter
rm -f $(GENERATED_FILES)
# assign the phony target node_exporter the dependency of the actual executable.
node_exporter: $(GOPATH1)/bin/node_exporter
# The recipe for making the node_exporter is by extracting it from the gzipped&tar file.
# The file is was taken from the S3 cloud and it traditionally stored at
# /travis-build-artifacts-us-ea-1.algorand.network/algorand/node_exporter/latest/node_exporter-stable-linux-x86_64.tar.gz
$(GOPATH1)/bin/node_exporter:
tar -xzvf installer/external/node_exporter-stable-$(shell ./scripts/ostype.sh)-$(shell uname -m | tr '[:upper:]' '[:lower:]').tar.gz -C $(GOPATH1)/bin
# deploy
deploy:
scripts/deploy_dev.sh
.PRECIOUS: gen/%/genesis.json
# devnet & testnet
NETWORKS = testnet devnet
gen/%/genesis.dump: gen/%/genesis.json
./scripts/dump_genesis.sh $< > $@
gen/%/genesis.json: gen/%.json gen/generate.go buildsrc
$(GOPATH1)/bin/genesis -q -n $(shell basename $(shell dirname $@)) -c $< -d $(subst .json,,$<)
gen: $(addsuffix gen, $(NETWORKS)) mainnetgen
$(addsuffix gen, $(NETWORKS)): %gen: gen/%/genesis.dump
# mainnet
gen/mainnet/genesis.dump: gen/mainnet/genesis.json
./scripts/dump_genesis.sh gen/mainnet/genesis.json > gen/mainnet/genesis.dump
mainnetgen: gen/mainnet/genesis.dump
gen/mainnet/genesis.json: gen/pregen/mainnet/genesis.csv buildsrc
mkdir -p gen/mainnet
cat gen/pregen/mainnet/genesis.csv | $(GOPATH1)/bin/incorporate -m gen/pregen/mainnet/metadata.json > gen/mainnet/genesis.json
capabilities: build
sudo setcap cap_ipc_lock+ep $(GOPATH1)/bin/kmd
dump: $(addprefix gen/,$(addsuffix /genesis.dump, $(NETWORKS)))
install: build
scripts/dev_install.sh -p $(GOPATH1)/bin
.PHONY: default fmt vet lint check_license check_shell sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install %gen gen NONGO_BIN
### TARGETS FOR CICD PROCESS
ci-deps:
scripts/configure_dev-deps.sh && \
scripts/check_deps.sh
ci-build: buildsrc gen
mkdir -p $(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH) && \
PKG_ROOT=$(SRCPATH)/tmp/node_pkgs/$(OS_TYPE)/$(ARCH) NO_BUILD=True VARIATIONS=$(OS_TYPE)/$(ARCH) scripts/build_packages.sh $(OS_TYPE)/$(ARCH)