-
Notifications
You must be signed in to change notification settings - Fork 53
/
justfile
165 lines (136 loc) · 4.81 KB
/
justfile
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
# set to non-empty string to disable parallel builds and tests
#
# e.g:
# just disableParallel=yes test
disableParallel := ''
# set to non-empty string to disable optimized build
#
# e.g:
# just disableOptimized=yes install
disableOptimized := ''
# set to non-empty string to enable command debugging
enableDebug := ''
# set to non-empty string to enable pedantic mode
pedantic := ''
# set to number of parallel jobs
numParallelJobs := ''
# the command used to run stack
stack := "stack"
# the command used to run ormolu
ormolu := "ormolu"
# The CC argument to the runtime Makefile
runtimeCcArg := ''
# The LIBTOOL argument to the runtime Makefile
runtimeLibtoolArg := ''
# The flags used in the runtime make commands
runtimeCcFlag := if runtimeCcArg == '' { '' } else { "CC=" + runtimeCcArg }
runtimeLibtoolFlag := if runtimeLibtoolArg == '' { '' } else { "LIBTOOL=" + runtimeLibtoolArg }
runtimeArgs := trim(runtimeCcFlag + ' ' + runtimeLibtoolFlag)
# flags used in the stack command
stackOptFlag := (if disableOptimized == '' { '' } else { '--fast' }) + ' ' + (if pedantic == '' { '' } else { '--pedantic' })
# The ghc `-j` flag defaults to number of cpus when no argument is passed
stackGhcParallelFlag := if disableParallel == '' { "--ghc-options=-j" + numParallelJobs } else { '' }
# The stack `-j` options requires an argument
stackParallelFlagJobs := if numParallelJobs == '' { num_cpus() } else { numParallelJobs }
stackParallelFlag := if disableParallel == '' { '-j' + stackParallelFlagJobs } else { '' }
stackArgs := stackOptFlag + ' ' + stackParallelFlag + ' ' + stackGhcParallelFlag
# flags used in the stack test command
testArgs := "--hide-successes"
rtsFlag := if disableParallel == '' { '+RTS -N' + numParallelJobs + ' -RTS' } else { '' }
# flag used to enable tracing of bash commands
bashDebugArg := if enableDebug == '' { '' } else { 'x' }
[private]
default:
@just --list
@_ormoluCmd filesCmd mode:
{{ trim(filesCmd) }} \
| xargs -r {{ ormolu }} --mode {{ mode }}
# Formats all Haskell files in the project. `format changed` formats only changed files. `format FILES` formats individual files.
format *opts:
#!/usr/bin/env bash
set -euo{{ bashDebugArg }} pipefail
if [ ! -e "juvix.cabal" ]; then
echo "Error: juvix.cabal does not exist. Please, run 'just install' or 'stack setup' first"
exit 1
fi
opts='{{ trim(opts) }}'
case $opts in
"")
just _ormoluCmd "git ls-files '*.hs'" inplace
;;
changed)
just _ormoluCmd \
"(git --no-pager diff --name-only --diff-filter=AM && git --no-pager diff --cached --name-only --diff-filter=AM) | grep '\\.hs\$'" \
inplace
;;
check)
just _ormoluCmd "git ls-files '*.hs'" check
;;
*)
just _ormoluCmd "echo {{ opts }}"
;;
esac
# Run the tests in the project. Use the filter arg to set a Tasty pattern.
[no-exit-message]
test *filter:
#!/usr/bin/env bash
set -euo{{ bashDebugArg }} pipefail
filter='{{ trim(filter) }}'
if [ -n "$filter" ]; then
filter="-p \"$filter\""
fi
set -x
{{ stack }} test {{ stackArgs }} --ta "{{ testArgs }} {{ rtsFlag }} $filter"
# Run a juvix command and profile it
run-profile +cmd:
cabal run --enable-profiling juvix -- {{ cmd }} +RTS -p
# Compile-time configuration
configure:
{{ runtimeCcFlag }} config/configure.sh
# Build the juvix runtime
_buildRuntime: configure
cd runtime && make {{ runtimeArgs }}
# Build the project. `build runtime` builds only the runtime.
[no-exit-message]
build *opts:
#!/usr/bin/env bash
set -euo{{ bashDebugArg }} pipefail
opts='{{ trim(opts) }}'
case $opts in
runtime)
just runtimeCcArg="{{ runtimeCcArg }}" runtimeArgs="{{ runtimeArgs }}" _buildRuntime
;;
*)
just runtimeCcArg="{{ runtimeCcArg }}" runtimeArgs="{{ runtimeArgs }}" _buildRuntime
set -x
{{ stack }} build {{ stackArgs }}
;;
esac
# Install juvix
[no-exit-message]
install: _buildRuntime
{{ stack }} install {{ stackArgs }}
# Clean all .juvix-build directories in the project
_cleanJuvixBuild:
@find . -type d -name '.juvix-build' | xargs rm -rf
# Clean the juvix runtime build directory
_cleanRuntime:
@cd runtime && make clean
# Clean the project. `clean runtime` cleans only the runtime. `clean juvix-build` cleans only juvix-build dirs.
clean *opts:
#!/usr/bin/env bash
set -euo{{ bashDebugArg }} pipefail
opts='{{ trim(opts) }}'
case $opts in
runtime)
just _cleanRuntime
;;
juvix-build)
just _cleanJuvixBuild
;;
*)
just _cleanRuntime
just _cleanJuvixBuild
{{ stack }} clean --full
;;
esac