-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathJustfile
136 lines (114 loc) · 4.47 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
default:
@just --list --unsorted
config := absolute_path('config')
build := absolute_path('.build')
out := absolute_path('firmware')
draw := absolute_path('draw')
# parse combos.dtsi and adjust settings to not run out of slots
_parse_combos:
#!/usr/bin/env bash
set -euo pipefail
cconf="{{ config / 'combos.dtsi' }}"
if [[ -f $cconf ]]; then
# set MAX_COMBOS_PER_KEY to the most frequent combos count
count=$(
tail -n +10 $cconf |
grep -Eo '[LR][TMBH][0-9]' |
sort | uniq -c | sort -nr |
awk 'NR==1{print $1}'
)
sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" "{{ config }}"/*.conf
echo "Setting MAX_COMBOS_PER_KEY to $count"
# set MAX_KEYS_PER_COMBO to the most frequent key count
count=$(
tail -n +10 $cconf |
grep -o -n '[LR][TMBH][0-9]' |
cut -d : -f 1 | uniq -c | sort -nr |
awk 'NR==1{print $1}'
)
sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" "{{ config }}"/*.conf
echo "Setting MAX_KEYS_PER_COMBO to $count"
fi
# parse build.yaml and filter targets by expression
_parse_targets $expr:
#!/usr/bin/env bash
attrs="[.board, .shield, .snippet]"
filter="(($attrs | map(. // [.]) | combinations), ((.include // {})[] | $attrs)) | join(\",\")"
echo "$(yq -r "$filter" build.yaml | grep -v "^," | grep -i "${expr/#all/.*}")"
# build firmware for single board & shield combination
_build_single $board $shield $snippet *west_args:
#!/usr/bin/env bash
set -euo pipefail
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"}
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
# build firmware for matching targets
build expr *west_args: _parse_combos
#!/usr/bin/env bash
set -euo pipefail
targets=$(just _parse_targets {{ expr }})
[[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1
echo "$targets" | while IFS=, read -r board shield snippet; do
just _build_single "$board" "$shield" "$snippet" {{ west_args }}
done
# clear build cache and artifacts
clean:
rm -rf {{ build }} {{ out }}
# clear all automatically generated files
clean-all: clean
rm -rf .west zmk
# clear nix cache
clean-nix:
nix-collect-garbage --delete-old
# parse & plot keymap
draw:
#!/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"
# initialize west
init:
west init -l config
west update --fetch-opt=--filter=blob:none
west zephyr-export
# list build targets
list:
@just _parse_targets all | sed 's/,*$//' | sort | column
# update west
update:
west update --fetch-opt=--filter=blob:none
# upgrade zephyr-sdk and python dependencies
upgrade-sdk:
nix flake update --flake .
[no-cd]
test $testpath *FLAGS:
#!/usr/bin/env bash
set -euo pipefail
testcase=$(basename "$testpath")
build_dir="{{ build / "tests" / '$testcase' }}"
config_dir="{{ '$(pwd)' / '$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_posix_64 -- \
-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
diff -auZ ${config_dir}/keycode_events.snapshot ${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