forked from input-output-hk/xsy-liqwid-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (110 loc) · 4.85 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
SHELL := env bash
.PHONY: hoogle build dev watch test ghci ghci-test format format_check lint \
refactor readme_contents hasktags haddock precommit ci
usage:
@echo "usage: make <command> [OPTIONS]"
@echo
@echo "Available options:"
@echo " FLAGS -- Additional options passed to --ghc-options"
@echo
@echo "Available commands:"
@echo " hoogle -- Start local hoogle"
@echo " build -- Run cabal v2-build"
@echo " dev -- Run cabal v2-build -f development"
@echo " ci -- Run the full CI derivation"
@echo " watch [COMMAND] -- Track files and run 'make [COMMAND]' on change"
@echo " test -- Run cabal v2-test"
@echo " ghci -- Run cabal v2-repl plutarch-benchmark"
@echo " format -- Apply source code formatting with fourmolu"
@echo " format_check -- Check source code formatting without making changes"
@echo " lint -- Check hlint suggestions"
@echo " refactor -- Automatically apply hlint refactors, with prompt"
@echo " readme_contents -- Add table of contents to README"
@echo " hasktags -- Build ctags/etags files"
@echo " haddock -- Build haddock docs"
ifdef FLAGS
GHC_FLAGS = --ghc-options "$(FLAGS)"
endif
PROJECT_SOURCES := $(shell find -name '*.hs' -not -path './dist-*/*' -not -path './haddock/*')
hoogle: requires_nix_shell haddock
-killall -q hoogle
hoogle generate --local=haddock --database=plutarch-benchmark.hoo
hoogle server --local --database=plutarch-benchmark.hoo -p 8070 >> /dev/null && echo $! > ./.hoogle.pid &
hoogle server --local -p 8080 >> /dev/null && echo $! > ./.hoogle.pid &
# use this when the project has build errors. hoogle seems to currently not index the project anyway..
hoogle_deps: requires_nix_shell
-killall -q hoogle
hoogle generate --local --database=plutarch-benchmark.hoo
hoogle server --local --database=plutarch-benchmark.hoo -p 8070 >> /dev/null && echo $! > ./.hoogle.pid &
hoogle server --local -p 8080 >> /dev/null && echo $! > ./.hoogle.pid &
build: requires_nix_shell
cabal v2-build $(GHC_FLAGS)
dev: requires_nix_shell
cabal v2-build $(GHC_FLAGS) -f development
ci:
nix build '.#check.x86_64-linux'
# TODO: This should share common find/fd commands with HASKELL_SOURCES and CABAL_SOURCES
watch: requires_nix_shell
while sleep 1; \
do \
find $(HASKELL_SOURCES) $(NIX_SOURCES) $(CABAL_SOURCES) | \
entr -cd make $(filter-out $@,$(MAKECMDGOALS)); \
done
test: requires_nix_shell
cabal v2-test
ghci: requires_nix_shell
cabal v2-repl $(GHC_FLAGS) plutarch-benchmark
# TODO: Should this use fd like the others? fd gets ignore patterns out of .gitignore.
HASKELL_SOURCES := $(shell find -name '*.hs' -not -path './dist-*/*' -not -path './haddock/*')
NIX_SOURCES := $(shell fd -enix)
CABAL_SOURCES := $(shell fd -ecabal)
# Extensions we need to tell fourmolu about
FORMAT_EXTENSIONS := -o -XQualifiedDo -o -XTemplateHaskell -o -XTypeApplications -o -XPatternSynonyms -o -XOverloadedRecordDot
# Run fourmolu formatter
format: requires_nix_shell
fourmolu --mode inplace --check-idempotence $(FORMAT_EXTENSIONS) $(HASKELL_SOURCES)
nixpkgs-fmt $(NIX_SOURCES)
cabal-fmt -i $(CABAL_SOURCES)
# Check formatting (without making changes)
format_check:
fourmolu --mode check --check-idempotence $(FORMAT_EXTENSIONS) $(HASKELL_SOURCES)
nixpkgs-fmt --check $(NIX_SOURCES)
cabal-fmt -c $(CABAL_SOURCES)
NIX_SHELL = nix develop
HLS_SHELL = $(NIX_SHELL) -c nix-shell -p bashInteractive haskell-language-server
shell:
$(NIX_SHELL)
hls_shell:
$(HLS_SHELL)
code:
$(HLS_SHELL) --run "code ."
# Extentions we need to tell Hlint about
HLINT_EXTS := -XQuasiQuotes
# Check with hlint
lint: requires_nix_shell
hlint $(HLINT_EXTS) $(PROJECT_SOURCES)
# Apply automatic hlint refactors, with prompt
refactor: requires_nix_shell
for f in $(HASKELL_SOURCES); do \
hlint $(HLINT_EXTS) --refactor --refactor-options="-i -s" "$$f";\
done
readme_contents:
echo "this command is not nix-ified, you may receive an error from npx"
npx markdown-toc ./README.md --no-firsth1
# Target to use as dependency to fail if not inside nix-shell
requires_nix_shell:
@ [ "$(IN_NIX_SHELL)" ] || echo "The $(MAKECMDGOALS) target must be run from inside a nix shell"
@ [ "$(IN_NIX_SHELL)" ] || (echo " run 'nix develop' first" && false)
################################################################################
# Utils
build_path = dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/plutarch-benchmark-0.1
clear_build:
@[ ! -e $(build_path) ] || rm -rf $(build_path)
################################################################################
# Docs
hasktags:
hasktags -b ./src ./test ./testlib
haddock:
cabal haddock --haddock-html --haddock-hoogle --builddir=haddock
clean_haddock:
rm -rf haddock