forked from MinaProtocol/mina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
281 lines (221 loc) · 9.02 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
########################################
## Docker Wrapper
## Hint: export USEDOCKER=TRUE
GITHASH = $(shell git rev-parse --short=8 HEAD)
GITLONGHASH = $(shell git rev-parse HEAD)
MYUID = $(shell id -u)
DOCKERNAME = codabuilder-$(MYUID)
# Unique signature of kademlia code tree
KADEMLIA_SIG = $(shell cd src/app/kademlia-haskell ; find . -type f -print0 | xargs -0 sha1sum | sort | sha1sum | cut -f 1 -d ' ')
ifeq ($(DUNE_PROFILE),)
DUNE_PROFILE := dev
endif
ifeq ($(USEDOCKER),TRUE)
$(info INFO Using Docker Named $(DOCKERNAME))
WRAP = docker exec -it $(DOCKERNAME)
WRAPSRC = docker exec --workdir /home/opam/app/src -it $(DOCKERNAME)
else
$(info INFO Not using Docker)
WRAP =
endif
########################################
## Coverage directory
COVERAGE_DIR=_coverage
########################################
## Git hooks
git_hooks: $(wildcard scripts/git_hooks/*)
@case "$$(file .git | cut -d: -f2)" in \
' ASCII text') \
echo 'refusing to install git hooks in worktree' \
break;; \
' directory') \
for f in $^; do \
[ ! -f ".git/hooks/$$(basename $$f)" ] && ln -s ../../$$f .git/hooks/; \
done; \
break;; \
*) \
echo 'unhandled case when installing git hooks' \
exit 1 \
break;; \
esac
########################################
## Code
all: clean codabuilder containerstart build
clean:
$(info Removing previous build artifacts)
@rm -rf src/_build
@rm -rf src/$(COVERAGE_DIR)
kademlia:
@# FIXME: Bash wrap here is awkward but required to get nix-env
bash -c "source ~/.profile && cd src/app/kademlia-haskell && nix-build release2.nix"
# Alias
dht: kademlia
build: git_hooks
$(info Starting Build)
ulimit -s 65536
cd src ; $(WRAPSRC) env CODA_COMMIT_SHA1=$(GITLONGHASH) dune build --profile=$(DUNE_PROFILE)
$(info Build complete)
dev: docker container build
########################################
## Lint
reformat: git_hooks
cd src; $(WRAPSRC) dune exec --profile=$(DUNE_PROFILE) app/reformat/reformat.exe -- -path .
check-format:
cd src; $(WRAPSRC) dune exec --profile=$(DUNE_PROFILE) app/reformat/reformat.exe -- -path . -check
########################################
## Merlin fixup for docker builds
merlin-fixup:
ifeq ($(USEDOCKER),TRUE)
@echo "Fixing up .merlin files for Docker build"
@./scripts/merlin-fixup.sh
else
@echo "Not building in Docker, .merlin files unchanged"
endif
########################################
## Containers and container management
# push steps require auth on docker hub
docker-toolchain:
@if git diff-index --quiet HEAD ; then \
docker build --no-cache --file dockerfiles/Dockerfile-toolchain --tag codaprotocol/coda:toolchain-$(GITLONGHASH) . && \
docker tag codaprotocol/coda:toolchain-$(GITLONGHASH) codaprotocol/coda:toolchain-latest && \
docker push codaprotocol/coda:toolchain-$(GITLONGHASH) && \
docker push codaprotocol/coda:toolchain-latest ;\
else \
echo "Repo has uncommited changes, commit first to set hash." ;\
fi
docker-toolchain-rust:
@if git diff-index --quiet HEAD ; then \
docker build --file dockerfiles/Dockerfile-toolchain-rust --tag codaprotocol/coda:toolchain-rust-$(GITLONGHASH) . && \
docker tag codaprotocol/coda:toolchain-rust-$(GITLONGHASH) codaprotocol/coda:toolchain-rust-latest && \
docker push codaprotocol/coda:toolchain-rust-$(GITLONGHASH) && \
docker push codaprotocol/coda:toolchain-rust-latest ;\
else \
echo "Repo has uncommited changes, commit first to set hash." ;\
fi
# All in one step to build toolchain and binary for kademlia
docker-toolchain-haskell:
@echo "Building codaprotocol/coda:toolchain-haskell-$(KADEMLIA_SIG)" ;\
docker build --file dockerfiles/Dockerfile-toolchain-haskell --tag codaprotocol/coda:toolchain-haskell-$(KADEMLIA_SIG) . ;\
echo 'Extracting deb package' ;\
mkdir -p src/_build ;\
docker run --rm --entrypoint cat codaprotocol/coda:toolchain-haskell-$(KADEMLIA_SIG) /src/coda-kademlia.deb > src/_build/coda-kademlia.deb
toolchains: docker-toolchain docker-toolchain-rust docker-toolchain-haskell
update-deps:
./scripts/update-toolchain-references.sh $(GITLONGHASH)
cd .circleci; python2 render.py > config.yml
# Local 'codabuilder' docker image (based off docker-toolchain)
codabuilder: git_hooks
docker build --file dockerfiles/Dockerfile --tag codabuilder .
# Restarts codabuilder
containerstart: git_hooks
@./scripts/container.sh restart
########################################
## Artifacts
deb:
$(WRAP) ./scripts/rebuild-deb.sh
@mkdir -p /tmp/artifacts
@cp src/_build/coda.deb /tmp/artifacts/.
# deb-s3 https://github.com/krobertson/deb-s3
DEBS3 = deb-s3 upload --s3-region=us-west-2 --bucket packages.o1test.net --preserve-versions --cache-control=120
publish_kademlia_deb:
@if [ $(AWS_ACCESS_KEY_ID) ] ; then \
if [ "$(CIRCLE_BRANCH)" = "master" ] ; then \
$(DEBS3) --codename stable --component main src/_build/coda-kademlia.deb ; \
else \
$(DEBS3) --codename unstable --component main src/_build/coda-kademlia.deb ; \
fi ; \
else \
echo "WARNING: AWS_ACCESS_KEY_ID not set, deb-s3 not run" ; \
fi
publish_deb:
@if [ $(AWS_ACCESS_KEY_ID) ] ; then \
if [ "$(CIRCLE_BRANCH)" = "master" ] ; then \
$(DEBS3) --codename stable --component main src/_build/coda.deb ; \
else \
$(DEBS3) --codename unstable --component main src/_build/coda.deb ; \
fi ; \
else \
echo "WARNING: AWS_ACCESS_KEY_ID not set, deb-s3 commands not run" ; \
fi
publish_debs: publish_deb publish_kademlia_deb
provingkeys:
@if [ "$(CIRCLE_BRANCH)" = "master" ] ; then \
$(WRAP) tar -cvjf src/_build/coda_cache_dir_$(GITHASH).tar.bz2 /tmp/coda_cache_dir ; \
mkdir -p /tmp/artifacts ; \
cp src/_build/coda_cache_dir*.tar.bz2 /tmp/artifacts/. ; \
else \
echo "Skipping because not on master" ; \
fi
genesiskeys:
@mkdir -p /tmp/artifacts
@cp src/_build/default/lib/coda_base/sample_keypairs.ml /tmp/artifacts/.
codaslim:
@# FIXME: Could not reference .deb file in the sub-dir in the docker build
@cp src/_build/coda.deb .
@./scripts/rebuild-docker.sh codaslim dockerfiles/Dockerfile-codaslim
@rm coda.deb
########################################
## Tests
render-circleci:
cd .circleci; python2 render.py > config.yml
check-render-circleci:
cd .circleci; ./check_render.sh
test:
$(WRAP) make test-all
test-all: | test-runtest \
test-sigs \
test-stakes
test-runtest: SHELL := /bin/bash
test-runtest:
source scripts/test_all.sh ; cd src ; run_unit_tests
test-sigs: SHELL := /bin/bash
test-sigs:
source scripts/test_all.sh ; cd src ; run_all_sig_integration_tests
test-stakes: SHELL := /bin/bash
test-stakes:
source scripts/test_all.sh ; cd src ; run_all_stake_integration_tests
test-withsnark: SHELL := /bin/bash
test-withsnark:
source scripts/test_all.sh ; cd src; CODA_PROPOSAL_INTERVAL=30000 WITH_SNARKS=true DUNE_PROFILE=test_snark run_integration_test full-test
web:
./scripts/web.sh
########################################
# Coverage testing and output
test-coverage: SHELL := /bin/bash
test-coverage:
source scripts/test_all.sh ; cd src ; run_unit_tests_with_coverage
# we don't depend on test-coverage, which forces a run of all unit tests
coverage-html:
ifeq ($(shell find src/_build/default -name bisect\*.out),"")
echo "No coverage output; run make test-coverage"
else
cd src && bisect-ppx-report -I _build/default/ -html $(COVERAGE_DIR) `find . -name bisect\*.out`
endif
coverage-text:
ifeq ($(shell find src/_build/default -name bisect\*.out),"")
echo "No coverage output; run make test-coverage"
else
cd src && bisect-ppx-report -I _build/default/ -text $(COVERAGE_DIR)/coverage.txt `find . -name bisect\*.out`
endif
coverage-coveralls:
ifeq ($(shell find src/_build/default -name bisect\*.out),"")
echo "No coverage output; run make test-coverage"
else
cd src && bisect-ppx-report -I _build/default/ -coveralls $(COVERAGE_DIR)/coveralls.json `find . -name bisect\*.out`
endif
########################################
# Diagrams for documentation
docs/res/%.dot.png: docs/res/%.dot
dot -Tpng $< > $@
docs/res/%.tex.pdf: docs/res/%.tex
cd docs/res && pdflatex $(notdir $<)
cp $(@:.tex.pdf=.pdf) $@
docs/res/%.tex.png: docs/res/%.tex.pdf
convert -density 600x600 $< -quality 90 -resize 1080x1080 $@
doc_diagrams: $(addsuffix .png,$(wildcard docs/res/*.tex) $(wildcard docs/res/*.dot))
########################################
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
# HACK: cat Makefile | egrep '^\w.*' | sed 's/:/ /' | awk '{print $1}' | grep -v myprocs | sort | xargs
.PHONY: all base-docker base-googlecloud base-minikube build check-format ci-base-docker clean codaslim containerstart deb dev codabuilder kademlia coda-docker coda-googlecloud coda-minikube ocaml407-googlecloud pull-ocaml407-googlecloud reformat test test-all test-coda-block-production-sig test-coda-block-production-stake test-codapeers-sig test-codapeers-stake test-full-sig test-full-stake test-runtest test-transaction-snark-profiler-sig test-transaction-snark-profiler-stake update-deps render-circleci check-render-circleci docker-toolchain-rust toolchains doc_diagrams