forked from mlabs-haskell/plutus-simple-model
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
131 lines (100 loc) · 4.95 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
# 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.
SHELL := /usr/bin/env bash
.PHONY: hoogle build test watch ghci readme_contents \
format lint refactor requires_nix_shell
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 " watch -- Track files and run 'make build' on change"
@echo " test -- Run cabal v2-test"
@echo " costing -- Run cost-estimation benchmark"
@echo " ci -- Run ci locally"
@echo " coverage -- Generate a coverage report of the tests"
@echo " ghci -- Run cabal v2-repl on src files"
@echo " examples -- Run cabal v2-repl on example files"
@echo " format -- Apply source code formatting with fourmolu"
@echo " format_check -- Check source code formatting without making changes"
@echo " cabalfmt -- Apply cabal formatting with cabal-fmt"
@echo " cabalfmt_check -- Check cabal files for formatting errors 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 " refactor -- Automatically apply hlint refactors, with prompt
@echo " readme_contents -- Add table of contents to README"
@echo " update_plutus -- Update plutus version with niv"
hoogle: requires_nix_shell
hoogle server --local --port=8070 > /dev/null &
STACK_EXE_PATH = $(shell stack $(STACK_FLAGS) path --local-install-root)/bin
ifdef FLAGS
GHC_FLAGS = --ghc-options "$(FLAGS)"
endif
ci:
nix-build ./nix/ci.nix
build: requires_nix_shell plutus-simple-model.cabal
cabal v2-build $(GHC_FLAGS)
watch: requires_nix_shell plutus-simple-model.cabal
while sleep 1; do find plutus-simple-model.cabal src test | entr -cd make build; done
test: requires_nix_shell plutus-simple-model.cabal
cabal new-test --test-show-details=always --test-options="--color always"
ghci: requires_nix_shell plutus-simple-model.cabal
cabal v2-repl $(GHC_FLAGS) plutus-simple-model
examples: requires_nix_shell plutus-simple-model.cabal
cabal v2-repl $(GHC_FLAGS) plutus-simple-model-examples
coverage: plutus-simple-model.cabal
nix-build --arg doCoverage true -A projectCoverageReport
# Source dirs to run fourmolu on
FORMAT_SOURCES := $(shell find -name '*.hs' -not -path './dist-*/*')
# 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)
CABAL_SOURCES := $(shell git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.cabal' )
cabalfmt: requires_nix_shell
cabal-fmt --inplace $(CABAL_SOURCES)
cabalfmt_check: requires_nix_shell
cabal-fmt --check $(CABAL_SOURCES)
# 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)
# Apply automatic hlint refactors, with prompt
refactor: requires_nix_shell
for src in $(FORMAT_SOURCES) ; do hlint --refactor --refactor-options='-i -s' $$src ; 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:
@ [ -v IN_NIX_SHELL ] || echo "The $(MAKECMDGOALS) target must be run from inside nix-shell"
@ [ -v 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 cabal.project with:"
@echo " commit: $(PLUTUS_REV)"
@echo "This may require further resolution of dependency versions."
run:
nix develop