-
Notifications
You must be signed in to change notification settings - Fork 0
/
mb_runner.sh
executable file
·223 lines (189 loc) · 5.15 KB
/
mb_runner.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
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
215
216
217
218
219
220
221
222
223
#!/bin/bash
# This is just a little helper-script to make ConnectIQ-development on UNIX-systems easier (without using the Eclipse-plugin).
#
# Based on the (Linux) ConnectIQ SDK 3.1.0
# ( https://developer.garmin.com/downloads/connect-iq/sdks/connectiq-sdk-lin-3.1.6-2019-10-23-2de4665c6.zip )
#
# The following tasks can be invoked:
# * compiling (re)sources and building a PRG-file for testing
# * run unit-tests (requires a running simulator)
# * creating a signed IQ-file package for publishing
# * cleaning up previously built files
# * starting the ConnectIQ-simulator
# * pushing the generated PRG-file to the running simulator
#
# Usage:
# mb_runner.sh {build|test|package|clean|simulator|push} [full-path-to-ciq-project-root] [relative-resources-folder-path] [relative-source-folder-path]
#
# Example (for a standard project with jungle-file; script directly run from within project-root):
# mb_runner.sh package
#
# Example (for a standard project with jungle-file; using a specified project-root):
# mb_runner.sh package /home/achim/projects/HueCIQ
#
# Example (for a "legacy" project WITHOUT jungle file; using custom paths for root/resources/sources):
# mb_runner.sh package /home/achim/projects/HueCIQ resources source
# **********
# env checks
# **********
[ -z "${MB_HOME}" ] && { echo "MB_HOME not set!"; exit 1; }
[ -z "${MB_PRIVATE_KEY}" ] && { echo "MB_PRIVATE_KEY not set!"; exit 1; }
# ***********
# param check
# ***********
case "${1}" in
build|test|package|clean|simulator|push)
;;
*)
echo "Usage: `basename ${0}` {build|test|package|clean|simulator|push} [full-path-to-ciq-project-root] [relative-resources-folder-path] [relative-source-folder-path]"
exit 1
;;
esac
if [ -n "${2}" ]; then
PROJECT_HOME="${2}"
else
PROJECT_HOME="${PWD}"
fi
if [ ! -n ${3} ]; then
RESOURCES_FOLDER="${3}"
else
RESOURCES_FOLDER="resources"
fi
if [ ! -n ${4} ]; then
SOURCE_FOLDER="${4}"
else
SOURCE_FOLDER="source"
fi
# *****************
# defaults & config
# *****************
JUNGLE_FILES=("${PROJECT_HOME}/monkey.jungle")
TEST_JUNGLE_FILES=("${PROJECT_HOME}/test.jungle")
MANIFEST_FILE="${PROJECT_HOME}/manifest.xml"
CONFIG_FILE="${PROJECT_HOME}/mb_runner.cfg"
if [ ! -e "${CONFIG_FILE}" ] ; then
echo "Config file \"${CONFIG_FILE}\" not found!"
exit 1
else
source "${CONFIG_FILE}"
fi
[ -z "${APP_NAME}" ] && { echo "APP_NAME not set!"; exit 1; }
OUT_DIR="${PROJECT_HOME}/bin"
# ******************
# sdk specific stuff
# ******************
API_DB="${MB_HOME}/bin/api.db"
PROJECT_INFO="${MB_HOME}/bin/projectInfo.xml"
API_DEBUG="${MB_HOME}/bin/api.debug.xml"
DEVICES="${MB_HOME}/bin/devices.xml"
# **********
# processing
# **********
# possible parameters ...
#PARAMS+="--apidb \"${API_DB}\" "
#PARAMS+="--buildapi "
#PARAMS+="--configs-dir <arg> "
#PARAMS+="--device \"${TARGET_DEVICE}\" "
#PARAMS+="--package-app "
#PARAMS+="--debug "
#PARAMS+="--excludes-map-file <arg> "
#PARAMS+="--import-dbg \"${API_DEBUG}\" "
#PARAMS+="--write-db "
#PARAMS+="--manifest <arg> "
#PARAMS+="--api-version <arg> "
#PARAMS+="--output \"${APP_NAME}.prg\" "
#PARAMS+="--project-info \"${PROJECT_INFO}\" "
#PARAMS+="--release "
#PARAMS+="--sdk-version \"${TARGET_SDK_VERSION}\" "
#PARAMS+="--unit-test "
#PARAMS+="--devices \"${DEVICES}\" "
#PARAMS+="--version "
#PARAMS+="--warn "
#PARAMS+="--excludes <arg> "
#PARAMS+="--private-key \"${MB_PRIVATE_KEY}\" "
#PARAMS+="--rez <arg> "
function common_params
{
local -n JUNGLES=$1
#PARAMS+="--sdk-version \"${TARGET_SDK_VERSION}\" "
PARAMS+="--apidb \"${API_DB}\" "
PARAMS+="--import-dbg \"${API_DEBUG}\" "
PARAMS+="--project-info \"${PROJECT_INFO}\" "
PARAMS+="--warn "
JUNGLES=$(printf "%s;" "${JUNGLES[@]}")
JUNGLES=${JUNGLES::-1}
PARAMS+="-f $JUNGLES "
}
function params_for_package
{
common_params JUNGLE_FILES
GIT_VER=$(git describe --long --dirty)
PARAMS+="-o \"${OUT_DIR}/${APP_NAME}-${GIT_VER}.barrel\" "
}
function params_for_build
{
common_params JUNGLE_FILES
PARAMS+="-o \"${OUT_DIR}/${APP_NAME}.barrel\" "
}
function params_for_test
{
common_params TEST_JUNGLE_FILES
PARAMS+="--unit-test "
PARAMS+="-d \"${TARGET_DEVICE}\" "
PARAMS+="-o \"${OUT_DIR}/${APP_NAME}.prg\" "
PARAMS+="--private-key \"${MB_PRIVATE_KEY}\" "
}
function prep_out_dir
{
if [ ! -d "$OUT_DIR" ]; then
mkdir $OUT_DIR
fi
}
function barrel
{
"${MB_HOME}/bin/barrelbuild" ${PARAMS}
}
function build_tests
{
"${MB_HOME}/bin/monkeyc" ${PARAMS}
}
function tests
{
"${MB_HOME}/bin/monkeydo" "${OUT_DIR}/${APP_NAME}.prg" "${TARGET_DEVICE}" -t
}
function clean
{
rm -rf $OUT_DIR
}
function simulator
{
SIM_PID=$(ps aux | grep simulator | grep -v "grep" | grep -v `basename "${0}"` | awk '{print $2}')
[[ ${SIM_PID} ]] && kill ${SIM_PID}
"${MB_HOME}/bin/connectiq" &
}
###
cd ${PROJECT_HOME}
case "${1}" in
build)
prep_out_dir
params_for_build
barrel
;;
package)
prep_out_dir
params_for_package
barrel
;;
test)
prep_out_dir
params_for_test
build_tests
tests
;;
clean)
clean
;;
simulator)
simulator
;;
esac