-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
182 lines (142 loc) · 6.25 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
# The plutus-pab commands, contracts and hoogle environment
# are made availible by the nix shell defined in shell.nix.
# In most cases you should execute Make after entering nix-shell.
.PHONY: hoogle pab_servers_all pab_servers_all pab_db clean_db \
build test accept_pirs watch ghci readme_contents \
format lint requires_nix_shell
usage:
@echo "usage: make <command> [OPTIONS]"
@echo
@echo "Available options:"
@echo " WALLET -- Specify wallet for command (1 or 2)"
@echo " FLAGS -- Additional options passed to --ghc-options"
@echo " NIXOS -- Add stack flags --no-nix and --system-ghc to work around stack issues on NixOS"
@echo
@echo "Available commands:"
@echo " hoogle -- Start local hoogle"
@echo " pab_servers_all -- Start the pab servers"
@echo " pab_servers_client -- Start the pab web client"
@echo " pab_db -- Generate pab db"
@echo " clean_db -- Delete pab db"
@echo " build -- Run cabal v2-build"
@echo " watch -- Track files: shrinker.cabal, src/* and run 'make build' on change"
@echo " test -- Run cabal v2-test"
@echo " accept_pirs -- Accept new PIR changes"
@echo " ghci -- Run cabal v2-repl shrinker"
@echo " format -- Apply source code formatting with fourmolu"
@echo " format_check -- Check source code formatting without making changes"
@echo " nixfmt -- Apply nix formatting with nixfmt"
@echo " nixfmt_check -- Check nix files for format errors"
@echo " lint -- Check the sources with hlint"
@echo " ci -- Execute CI action"
@echo " readme_contents -- Add table of contents to README"
@echo " update_plutus -- Update plutus version with niv"
@echo " clear_build -- Deletes the build files for this specific project"
@echo " diagrams -- Build SVG diagrams from graphviz dot diagrams"
@echo " diagram_pngs -- Build PNG images from graphviz dot diagrams"
@echo " clean_diagrams -- Delete results from diagrams, diagram_pngs"
PAB1 := plutus-pab --config=${PAB_CONFIG_PATH}/pab_env1.yaml
PAB2 := plutus-pab --config=${PAB_CONFIG_PATH}/pab_env2.yaml
WALLET ?= 1
ifeq ($(WALLET), 1)
PAB := $(PAB1)
PAB_DB_PATH := ${PAB_DB1_PATH}
else
PAB := $(PAB2)
PAB_DB_PATH := ${PAB_DB2_PATH}
endif
# Need to use --no-nix and --system-ghc from inside nix-shell
# on NixOS since stack doesn't support nixos, and ghc8103 isnt in any nixpkgs version
# maybe we could support this via stack's nix integration using a separate stack_shell.nix
ifdef NIXOS
STACK_FLAGS = --no-nix --system-ghc
endif
hoogle: requires_nix_shell
hoogle server --local --port=8070 > /dev/null &
pab_servers_all: | requires_nix_shell pab_db install_contracts
@echo "Starting plutus servers."
$(PAB) all-servers
pab_servers_client: | requires_nix_shell pab_db install_contracts
@echo "Starting plutus client servers"
$(PAB) client-services
pab_db: requires_nix_shell
@echo "Generating pab db at ${PAB_DB_PATH}"
$(PAB) migrate ${PAB_DB_PATH}
clean_db: requires_nix_shell
@echo "Cleaning db file at ${PAB_DB_PATH}"
rm $(PAB_DB_PATH)
ifdef FLAGS
GHC_FLAGS = --ghc-options "$(FLAGS)"
endif
build: requires_nix_shell
cabal v2-build $(GHC_FLAGS)
watch: requires_nix_shell
while sleep 1; do find src shrinker.cabal | entr -cd make build; done
test: requires_nix_shell
cabal v2-test
accept_pirs: requires_nix_shell
stack build --test $(STACK_FLAGS) $(GHC_FLAGS) --ta '-p MarketAction --accept'
ghci: requires_nix_shell
cabal v2-repl $(GHC_FLAGS) shrinker
# Source dirs to run fourmolu on
FORMAT_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.hs' )
# Extensions we need to tell fourmolu about
FORMAT_EXTENSIONS := -o -XTemplateHaskell -o -XTypeApplications -o -XImportQualifiedPost -o -XPatternSynonyms -o -fplugin=RecordDotPreprocessor
# Run fourmolu formatter
format: requires_nix_shell
fourmolu --mode inplace --check-idempotence $(FORMAT_EXTENSIONS) $(FORMAT_SOURCES)
# Check formatting (without making changes)
format_check: requires_nix_shell
fourmolu --mode check --check-idempotence $(FORMAT_EXTENSIONS) $(FORMAT_SOURCES)
# Execute CI
ci:
nix-build ./nix/ci.nix
# Nix files to format
NIX_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.nix' )
nixfmt: requires_nix_shell
nixfmt $(NIX_SOURCES)
nixfmt_check: requires_nix_shell
nixfmt --check $(NIX_SOURCES)
# Check with hlint, currently I couldn't get --refactor to work
lint: requires_nix_shell
hlint $(FORMAT_SOURCES)
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 nix-shell"
@ [ "$(IN_NIX_SHELL)" ] || (echo " run 'nix-shell --pure' first" && false)
PLUTUS_BRANCH = $(shell jq '.plutus.branch' ./nix/sources.json )
PLUTUS_REPO = $(shell jq '.plutus.owner + "/" + .plutus.repo' ./nix/sources.json )
PLUTUS_REV = $(shell jq '.plutus.rev' ./nix/sources.json )
PLUTUS_SHA256 = $(shell jq '.plutus.sha256' ./nix/sources.json )
update_plutus:
@echo "Updating plutus version to latest commit at $(PLUTUS_REPO) $(PLUTUS_BRANCH)"
niv update plutus
@echo "Latest commit: $(PLUTUS_REV)"
@echo "Sha256: $(PLUTUS_SHA256)"
@echo "Make sure to update the plutus rev in stack.yaml with:"
@echo " commit: $(PLUTUS_REV)"
@echo "This may require further resolution of dependency versions."
################################################################################
# Utils
build_path = dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/shrinker-0.1
clear_build:
@[ ! -e $(build_path) ] || rm -rf $(build_path)
################################################################################
# Docs
DIAGRAMS := docs/eutxo-design
DOT_INPUTS := $(wildcard $(DIAGRAMS)/*.dot )
DOT_SVGS := $(patsubst %.dot, %.svg, $(DOT_INPUTS))
DOT_PNGS := $(patsubst %.dot, %.png, $(DOT_INPUTS))
diagram_pngs: $(DOT_PNGS)
diagrams: $(DOT_SVGS)
clean_diagrams:
rm $(DOT_SVGS)
rm $(DOT_PNGS)
# This doesn't work for now, some issue with resvg not loading fonts
%.png: %.svg
convert $< $@
%.svg: %.dot
dot -Tsvg $< -o $@