forked from algorand/go-algorand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
279 lines (213 loc) · 9.51 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
GOPATH := $(shell go env GOPATH)
export GOPATH
UNAME := $(shell uname)
SRCPATH := $(GOPATH)/src/github.com/algorand/go-algorand
# If build number already set, use it - to ensure same build number across multiple platforms being built
BUILDNUMBER ?= $(shell GOPATH=$(GOPATH) ./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))
ifeq ($(UNAME), Linux)
EXTLDFLAGS := -static-libstdc++ -static-libgcc
endif
GOTAGS := --tags "sqlite_unlock_notify sqlite_omit_load_extension"
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)
SOURCES := $(shell cd $(SRCPATH) && \
go list ./... | grep -v /go-algorand/test/)
UNIT_TEST_SOURCES := $(sort $(shell cd $(SRCPATH) && go list ./... | grep -v /go-algorand/test/ | grep -v /go-algorand/vendor/ ))
E2E_TEST_SOURCES := $(shell cd $(SRCPATH)/test/e2e-go && go list ./...)
default: build
# tools
fmt:
cd $(SRCPATH) && \
go fmt `go list ./... | grep -v /vendor/`
fix: build
cd $(SRCPATH) && \
$(GOPATH)/bin/algofix `ls -d */ | grep -vw vendor`
fixcheck: build
cd $(SRCPATH) && \
$(GOPATH)/bin/algofix -error `ls -d */ | grep -vw vendor`
lint: deps
cd $(SRCPATH) && \
$(GOPATH)/bin/golint `go list ./... | grep -v /vendor/`
depensure:
cd $(SRCPATH) && \
$(GOPATH)/bin/dep ensure
vet:
cd $(SRCPATH) && \
go vet `go list ./... | grep -v /vendor/`
sanity: vet fix lint fmt
cover:
cd $(SRCPATH) && \
go test $(GOTAGS) -coverprofile=cover.out $(UNIT_TEST_SOURCES)
prof:
cd $(SRCPATH)/node && \
go test $(GOTAGS) -cpuprofile=cpu.out -memprofile=mem.out -mutexprofile=mutex.out
generate: deps
cd $(SRCPATH) && \
PATH=$(GOPATH)/bin:$$PATH \
go generate `go list ./... | grep -v /vendor/`
# build our fork of libsodium, placing artifacts into crypto/lib/ and crypto/include/
$(SRCPATH)/crypto/lib/libsodium.a:
cd $(SRCPATH)/crypto/libsodium-fork && \
./autogen.sh && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/" && \
$(MAKE) && \
$(MAKE) install
deps:
$(SRCPATH)/scripts/check_deps.sh
# artifacts
# Regenerate algod swagger spec files
ALGOD_API_SWAGGER_SPEC := $(SRCPATH)/daemon/algod/api/swagger.json
ALGOD_API_FILES := $(shell find $(SRCPATH)/daemon/algod/api/server/common -type f) \
$(shell find $(SRCPATH)/daemon/algod/api/server/v1 -type f) \
$(SRCPATH)/daemon/algod/api/server/router.go
ALGOD_API_SWAGGER_INJECT := $(SRCPATH)/daemon/algod/api/server/lib/bundledSpecInject.go
# Note that swagger.json requires the go-swagger dep.
$(ALGOD_API_SWAGGER_SPEC): $(ALGOD_API_FILES)
$(info "regenerating swagger.json due to changes in algod/api/server")
@cd $(SRCPATH)/daemon/algod/api && \
PATH=$(GOPATH)/bin:$$PATH \
go generate ./...
@{ \
echo "performing custom validation of swagger.json";\
algodProblem=$$(cat $(ALGOD_API_SWAGGER_SPEC) | jq -c '.definitions[].properties | select(. != null) | with_entries(select(.value.type=="array" and .value.items.format=="uint8")) | select(. != {}) | keys[]');\
if [ "$${algodProblem}" != "" ]; then\
echo "detected uint8 array in algod/swagger.json:$${algodProblem}. Did you mean to use format: binary?";\
echo "you will need to fix these swagger problems to allow build to proceed";\
exit 1;\
else\
echo "custom validation succeeded";\
fi;\
} \
$(ALGOD_API_SWAGGER_INJECT): $(ALGOD_API_SWAGGER_SPEC)
$(SRCPATH)/daemon/algod/api/server/lib/bundle_swagger_json.sh
# Regenerate kmd swagger spec files
KMD_API_SWAGGER_SPEC := $(SRCPATH)/daemon/kmd/api/swagger.json
KMD_API_DIRS := $(shell find $(SRCPATH)/daemon/kmd/api/ -type d)
KMD_API_FILES := $(shell find $(SRCPATH)/daemon/kmd/api/ -type f | grep -v $(KMD_API_SWAGGER_SPEC))
KMD_API_SWAGGER_WRAPPER := kmdSwaggerWrappers.go
KMD_API_SWAGGER_INJECT := $(SRCPATH)/daemon/kmd/lib/kmdapi/bundledSpecInject.go
# Note that swagger.json requires the go-swagger dep.
$(KMD_API_SWAGGER_SPEC): $(KMD_API_DIRS) $(KMD_API_FILES)
$(info "regenerating swagger.json due to changes in kmd")
@cd $(SRCPATH)/daemon/kmd/lib/kmdapi && \
python genSwaggerWrappers.py $(KMD_API_SWAGGER_WRAPPER) && \
cd $(SRCPATH)/daemon/kmd && \
PATH=$(GOPATH)/bin:$$PATH \
go generate ./... && \
rm $(SRCPATH)/daemon/kmd/lib/kmdapi/$(KMD_API_SWAGGER_WRAPPER)
@{ \
echo "performing custom validation of swagger.json";\
kmdProblem=$$(cat $(KMD_API_SWAGGER_SPEC) | jq -c '.definitions[].properties | select(. != null) | with_entries(select(.value.type=="array" and .value.items.format=="uint8")) | select(. != {}) | keys[]');\
if [ "$${kmdProblem}" != "" ]; then\
echo "detected uint8 array in kmd/swagger.json:$${kmdProblem}. Did you mean to use format: binary?";\
echo "you will need to fix these swagger problems to allow build to proceed";\
exit 1;\
else\
echo "custom validation succeeded";\
fi;\
} \
$(KMD_API_SWAGGER_INJECT): $(KMD_API_SWAGGER_SPEC)
$(SRCPATH)/daemon/kmd/lib/kmdapi/bundle_swagger_json.sh
# develop
build: buildsrc gen
buildsrc: $(SRCPATH)/crypto/lib/libsodium.a node_exporter NONGO_BIN deps $(ALGOD_API_SWAGGER_INJECT) $(KMD_API_SWAGGER_INJECT)
cd $(SRCPATH) && \
go install $(GOTAGS) -ldflags="$(GOLDFLAGS)" $(SOURCES)
cd $(SRCPATH) && \
go vet $(UNIT_TEST_SOURCES) $(E2E_TEST_SOURCES)
## Build binaries with the race detector enabled in them.
## This allows us to run e2e tests with race detection.
build-race: build
@mkdir -p $(GOPATH)/bin-race
cd $(SRCPATH) && \
GOBIN=$(GOPATH)/bin-race go install $(GOTAGS) -ldflags="$(GOLDFLAGS)" $(SOURCES)
NONGO_BIN_FILES=$(GOPATH)/bin/find-nodes.sh $(GOPATH)/bin/update.sh $(GOPATH)/bin/updatekey.json $(GOPATH)/bin/COPYING
NONGO_BIN: $(NONGO_BIN_FILES)
$(GOPATH)/bin/find-nodes.sh: scripts/find-nodes.sh
$(GOPATH)/bin/update.sh: cmd/updater/update.sh
$(GOPATH)/bin/updatekey.json: installer/updatekey.json
$(GOPATH)/bin/COPYING: COPYING
$(GOPATH)/bin/%:
cp -f $< $@
test: build
cd $(SRCPATH) && \
go test $(GOTAGS) -race $(UNIT_TEST_SOURCES)
fulltest: build-race
cd $(SRCPATH) && 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
@cd $(SRCPATH) && \
go test $(GOTAGS) -short -timeout 2000s -race $(subst short_test_target_,,$@)
integration: build-race
cd $(SRCPATH) && \
./test/scripts/run_integration_tests.sh
testall: fulltest integration
# generated files we should make sure we clean
GENERATED_FILES := $(SRCPATH)/daemon/algod/api/bundledSpecInject.go \
$(SRCPATH)/daemon/algod/api/lib/bundledSpecInject.go \
$(SRCPATH)/daemon/kmd/lib/kmdapi/bundledSpecInject.go
clean:
cd $(SRCPATH) && \
go clean -i ./...
rm -f $(GOPATH)/bin/node_exporter
rm -f $(GENERATED_FILES)
cd crypto/libsodium-fork && \
test ! -e Makefile || make clean
rm -rf $(SRCPATH)/crypto/lib
# clean without crypto
cleango:
cd $(SRCPATH) && \
go clean -i ./...
rm -f $(GOPATH)/bin/node_exporter
rm -f $(GENERATED_FILES)
# assign the phony target node_exporter the dependency of the actual executable.
node_exporter: $(GOPATH)/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
$(GOPATH)/bin/node_exporter:
cd $(GOPATH)/bin && \
tar -xzvf $(SRCPATH)/installer/external/node_exporter-stable-$(shell ./scripts/ostype.sh)-$(shell uname -m | tr '[:upper:]' '[:lower:]').tar.gz
# deploy
deploy:
cd $(SRCPATH) && \
scripts/deploy_dev.sh
.PRECIOUS: gen/%/genesis.json
# devnet & testnet
NETWORKS = testnet devnet
gen/%/genesis.dump: gen/%/genesis.json
cd $(SRCPATH) && \
./scripts/dump_genesis.sh $< > $@
gen/%/genesis.json: gen/%.json $(SRCPATH)/gen/generate.go
cd $(SRCPATH) && \
$(GOPATH)/bin/genesis -n $(shell basename $(shell dirname $@)) -c $< -d $(subst $(SRCPATH)/,,$(subst .json,,$<))
gen: $(addsuffix gen, $(NETWORKS)) mainnetgen
$(addsuffix gen, $(NETWORKS)): %gen: gen/%/genesis.dump
# mainnet
$(SRCPATH)/gen/mainnet/genesis.dump: $(SRCPATH)/gen/mainnet/genesis.json
cd $(SRCPATH) && \
./scripts/dump_genesis.sh gen/mainnet/genesis.json > gen/mainnet/genesis.dump
mainnetgen: $(SRCPATH)/gen/mainnet/genesis.dump
$(SRCPATH)/gen/mainnet/genesis.json: $(SRCPATH)/gen/pregen/mainnet/genesis.csv buildsrc
cd $(SRCPATH) && \
mkdir -p gen/mainnet && \
cat $(SRCPATH)/gen/pregen/mainnet/genesis.csv | $(GOPATH)/bin/incorporate -m $(SRCPATH)/gen/pregen/mainnet/metadata.json > $(SRCPATH)/gen/mainnet/genesis.json
capabilities: build
sudo setcap cap_ipc_lock+ep ${GOPATH}/bin/kmd
dump: $(addprefix gen/,$(addsuffix /genesis.dump, $(NETWORKS)))
install: build
cd $(SRCPATH) && \
scripts/dev_install.sh -p ${GOPATH}/bin
.PHONY: default fmt vet lint sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install %gen gen NONGO_BIN