Repository navigation
Expand file tree
/
Copy pathJustfile
More file actions
214 lines (184 loc) · 7.41 KB
/
Copy pathJustfile
File metadata and controls
214 lines (184 loc) · 7.41 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
[private]
default:
@just --list --unsorted
config := absolute_path('config')
build := absolute_path('.build')
out := absolute_path('firmware')
draw := absolute_path('draw')
build_matrix := "build.yaml"
# parse build.yaml and filter targets by expression
_parse_targets $expr: _check_yq_version
#!/usr/bin/env bash
attrs="[.board, .shield, .snippet, .\"artifact-name\", .\"cmake-args\"]"
filter="(($attrs | map(. // [.]) | combinations), ((.include // {})[] | $attrs)) | join(\",\")"
echo "$(yq -r "$filter" {{build_matrix}} | grep -v "^," | grep -i "${expr/#all/.*}")"
# build firmware for single board & shield combination
_build_single $board $shield $snippet $artifact cmake_args *west_args:
#!/usr/bin/env bash
set -euo pipefail
artifact="${artifact:-${shield:+${shield// /+}-}${board//\//_}}"
build_dir="{{ build / '$artifact' }}"
echo "Building firmware for $artifact..."
west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} ${snippet:+-S "$snippet"} -- \
-DZMK_CONFIG="{{ config }}" ${shield:+-DSHIELD="$shield"} {{ cmake_args }}
if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then
mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.uf2" "{{ out }}/$artifact.uf2"
else
mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.bin" "{{ out }}/$artifact.bin"
fi
# flash firmware for single board & shield combination
# only needed for boards which do not support UF2
_flash_single $board $shield $artifact:
#!/usr/bin/env bash
set -euo pipefail
artifact="${artifact:-${shield:+${shield// /+}-}${board//\//_}}"
build_dir="{{ build / '$artifact' }}"
echo "Flashing firmware for $artifact..."
west flash -d "$build_dir"
# List build targets. The sed chain removes version and build variants,
# and prints the shield (if given) or otherwise the board name.
[group('build & draw')]
[doc('list build targets')]
list:
@just build_matrix={{build_matrix}} _parse_targets all \
| sed 's|[@/][^,]*,|,|' \
| sed 's|\([^,]*\),\([^,]\+\),.*|\2|' \
| sed 's|\([^,]*\),,.*|\1|' \
| sort \
| column
# build firmware for targets matching <expr>
[group('build & draw')]
build expr *west_args:
#!/usr/bin/env bash
set -euo pipefail
targets=$(just build_matrix={{build_matrix}} _parse_targets {{ expr }})
[[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1
echo "$targets" | while IFS=, read -r board shield snippet artifact cmake_args; do
just _build_single "$board" "$shield" "$snippet" "$artifact" "$cmake_args" {{ west_args }}
done
# flash firmware for targets matching <expr>
[group('build & draw')]
flash expr: (build expr)
#!/usr/bin/env bash
set -euo pipefail
targets=$(just build_matrix={{build_matrix}} _parse_targets {{ expr }})
[[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1
echo "$targets" | while IFS=, read -r board shield snippet artifact cmake_args; do
just _flash_single "$board" "$shield" "$artifact"
done
# parse & plot keymap
[group('build & draw')]
draw: _check_yq_version
#!/usr/bin/env bash
set -euo pipefail
keymap -c "{{ draw }}/config.yaml" parse -z "{{ config }}/base.keymap" --virtual-layers Combos >"{{ draw }}/base.yaml"
yq -Yi '.combos.[].l = ["Combos"]' "{{ draw }}/base.yaml"
keymap -c "{{ draw }}/config.yaml" draw "{{ draw }}/base.yaml" -k "ferris/sweep" >"{{ draw }}/base.svg"
jq_expr='
def extract_label: if type == "string" then . else .t end;
def is_transparent: type == "object" and (.type == "trans" or .type == "held");
.layers = {
Base: [
[.layers.Base, .layers.Nav, .layers.Fn, .layers.Num, .layers.Sys] | transpose[] |
(.[0] | if type == "string" then {t: .} else . end) as $base |
(.[1] | if is_transparent then null else extract_label end) as $nav |
(.[2] | if is_transparent then null else extract_label end) as $fn |
(.[3] | if is_transparent then null else extract_label end) as $num |
(.[4] | if is_transparent then null else extract_label end) as $sys |
$base
+ (if $nav == null then {} else {tr: $nav} end)
+ (if $fn == null then {} else {tl: $fn} end)
+ (if $num == null then {} else {bl: $num} end)
+ (if $sys == null then {} else {br: $sys} end)
],
Combos: .layers.Combos
} |
.combos = [.combos[] | .l = ["Combos"]]
'
yq -y "$jq_expr" "{{ draw }}/base.yaml" >"{{ draw }}/overview.yaml"
keymap -c "{{ draw }}/config.yaml" draw "{{ draw }}/overview.yaml" -k "ferris/sweep" >"{{ draw }}/overview.svg"
sed -i '/<text.*class="label"/d' "{{ draw }}/overview.svg"
# initialize the west workspace
[group('workspace')]
init:
west init -l config
west update --fetch-opt=--filter=blob:none
west zephyr-export
# synchronize the west workspace (after manifest changes)
[group('workspace')]
sync:
west update --fetch-opt=--filter=blob:none
# bump west manifest and re-sync the workspace
[group('workspace')]
bump-west: && sync
pin-west bump
# bump nix toolchain (flake.lock)
[group('workspace')]
bump-nix:
nix flake update --flake .
# clear build cache and artifacts
[group('cleanup')]
clean:
rm -rf {{ build }} {{ out }}
# garbage-collect the nix store (system-wide)
[group('cleanup')]
nix-gc:
nix-collect-garbage --delete-old
# format devicetree files, or a single directory recursively
[group('dev')]
[no-cd]
format *paths:
#!/usr/bin/env bash
set -euo pipefail
paths=({{ paths }})
if [[ ${#paths[@]} -eq 0 ]]; then
echo "Usage: just format <file>... | <dir>" >&2
exit 1
fi
for path in "${paths[@]}"; do
if [[ -d "$path" ]]; then
if [[ ${#paths[@]} -gt 1 ]]; then
echo "A directory must be the only argument. Aborting..." >&2
exit 1
fi
cd "$path"
dts-format --fix
exit 0
fi
done
dts-format --fix "${paths[@]}"
# run test suites (--auto-accept updates the snapshot)
[group('dev')]
[no-cd]
test $testpath *FLAGS:
#!/usr/bin/env bash
set -euo pipefail
testcase=$(basename "$testpath")
build_dir="{{ build / "tests" / '$testcase' }}"
config_dir=$(realpath "$testpath")
cd {{ justfile_directory() }}
if [[ "{{ FLAGS }}" != *"--no-build"* ]]; then
echo "Running $testcase..."
rm -rf "$build_dir"
west build -s zmk/app -d "$build_dir" -b native_sim//zmk_test_mock -- \
-DCONFIG_ASSERT=y -DZMK_CONFIG="$config_dir"
fi
${build_dir}/zephyr/zmk.exe | sed -e "s/.*> //" |
tee ${build_dir}/keycode_events.full.log |
sed -n -f ${config_dir}/events.patterns > ${build_dir}/keycode_events.log
if [[ "{{ FLAGS }}" == *"--verbose"* ]]; then
cat ${build_dir}/keycode_events.log
fi
if [[ "{{ FLAGS }}" == *"--auto-accept"* ]]; then
cp ${build_dir}/keycode_events.log ${config_dir}/keycode_events.snapshot
fi
diff -auZ ${config_dir}/keycode_events.snapshot ${build_dir}/keycode_events.log
# warn user if they are using golang-yq and not python-yq
[no-exit-message]
_check_yq_version:
#!/usr/bin/env bash
if yq --help 2>&1 | grep -qi 'eval'; then
echo "This script requires python-yq, but PATH contains golang-yq" >&2
echo "Please install python-yq or use the included nix shell" >&2
exit 1
fi