-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
340 lines (266 loc) ยท 12.2 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
SHELL=/bin/bash
CHECKMARK := "\033[0;32m\xE2\x9C\x94\xE2\x83\x9E\033[0m"
package-name := phylogenetic-component-graph
cabal-depends := $(package-name).cabal cabal.project
bin-dir := ./bin
cfg-dir := ./config
hie-dir := ./.hie
tmp-dir := ./.temp
diff-log := $(tmp-dir)/diffs.log
formatter := $(bin-dir)/stylish-haskell
formatter-flags := --config $(cfg-dir)/.stylish-haskell.yaml
linter-flags := --hint=$(cfg-dir)/.hlint.yaml
lower-bound-file := $(cfg-dir)/lower-bounds.project
stan-exe := $(bin-dir)/stan
stan-flags := --config-file=$(cfg-dir)/.stan.toml --hiedir=$(hie-dir)
weeder-exe := $(bin-dir)/weeder
weeder-flags := --config $(cfg-dir)/weeder.dhall --hie-directory $(hie-dir)
code-dirs := app bench test $(shell find lib -maxdepth 1 -type d -name "*" | tail -n +2 | tr '\n' ' ')
code-files := $(shell find $(code-dirs) -type f -name "*.hs" | tr '\n' ' ')
################################################################################
### Target aliases for easy CLI use
################################################################################
# Clean up and build everything; default build target
all: cabal-clean cabal-setup cabal-deploy
build: prof
clean: cabal-clean clean-up-latex cleanup-log-files cleanup-junk-file
# Rebuilds with profiling
prof: cabal-quick-prof
lint: format-code spelling-check hlint-check documentation-check static-analysis-check dead-code-check
################################################################################
### Reusable cabal build definitions
################################################################################
with-compiler-flags =
ifdef ghc
with-compiler-flags := --with-compiler=ghc-$(ghc) --with-hc-pkg=ghc-pkg-$(ghc)
else
with-compiler-flags := --with-compiler=ghc
endif
cabal-fast-prof = --ghc-options="-O0" --enable-profiling --profiling-detail=all-functions --ghc-options="-O0 -fprof-cafs -rtsopts=all"
cabal-haddock-flags = --enable-documentation --haddock-all --haddock-hyperlink-source --haddock-internal
cabal-install-flags = --installdir=$(bin-dir) --overwrite-policy=always
cabal-total-targets = --enable-benchmarks --enable-tests
cabal-suffix = 2>&1 | grep -v -f $(cfg-dir)/.ignored-warnings
# Actions to perform before building dependencies and project
# Seperating the "pre-deploy" from "deploy" allows for CI caching the results
# of the pre-deployment configuration.
cabal-setup: $(cabal-depends)
cabal update
cabal clean
cabal configure $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) $(cabal-suffix)
cabal freeze $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) $(cabal-suffix)
# Actions for building all binaries, benchmarks, and test-suites
cabal-build: $(cabal-depends)
cabal build $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) --only-dependencies $(cabal-suffix)
cabal build $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) $(cabal-suffix)
# Actions for building all binaries, benchmarks, and test-suites
cabal-deploy: cabal-build make-bin-dir
cabal install $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-install-flags) $(cabal-suffix)
cabal-clean: cleanup-cabal-default cleanup-cabal-build-artifacts cleanup-HIE-files
# Builds with no extra generated features and no optimizations
cabal-quick-prof: make-bin-dir $(cabal-depends)
cabal build $(cabal-fast-prof) $(cabal-total-targets) --only-dependencies $(cabal-suffix)
cabal build $(cabal-fast-prof) $(cabal-total-targets) $(cabal-suffix)
cabal install $(cabal-fast-prof) $(cabal-install-flags) $(cabal-suffix)
################################################################################
### CI definitions
################################################################################
# Check that the project builds with the specified lower bounds
lower-bounds-check: $(lower-bound-file) lower-bounds-check-setup lower-bounds-check-deploy
lower-bounds-check-setup: cabal-haddock-flags += --project-file=$(lower-bound-file)
lower-bounds-check-setup: $(lower-bound-file) cabal-setup
lower-bounds-check-deploy: cabal-haddock-flags += --project-file=$(lower-bound-file)
lower-bounds-check-deploy: $(lower-bound-file) cabal-deploy
# Check that all unit tests pass
run-unit-tests: unit-tests-setup unit-tests-verification
unit-tests-setup: cabal.project cabal-setup
unit-tests-verification: cabal.project
cabal build --enable-tests $(with-compiler-flags)
cabal test
# Check that all example input files parse
run-file-tests: file-tests-setup file-tests-verification
file-tests-setup: cabal.project cabal-setup
file-tests-verification:
cabal run file-tests
# Check that all example input files parse
run-integration-tests: integration-tests-setup integration-tests-verification
integration-tests-setup: cabal.project cabal-setup
integration-tests-verification:
cabal install exe:pcg --overwrite-policy=always --installdir=./bin
cabal run integration-tests
# Check that the project builds with the specified lower bounds
compilation-check: compilation-check-setup compilation-check-deploy
compilation-check-setup: cabal-haddock-flags += $(with-compiler-flags)
compilation-check-setup: cabal.project cabal-setup
compilation-check-deploy: cabal-haddock-flags += $(with-compiler-flags)
compilation-check-deploy: cabal.project cabal-deploy
################################################################################
### Code hygeine
################################################################################
dead-code-check: dead-code-check-setup dead-code-check-deploy
dead-code-check-setup: install-weeder
$(weeder-exe) --version
@$(MAKE) --no-print-directory hie-setup
dead-code-check-deploy: hie-deploy
$(weeder-exe) $(weeder-flags)
hlint-check:
@curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s $(code-dirs) -j $(linter-flags)
format-code:
@echo -n " โ Formatting code..."
@$(MAKE) --no-print-directory run-stylish-haskell in-place=true
@echo -e "\r\033[K" $(CHECKMARK) " Formatting code complete!"
formatting-check:
@echo -n "Checking code for required formatting"
@$(MAKE) --no-print-directory run-stylish-haskell
@if find . -empty -wholename $(diff-log) | grep "^" &> /dev/null; \
then \
echo -e "\r\033[KCode is properly formatted!"; \
else \
echo -e "\nFormatting required!\nFix by running the following:\n\n> make format-code\n" \
rm -f $(diff-log) \
sleep 1 \
exit 1; \
fi
run-stylish-haskell: install-stylish-haskell make-tmp-dir
ifdef in-place
@$(eval formatter-flags += -i)
endif
@$(eval temp-file := $(tmp-dir)/styled.temp)
@rm -f $(diff-log)
@touch $(diff-log)
@echo $(code-files) | tr ' ' '\n' | while read fname; do \
$(formatter) $(formatter-flags) "$$fname" > $(temp-file); \
diff "$$fname" $(temp-file) >> $(diff-log) || true; \
done
@rm -f $(temp-file) || true
spelling-check: install-codespell
@$(eval spell-check-flags := -I $(cfg-dir)/.ignored-words -x $(cfg-dir)/.excluded-lines)
ifdef fix-spelling
@$(eval spell-check-flags += --write-changes)
endif
@echo "Checking code for misspellings"
@codespell $(spell-check-flags) $(code-files)
static-analysis-check: static-analysis-check-setup static-analysis-check-deploy
static-analysis-check-setup: install-stan
$(stan-exe) --version
@$(MAKE) --no-print-directory hie-setup
static-analysis-check-deploy: hie-deploy make-tmp-dir
@$(eval stan-log := $(tmp-dir)/.stan.log)
@$(eval observations := $(tmp-dir)/.stan.observations.log)
@rm -f $(stan-log)
@rm -f $(observations)
@touch $(stan-log)
$(stan-exe) $(stan-flags) | tee $(stan-log)
@grep ' ID: ' $(stan-log) > $(observations) || true
@rm -f $(stan-log)
@find . -empty -wholename $(observations) | grep "^" &> /dev/null || ( \
echo -e "\nAnti-pattern observations found!\nCorrect the following $$(wc -l $(observations) | cut -d " " -f1) observations:\n" && \
echo -n " โ" && printf 'โ%.0s' {1..52} && echo "โ" && \
cat $(observations) && \
rm -f $(observations) && \
echo -en " โ" && printf 'โ%.0s' {1..52} && echo "โ\n" && \
sleep 1 && \
exit 1 \
)
documentation-check: documentation-check-setup documentation-check-deploy
documentation-check-setup: cabal-setup
documentation-check-deploy: make-tmp-dir
@$(eval docs-log := $(tmp-dir)/.haddock.log)
@$(eval missing-docs := $(tmp-dir)/.missing.docs.log)
@rm -f $(docs-log)
@rm -f $(missing-docs)
cabal build $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) --only-dependencies $(cabal-suffix)
cabal haddock $(with-compiler-flags) $(cabal-haddock-flags) $(cabal-total-targets) $(cabal-suffix) | tee $(docs-log)
@grep '^[[:space:]]*[[:digit:] ][[:digit:]]% (' $(docs-log) > $(missing-docs) || true
@rm -f $(docs-log)
@(find . -empty -wholename $(missing-docs) | grep "^" &> /dev/null) || ( \
echo $(count) && \
echo -e "\nMissing documetation!\nThe following $$(wc -l $(missing-docs) | cut -d ' ' -f1) files have incomplete documetation coverage:\n" && \
cat $(missing-docs) && \
echo "" && \
sleep 1 && \
exit 1 \
)
hie-setup: compilation-check-setup cleanup-HIE-files
hie-deploy: compilation-check-deploy
ls -ahlr $(hie-dir)
################################################################################
### Cleaning
################################################################################
cleanup-cabal-default:
@echo -n " โ Cleaning Cabal..."
@cabal clean
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned Cabal defaults"
cleanup-cabal-build-artifacts:
@echo -n " โ Cleaning extra Cabal build artifacts..."
@rm -f lower-bounds.project?*
@rm -f cabal.project?*
@rm -f cabal.project.local~?*
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned Cabal extras"
cleanup-HIE-files:
@echo -n " โ Cleaning HIE files..."
@rm -fR $(hie-dir)
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned HIE files"
cleanup-junk-file:
@echo -n " โ Cleaning code directories of temporary files..."
@for dir in $(code-dirs); do \
find $$dir -type f -name '*.o' -delete; \
find $$dir -type f -name '*.hi' -delete; \
find $$dir -type f -name '*.*~' -delete; \
find $$dir -type f -name '#*.*' -delete; \
find $$dir -type f -name '*#.*#' -delete; \
find $$dir -type f -name 'log.err' -delete; \
find $$dir -type f -name 'log.out' -delete; \
find $$dir -type f -name '*dump\-hi*' -delete; \
find $$dir -type f -name '*dump\-simpl*' -delete; \
find $$dir -type f -name '*.data.?*' -delete; \
find $$dir -type f -name '*.dot.?*' -delete; \
find $$dir -type f -name '*.xml.?*' -delete; \
done
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned temporary files"
cleanup-log-files:
@echo -n " โ Cleaning log files..."
@rm -fR $(tmp-dir)
@rm -fR .*.log*
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned log files"
clean-up-latex:
@echo -n " โ Cleaning documentation directory of LaTeX artifacts..."
@rm -f *.bbl
@rm -f *.blg
@rm -f *.synctex.gz
@rm -f *.toc
@echo -e "\r\033[K" $(CHECKMARK) " Cleaned LaTeX artifacts"
################################################################################
### Miscellaneous
################################################################################
code-lines:
loc --exclude 'css|html|js|makefile|md|tex|sh|yaml' --sort lines $(code-dirs)
install-codespell:
@which codespell &> /dev/null || (\
echo "Downloading codespell" && \
pip3 install codespell \
)
install-stan: make-bin-dir
@ls $(formatter) &> /dev/null || (\
echo "Downloading stan..." && \
cabal update && \
cabal install stan $(with-compiler-flags) $(cabal-install-flags) \
)
install-stylish-haskell: make-bin-dir
@ls $(formatter) &> /dev/null || (\
echo "Downloading stylish-haskell" && \
cabal update && \
cabal install stylish-haskell $(with-compiler-flags) $(cabal-install-flags) \
)
install-weeder: make-bin-dir
@ls $(weeder-exe) &> /dev/null || (\
echo "Downloading weeder..." && \
cabal update && \
cabal install weeder $(with-compiler-flags) $(cabal-install-flags) \
--allow-newer --constraints="weeder >= 2.0" \
)
make-bin-dir:
@ls | grep $(bin-dir) || mkdir -p $(bin-dir)
make-tmp-dir:
@ls | grep $(tmp-dir) || mkdir -p $(tmp-dir)
.PHONY: all build clean lint prof test