-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
153 lines (125 loc) · 5.24 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
.PHONY: usage
usage:
@echo "usage: make <command>"
@echo
@echo "Available commands:"
@echo ""
# Code format
@echo " format_lint -- Formats .hs, .cabal, .nix files and auto-refactors code"
@echo " format -- Formats .hs, .cabal, .nix files"
@echo " format_check -- Check formatting of .hs, .cabal, .nix files"
@echo " format_haskell -- Formats .hs files"
@echo " format_check_haskell -- Check formatting of .hs files"
@echo " format_nix -- Formats .nix files"
@echo " format_check_nix -- Check formatting of .nix files"
@echo " format_cabal -- Formats .cabal files"
@echo " format_check_cabal -- Check formatting of .cabal files"
@echo " lint -- Auto-refactors code"
@echo " lint_haskell -- Auto-refactors code"
@echo " lint_haskell_check -- Run code linting"
@echo ""
# Build
@echo " build_all -- Build all"
@echo ""
# Test
@echo ""
# Check Typos
@echo " typos_check -- Check typos"
@echo " typos_fix -- Fix typos"
@echo ""
# Doc
@echo " build_doc -- Build haddock documentation"
@echo ""
# Doc
@echo " build_doc -- Build haddock documentation"
@echo " lint_markdown_check -- Check markdownlint suggestions"
@echo " lint_markdown -- Apply markdownlint suggestions"
@echo ""
################################################################################
# Code
# Leave the cabal build directory and the legacy code submodule alone
FIND_EXCLUDE_PATH := -not -path '*/dist-*/*'
FIND_HASKELL_SOURCES := find -name '*.hs' $(FIND_EXCLUDE_PATH)
FIND_NIX_SOURCES := find -name '*.nix' $(FIND_EXCLUDE_PATH)
FIND_CABAL_SOURCES := find -name '*.cabal' $(FIND_EXCLUDE_PATH)
FIND_MARKDOWN_SOURCES := find -name '*.md' $(FIND_EXCLUDE_PATH)
# Runs as command on all results of the `find` call at one.
# e.g.
# foo found_file_1 found_file_2
find_exec_all_fn = $(1) -exec $(2) {} +
# Runs a command on all results of the `find` call one-by-one
# e.g.
# foo found_file_1
# foo found_file_2
find_exec_one_by_one_fn = $(1) | xargs -i $(2) {}
.PHONY: format
format: format_haskell format_nix format_cabal
format_check : format_check_haskell format_check_nix format_check_cabal
# Run fourmolu of .hs files
.PHONY: format_haskell
format_haskell:
$(call find_exec_all_fn, $(FIND_HASKELL_SOURCES), fourmolu -i)
.PHONY: format_check_haskell
format_check_haskell:
$(call find_exec_one_by_one_fn, $(FIND_HASKELL_SOURCES), fourmolu --mode check)
# Run nixpkgs-fmt of .nix files
.PHONY: format_nix
format_nix:
$(call find_exec_all_fn, $(FIND_NIX_SOURCES), nixpkgs-fmt)
.PHONY: format_check_nix
format_check_nix:
$(call find_exec_all_fn, $(FIND_NIX_SOURCES), nixpkgs-fmt --check)
# Run cabal-fmt of .cabal files
.PHONY: format_cabal
format_cabal:
$(call find_exec_all_fn, $(FIND_CABAL_SOURCES), cabal-fmt -i)
.PHONY: format_check_cabal
format_check_cabal:
$(call find_exec_all_fn, $(FIND_CABAL_SOURCES), cabal-fmt --check)
# Apply hlint suggestions
.PHONY: lint_haskell
lint_haskell:
$(call find_exec_one_by_one_fn, $(FIND_HASKELL_SOURCES), hlint -j --refactor --refactor-options="-i")
# Check hlint suggestions
.PHONY: lint_haskell_check
lint_haskell_check:
$(call find_exec_all_fn, $(FIND_HASKELL_SOURCES), hlint -j)
# Apply lint suggestions
.PHONY: lint
lint: lint_haskell lint_markdown
# Apply format and hlint
.PHONY: format_lint
format_lint: format lint
################################################################################
# Build
CABAL_YTXP_SDK := cd ytxp-sdk && cabal
.PHONY: build_all
build_all:
$(CABAL_YTXP_SDK) build -j all
################################################################################
# Test
# .PHONY: test_TODO
# test_serialization:
# $(CABAL_YTXP_SDK) test -j TODO
################################################################################
# Test
.PHONY: typos_check
typos_check :
typos -c ../../.typos.toml ../../
.PHONY: typos_fix
typos_fix:
typos -w -c ../../.typos.toml ../../
################################################################################
# Doc
.PHONY: build_doc
build_doc:
$(CABAL_YTXP_SDK) haddock --haddock-all --haddock-quickjump
# Check markdownlint suggestions
.PHONY: lint_markdown_check
lint_markdown_check:
$(call find_exec_all_fn, $(FIND_MARKDOWN_SOURCES), markdownlint)
# Apply markdownlint suggestions.
# NOTE: there are some warnings that cannot be automatically fixed
.PHONY: lint_markdown
lint_markdown:
$(call find_exec_all_fn, $(FIND_MARKDOWN_SOURCES), markdownlint -f)