11#! /usr/bin/env bash
2-
3- set -e
4- set -u
5-
62# # START STANDARD BUILD SCRIPT INCLUDE
73# adjust relative paths as necessary
84THIS_SCRIPT=" $( readlink -f " ${BASH_SOURCE[0]} " ) "
95. " ${THIS_SCRIPT%/* } /../../../resources/build/build-utils.sh"
10- . " $KEYMAN_ROOT /resources/shellHelperFunctions.sh"
116# # END STANDARD BUILD SCRIPT INCLUDE
12- THIS_DIR=" $( dirname " $THIS_SCRIPT " ) "
13-
14- display_usage () {
15- echo " usage: build.sh [build options] [targets]"
16- echo
17- echo " Build options:"
18- echo " --clean, -c Clean instead of build"
19- echo " --debug, -d Debug build"
20- echo " --silent, -s Suppress information messages"
21- echo " --keyboard, -k Build only keyboards (not packages)"
22- echo " --kmcomp path Specify path to kmcomp.exe, defaults"
23- echo " to windows/bin/developer/kmcomp.exe"
24- echo " --zip-source Create zip file for source of each"
25- echo " keyboard for artifact tests"
26- echo " --index Build index.html for artifact tests"
27- echo
28- echo " Targets (all unless specified):"
29-
30- for d in " $THIS_DIR /" * /; do
31- d=" $( basename " $d " ) "
32- if [ " $d " != " invalid" ]; then
33- echo " $d "
34- fi
35- done
367
37- echo
38- exit 0
39- }
8+ cd " $THIS_SCRIPT_PATH "
409
41- QUIET=false
42- DEBUG=false
43- CLEAN=false
44- KEYBOARDS_ONLY=false
45- CUSTOM_KMCOMP=
46- INDEX=false
47- ZIPSOURCE=false
48- KMCOMP=" $KEYMAN_ROOT /developer/bin/kmcomp.exe"
49- TARGETS=()
50-
51- # Parse args
52- shopt -s nocasematch
53-
54- while [[ $# -gt 0 ]] ; do
55- key=" $1 "
56- case $key in
57- --help|-h|-\? )
58- display_usage
59- ;;
60- --clean|-c)
61- CLEAN=true
62- ;;
63- --debug|-d)
64- DEBUG=true
65- ;;
66- --silent|-s)
67- QUIET=true
68- ;;
69- --keyboard|-k)
70- KEYBOARDS_ONLY=true
71- ;;
72- --zip-source)
73- ZIPSOURCE=true
74- ;;
75- --index)
76- INDEX=true
77- ;;
78- --kmcomp)
79- shift
80- KMCOMP=" $1 "
81- CUSTOM_KMCOMP=true
82- ;;
83- * )
84- TARGETS+=(" $key " )
85- esac
86- 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
8717done
8818
89- # TODO: while this is intended to be cross platform, we
90- # don't currently have a binary version of kmcomp available
91- # during Linux and macOS builds, so that will need to be
92- # manually sourced.
93- KMCOMP_LAUNCHER=
94-
95- if ! $CUSTOM_KMCOMP ; then
96- case " ${OSTYPE} " in
97- " cygwin" )
98- ;;
99- " msys" )
100- ;;
101- " darwin" * )
102- # For Catalina (10.15) onwards, must use wine64
103- base_macos_ver=10.15
104- macos_ver=$( sw_vers -productVersion)
105- if verlt " $macos_ver " " $base_macos_ver " ; then
106- KMCOMP_LAUNCHER=wine
107- else
108- # On Catalina, and later versions:
109- # wine-4.12.1 works; wine-5.0, wine-5.7 do not.
110- # retrieve these from:
111- # `brew tap gcenx/wine && brew install --cask --no-quarantine wine-crossover`
112- # may also need to `sudo spctl --master-disable`
113- KMCOMP_LAUNCHER=wine64
114- KMCOMP=" $( dirname $KMCOMP ) /kmcomp.x64.exe"
115- fi
116- ;;
117- * )
118- KMCOMP_LAUNCHER=wine
119- ;;
120- esac
121- fi
19+ KMC=" $KEYMAN_ROOT /developer/src/kmc/build/src/kmc.js"
12220
123- # Build list of available targets from subfolders, if none specified
124- if [ ${# TARGETS[@]} == 0 ]; then
125- for d in " $THIS_DIR /" * /; do
126- d=" $( basename " $d " ) "
127- if [ " $d " != " invalid" ] && [ " $d " != " issue" ]; then
128- TARGETS+=(" $d " )
129- fi
130- done
131- fi
132-
133- if ! $QUIET ; then
134- displayInfo " " \
135- " CLEAN: $CLEAN " \
136- " DEBUG: $DEBUG " \
137- " QUIET: $QUIET " \
138- " KEYBOARDS_ONLY: $KEYBOARDS_ONLY " \
139- " TARGETS: ${TARGETS[@]} " \
140- " ZIPSOURCE: $ZIPSOURCE " \
141- " INDEX: $INDEX " \
142- " "
143- fi
144-
145- clean () {
146- local kpj=" $1 .kpj" ss= s=
147- if $QUIET ; then
148- ss=-ss
149- s=-s
150- fi
151- pushd " $1 " > /dev/null
152- if [ -f build.sh ]; then
153- ./build.sh -c $s
154- else
155- $KMCOMP_LAUNCHER " $KMCOMP " -c $ss " $kpj "
156- fi
157- popd > /dev/null
158- }
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"
15928
160- build () {
161- local kpj=" $1 .kpj" d= t= ss= target= s= k=
162- if $KEYBOARDS_ONLY ; then
163- k=-k
164- t=-t
165- target=" $1 .kmn"
166- fi
167- if $DEBUG ; then
168- d=-d
169- fi
170- if $QUIET ; then
171- s=-s
172- ss=-ss
173- fi
174- # -w - treat warnings as errors, we'll force this
175- # -cfc - check filename conventions
176- pushd " $1 " > /dev/null
177- if [ -f build.sh ]; then
178- ./build.sh $d $k $s
179- else
180- $KMCOMP_LAUNCHER " $KMCOMP " $d $ss -w -cfc " $kpj " $t " $target "
181- fi
182- popd > /dev/null
183- }
29+ builder_parse " $@ "
18430
185- zipsource () {
31+ function zipsource() {
18632 local target=" $1 "
18733 pushd " $1 " > /dev/null
18834 7z a -r -x! build -x" !$target .kpj.user" " ${target} _source.zip" .
18935 popd > /dev/null
19036}
19137
192- # ##
193-
194- for TARGET in " ${TARGETS[@]} " ; do
195- if $CLEAN ; then
196- if ! $QUIET ; then
197- echo
198- builder_heading " Cleaning target $TARGET "
199- echo
200- fi
201- clean " $TARGET "
202- else
203- if ! $QUIET ; then
204- echo
205- builder_heading " Building target $TARGET "
206- echo
207- fi
208- build " $TARGET "
209-
210- if $ZIPSOURCE ; then
211- zipsource " $TARGET "
212- fi
213- fi
214- done
215-
216- # ##
217-
218- if $INDEX ; then
219- if $CLEAN ; then
220- rm -f " $THIS_DIR /index.html"
221- else
222- cat << EOF > "$THIS_DIR /index.html"
38+ function build_index() {
39+ local active_targets=($* )
40+ cat << EOF > index.html
22341<!DOCTYPE html>
22442<html>
22543 <head>
@@ -231,19 +49,47 @@ if $INDEX; then
23149 <ul>
23250EOF
23351
234- for TARGET in " ${TARGETS [@]} " ; do
235- if $ZIPSOURCE ; then
236- echo " <li><a href='$TARGET /build/$TARGET .kmp'>$TARGET .kmp</a> (<a href='$TARGET /${TARGET} _source.zip'>source</a>)</li>" >> " $THIS_DIR / index.html"
237- else
238- echo " <li><a href='$TARGET /build/$TARGET .kmp'>$TARGET .kmp</a></li>" >> " $THIS_DIR / index.html"
239- fi
240- done
52+ for TARGET in " ${active_targets [@]} " ; do
53+ if builder_has_option --zip-source ; then
54+ echo " <li><a href='$TARGET /build/$TARGET .kmp'>$TARGET .kmp</a> (<a href='$TARGET /${TARGET} _source.zip'>source</a>)</li>" >> index.html
55+ else
56+ echo " <li><a href='$TARGET /build/$TARGET .kmp'>$TARGET .kmp</a></li>" >> index.html
57+ fi
58+ done
24159
242- cat << ' EOF ' >> "$THIS_DIR/ index.html"
60+ cat << EOF >> index.html
24361 </ul>
24462 </body>
24563</html>
24664EOF
65+ }
66+
67+ # ##
68+
69+ function build() {
70+ local active_targets=()
71+ for TARGET in " ${targets[@]} " ; do
72+ if builder_has_action build$TARGET ; then
73+ active_targets+=(${TARGET#: } )
74+ fi
75+ done
76+
77+ local ss=
78+ if builder_has_option --silent; then
79+ ss=" --log-level silent"
24780 fi
248- fi
249- exit 0
81+
82+ node " $KMC " build $builder_debug $ss -w " ${active_targets[@]} "
83+
84+ if builder_has_option --zip-source; then
85+ for TARGET in " ${active_targets[@]} " ; do
86+ zipsource " $TARGET "
87+ done
88+ fi
89+
90+ if builder_has_option --index; then
91+ build_index " ${active_targets[@]} "
92+ fi
93+ }
94+
95+ builder_run_action build build
0 commit comments