-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·134 lines (108 loc) · 3.4 KB
/
build.sh
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
#!/bin/bash
# Rowan Decker 2018
# Arg 1: Build script (keyboard.bash)
# Arg 2: Input dir (kll files)
# Arg 2: Output file
# Env: DefaultMapOverride, PartialMapsExpandedOverride, Layout
# SPLIT_KEYBOARD
#
# Example:
# export DefaultMapOverride="stdFuncMap KType-Standard-0"
# export PartialMapsExpandedOverride="stdFuncMap KType-Standard-0;stdFuncMap KType-Standard-1"
# export Layout="Standard"
# ./build.sh KType.bash my_ktype/kll MyBuild.zip
build() {
BuildScript="$1"
BUILD_DIR="$2"
(echo " Build Dir: ${BUILD_DIR}"
set -exo pipefail
pipenv run ./${BuildScript} -c "${CONTROLLER_DIR}" -o "${BUILD_DIR}" \
2>&1 | tee "${BUILD_DIR}/build.log"
RETVAL=$?
set +x
exit $RETVAL
)
}
if [ "$#" -lt 3 ]; then
echo "Usage: <build script> <input dir> <output file>"
exit
fi
# Double check with docker volume mountpoints
CONTROLLER_DIR="/controller"
BUILD_DIR="$(mktemp -d)"
IN_DIR="${IN_DIR:-/mnt/config}"
OUT_DIR="${OUT_DIR:-/mnt/builds}"
BuildScript="${1}"; shift
KllDir="${IN_DIR}/${1}"; shift
OutFile="${OUT_DIR}/${1}"; shift
echo
echo " ========== STARTING BUILD ======== "
echo " @@@@@ DefaultMapOverride=${DefaultMapOverride}"
echo " @@@@@ PartialMapsExpandedOverride=${PartialMapsExpandedOverride}"
echo " @@@@@ Layout=${Layout}"
ls -l "${KllDir}"
echo "------------------------"
# try to use ccache
export PATH="/usr/lib/ccache:$PATH"
# try to use a cached kll layouts dir
for f in /kll_cache/*; do ln -s "$f" /tmp/; done
# try to use a github apikey secret
[ -z "$GITHUB_APIKEY" ] && export GITHUB_APIKEY="$(cat /run/secrets/github_apikey)"
#set -x
# the kll compiler looks for files in the build dir
mv ${KllDir}/* "${BUILD_DIR}"
rmdir "${KllDir}/${HASH}"
if [ "${SPLIT_KEYBOARD}" == "1" ]; then
LBuildPath="${BUILD_DIR}/left"
mkdir -p "${LBuildPath}"
cp ${BUILD_DIR}/*.kll "${LBuildPath}"
build "${BuildScript%.*}-l.bash" "${LBuildPath}" &
PID_LEFT=$!
RBuildPath="${BUILD_DIR}/right"
mkdir -p "${RBuildPath}"
cp ${BUILD_DIR}/*.kll "${RBuildPath}"
build "${BuildScript%.*}-r.bash" "${RBuildPath}" &
PID_RIGHT=$!
wait $PID_LEFT
RETVAL=$?
wait $PID_RIGHT
RETVAL2=$?
if [ ${RETVAL} -eq 0 ]; then
RETVAL=${RETVAL2}
fi
ln -s ${LBuildPath}/kiibohd.dfu.bin ${BUILD_DIR}/left_kiibohd.dfu.bin
ln -s ${LBuildPath}/kiibohd.secure.dfu.bin ${BUILD_DIR}/left_kiibohd.secure.dfu.bin
ln -s ${LBuildPath}/kll.json ${BUILD_DIR}/left_kll.json
ln -s ${LBuildPath}/generatedKeymap.h ${BUILD_DIR}/left_generatedKeymap.h
ln -s ${LBuildPath}/kll_defs.h ${BUILD_DIR}/left_kll_defs.h
ln -s ${RBuildPath}/kiibohd.dfu.bin ${BUILD_DIR}/right_kiibohd.dfu.bin
ln -s ${RBuildPath}/kiibohd.secure.dfu.bin ${BUILD_DIR}/right_kiibohd.secure.dfu.bin
ln -s ${RBuildPath}/kll.json ${BUILD_DIR}/right_kll.json
ln -s ${RBuildPath}/generatedKeymap.h ${BUILD_DIR}/right_generatedKeymap.h
ln -s ${RBuildPath}/kll_defs.h ${BUILD_DIR}/right_kll_defs.h
cat ${LBuildPath}/build.log ${RBuildPath}/build.log > ${BUILD_DIR}/build.log
else
build "${BuildScript}" "${BUILD_DIR}"
RETVAL=$?
echo "Build Result: ${RETVAL}"
fi
if [ "$RETVAL" -ne 0 ]; then
OutFile="${OutFile%.*}_error.zip"
fi
ls -la "${BUILD_DIR}"
echo "------------------------"
echo " @@@@@ Creating build zip ${OutFile}"
cd "${BUILD_DIR}"
mkdir kll
cp *.kll kll/
mkdir log
mv *.log *.h log/
zip -v "${OutFile}" *.kll *.dfu.bin *.json kll/* log/*
echo -n " >>> Build Completed "
if [ "$RETVAL" -eq 0 ]; then
echo -e "\e[1;34m[OK]\e[0m"
else
echo -e "\e[1;91m[ERROR]\e[0m"
fi
echo
exit $RETVAL