Skip to content

Commit f140b5e

Browse files
committed
chore: convert keyboards build.sh to builder script
1 parent 454448b commit f140b5e

File tree

1 file changed

+58
-113
lines changed

1 file changed

+58
-113
lines changed

common/test/keyboards/build.sh

Lines changed: 58 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,42 @@
11
#!/usr/bin/env bash
2-
# TODO: builder script plz
32
## START STANDARD BUILD SCRIPT INCLUDE
43
# adjust relative paths as necessary
54
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
65
. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh"
76
## END STANDARD BUILD SCRIPT INCLUDE
8-
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
9-
THIS_DIR="$(dirname "$THIS_SCRIPT")"
10-
11-
display_usage() {
12-
echo "usage: build.sh [build options] [targets]"
13-
echo
14-
echo "Build options:"
15-
echo " --debug, -d Debug build"
16-
echo " --silent, -s Suppress information messages"
17-
echo " --kmc path Specify path to kmc, defaults"
18-
echo " to developer/src/kmc/build/"
19-
echo " --zip-source Create zip file for source of each"
20-
echo " keyboard for artifact tests"
21-
echo " --index Build index.html for artifact tests"
22-
echo
23-
echo "Targets (all unless specified):"
24-
25-
for d in "$THIS_DIR/"*/; do
26-
d="$(basename "$d")"
27-
if [ "$d" != "invalid" && "$d" != "issue"]; then
28-
echo " $d"
29-
fi
30-
done
317

32-
echo
33-
exit 0
34-
}
8+
cd "$THIS_SCRIPT_PATH"
359

36-
readonly KMC_LAUNCHER=node
37-
QUIET=false
38-
DEBUG=false
39-
INDEX=false
40-
ZIPSOURCE=false
41-
KMC="$KEYMAN_ROOT/developer/src/kmc/build/src/kmc.js"
42-
TARGETS=()
43-
44-
# Parse args
45-
shopt -s nocasematch
46-
47-
while [[ $# -gt 0 ]] ; do
48-
key="$1"
49-
case $key in
50-
--help|-h|-\?)
51-
display_usage
52-
;;
53-
--debug|-d)
54-
DEBUG=true
55-
;;
56-
--silent|-s)
57-
QUIET=true
58-
;;
59-
--zip-source)
60-
ZIPSOURCE=true
61-
;;
62-
--index)
63-
INDEX=true
64-
;;
65-
--kmc)
66-
shift
67-
KMC="$1"
68-
;;
69-
*)
70-
TARGETS+=("$key")
71-
esac
72-
shift
10+
targets=()
11+
# Build list of available targets from subfolders, if none specified
12+
for d in */; do
13+
d="$(basename "$d")"
14+
if [ "$d" != "invalid" ] && [ "$d" != "issue" ]; then
15+
targets+=(":$d")
16+
fi
7317
done
7418

75-
# Build list of available targets from subfolders, if none specified
76-
if [ ${#TARGETS[@]} == 0 ]; then
77-
for d in "$THIS_DIR/"*/; do
78-
d="$(basename "$d")"
79-
if [ "$d" != "invalid" ] && [ "$d" != "issue" ]; then
80-
TARGETS+=("$d")
81-
fi
82-
done
83-
fi
84-
85-
if ! $QUIET; then
86-
displayInfo "" \
87-
"DEBUG: $DEBUG" \
88-
"QUIET: $QUIET" \
89-
"TARGETS: ${TARGETS[@]}" \
90-
"ZIPSOURCE: $ZIPSOURCE" \
91-
"INDEX: $INDEX" \
92-
""
93-
fi
94-
95-
zipsource() {
19+
KMC="$KEYMAN_ROOT/developer/src/kmc/build/src/kmc.js"
20+
21+
builder_describe "Test Keyboards" \
22+
clean configure build \
23+
${targets[@]} \
24+
"--index Build index.html for artifact tests" \
25+
"--zip-source Create zip file for source of each keyboard for artifact tests" \
26+
"--kmc=KMC Specify path to kmc, defaults to developer/src/kmc/build/" \
27+
"--silent,-s Suppress information messages"
28+
29+
builder_parse "$@"
30+
31+
function zipsource() {
9632
local target="$1"
9733
pushd "$1" > /dev/null
9834
7z a -r -x!build -x"!$target.kpj.user" "${target}_source.zip" .
9935
popd > /dev/null
10036
}
10137

102-
###
103-
104-
d=
105-
ss=
106-
if $DEBUG; then
107-
d=-d
108-
fi
109-
if $QUIET; then
110-
ss="--log-level silent"
111-
fi
112-
$KMC_LAUNCHER "$KMC" build $d $ss -w "${TARGETS[@]}"
113-
114-
for TARGET in "${TARGETS[@]}"; do
115-
if $ZIPSOURCE; then
116-
zipsource "$TARGET"
117-
fi
118-
done
119-
120-
###
121-
122-
if $INDEX; then
123-
cat << EOF > "$THIS_DIR/index.html"
38+
function build_index() {
39+
cat << EOF > index.html
12440
<!DOCTYPE html>
12541
<html>
12642
<head>
@@ -132,18 +48,47 @@ if $INDEX; then
13248
<ul>
13349
EOF
13450

135-
for TARGET in "${TARGETS[@]}"; do
136-
if $ZIPSOURCE; then
137-
echo " <li><a href='$TARGET/build/$TARGET.kmp'>$TARGET.kmp</a> (<a href='$TARGET/${TARGET}_source.zip'>source</a>)</li>" >> "$THIS_DIR/index.html"
51+
for TARGET in "${targets[@]}"; do
52+
if builder_has_option --zip-source; then
53+
echo " <li><a href='$TARGET/build/$TARGET.kmp'>$TARGET.kmp</a> (<a href='$TARGET/${TARGET}_source.zip'>source</a>)</li>" >> index.html
13854
else
139-
echo " <li><a href='$TARGET/build/$TARGET.kmp'>$TARGET.kmp</a></li>" >> "$THIS_DIR/index.html"
55+
echo " <li><a href='$TARGET/build/$TARGET.kmp'>$TARGET.kmp</a></li>" >> index.html
14056
fi
14157
done
14258

143-
cat << 'EOF' >> "$THIS_DIR/index.html"
59+
cat << EOF >> index.html
14460
</ul>
14561
</body>
14662
</html>
14763
EOF
64+
}
65+
66+
###
67+
68+
function build() {
69+
local active_targets=()
70+
for TARGET in "${targets[@]}"; do
71+
if builder_has_action build$TARGET; then
72+
active_targets+=(${TARGET#:})
73+
fi
74+
done
75+
76+
local ss=
77+
if builder_has_option --silent; then
78+
ss="--log-level silent"
79+
fi
80+
81+
node "$KMC" build $builder_debug $ss -w "${active_targets[@]}"
82+
83+
if builder_has_option --zip-source; then
84+
for TARGET in "${active_targets[@]}"; do
85+
zipsource "$TARGET"
86+
done
87+
fi
88+
89+
if builder_has_option --index; then
90+
build_index
91+
fi
92+
}
14893

149-
fi
94+
builder_run_action build build

0 commit comments

Comments
 (0)