-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild
executable file
·318 lines (297 loc) · 9.96 KB
/
build
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/bash
#
# Copyright (c) 2020-2025 IAR Systems AB
#
# `build` - builds a container image with the IAR Build Tools (BX)
#
# See LICENSE for detailed license information
#
SCRIPT_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
SCRIPT_NAME=${BASH_SOURCE[0]#./}
SCRIPT_VERSION=2025.02
DOCKER_CONTEXT=${SCRIPT_PATH}
BX_DEFAULT_UBUNTU_VERSION=20.04
BX_DEFAULT_TAG_PREFIX="iarsystems/"
BX_CONTEXT_COPY=0
BX_DEV_CONTEXT_COPY=0
BX_INCLUDE_CMAKE=0
BX_INCLUDE_GIT=0
BX_INCLUDE_SUDO=0
BX_EXCLUDE_CMSIS=0
BX_EXCLUDE_DOCS=0
BX_EXCLUDE_SRC=0
BX_EXCLUDE_JPN_FILES=0
function _bx_show_help() {
echo " "
echo " IAR Container Image Build Utility V${SCRIPT_VERSION}"
echo " Copyright 2020-2025 IAR Systems AB."
echo " "
echo " Usage:"
echo " ${SCRIPT_NAME} -m /path/to/bx<package>.deb [options]"
echo " ${SCRIPT_NAME} -u https://url.to.iar.com/.../bx<package>.deb [options]"
echo " "
echo " Parameter: Description:"
echo " -m, --main-package <file> The main package."
echo " (ex: /path/to/bxarm-9.60.3.deb)"
echo " -u, --url <URL> Download package."
echo " (ex: https://url.to/.../bxarm-9.60.3.deb)"
echo " -h, --help Display help information."
echo " -v, --version Display utility version."
echo " "
echo " Option: Description:"
echo " -p, --device-package <file> The C-SPY device support package."
echo " (ex: /path/to/bxarm-cspy-device-support-9.60.3.deb)"
echo " -b, --base [18|20|22|24] Choose Ubuntu Linux base image LTS version."
echo " (Default: 20)"
echo " -t, --tag <name:version> Create an image with customized tag."
echo " (Default: iarsystems/bx<package>:<version>)"
echo " -z, --no-cache Build a container image from scratch."
echo " "
echo " Experimental: Description:"
echo " -c, --with-cmake Include \`cmake\` in the container image."
echo " -g, --with-git Include \`git\` in the container image."
echo " -r, --with-sudo Include \`sudo\` in the container image."
echo " -q, --no-cmsis Exclude \`arm/CMSIS\` from the container image (up to -129M)."
echo " -n, --no-docs Exclude \`<target>/doc\` from the container image (up to -64M)."
echo " -s, --no-source Exclude \`<target>/src\` from the container image (up to -318M)."
echo " -o, --no-translation Exclude localization files from the container image (up to -25M)."
echo " "
}
function _bx_show_version() {
echo "${SCRIPT_VERSION}"
}
red() { printf "\e[31m"; printf "ERROR: "; reset; }
reset() { printf "\e[0m"; }
yellow() { printf "\e33m"; printf "WARNING: "; reset; }
function _check_curl() {
if ! which curl &> /dev/null; then
red; echo "the -u parameter requires \`curl\` installed."
echo " Install \`curl\` with: sudo apt install curl."
echo " "
exit 1
fi
}
function _check_docker() {
if docker images &> /dev/null; then
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
DOCKER_EXECUTABLE=$(which docker)
echo "-- Using: ${DOCKER_EXECUTABLE} (v${DOCKER_VERSION})..."
DOCKER_CL=$(echo "docker build")
else
red; printf "%s requires \`docker\` for the current user ($USER).\n" "${SCRIPT_NAME}";
echo " Make sure you have it installed:"
echo " curl -fsSL https://get.docker.com -o get-docker.sh"
echo " sh ./get-docker.sh"
echo " sudo usermod -aG docker \$USER"
echo " sudo - \$UESR"
echo " "
exit 1
fi
}
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
red; printf "do not source. %s must be executed directly. (%s -h for help)\n" "${SCRIPT_NAME}" "${SCRIPT_NAME}" >&2
return 1
fi
while [ $# -gt 0 ]; do
case "${1}" in
-h|--help)
_bx_show_help;
exit 0
;;
-v|--version)
_bx_show_version;
exit 0
;;
-m|--main-package)
if [ ! -f "${2}" ]; then
red; echo "expected parameter \`--main-package\`."
echo " File not found \`$2\`. (${SCRIPT_NAME} -h for help)"
exit 1
fi
BX_DEB_PATH=$(dirname ${2})
BX_DEB_FILE=$(basename ${2})
BX_PKG_BASE=${BX_DEB_FILE%.deb}
BX_PKG_NAME=$(echo ${BX_PKG_BASE,,} | cut -d- -f1)
BX_PKG_VERSION=$(echo ${BX_PKG_BASE} | cut -d- -f2)
BX_PKG_PKG=${BX_PKG_NAME#bx}
BX_PKG_ARCH=${BX_PKG_PKG%fs}
if [ ! -f ${DOCKER_CONTEXT}/${BX_DEB_FILE} ]; then
echo " -- Copying \`${BX_DEB_FILE}\` to the context..."
cp ${2} ${DOCKER_CONTEXT}
BX_CONTEXT_COPY=1
fi
shift
;;
-p|--device-package)
if [ ! -f "${2}" ]; then
red; echo "expected parameter \`--device-package\`."
echo " File not found \`$2\`. (${SCRIPT_NAME} -h for help)"
exit 1
fi
BX_DEV_DEB_PATH=$(dirname ${2})
BX_DEV_DEB_FILE=$(basename ${2})
BX_DEV_PKG_BASE=${BX_DEV_DEB_FILE%.deb}
if [ ! -f ${DOCKER_CONTEXT}/${BX_DEV_DEB_FILE} ]; then
echo " -- Copying \`${BX_DEV_DEB_FILE}\` to the context..."
cp ${2} ${DOCKER_CONTEXT}
BX_DEV_CONTEXT_COPY=1
fi
shift
;;
-u|--url)
case "${2}" in
-*|--*|"")
red; echo "expected parameter \`--url\`. (${SCRIPT_NAME} -h for help)."
exit 1
;;
esac
_check_curl;
CURL_DL_PACKAGE_NAME=$(basename ${2})
if [ ! -f "${SCRIPT_PATH}/${CURL_DL_PACKAGE_NAME}" ]; then
echo "-- Downloading: ${CURL_DL_PACKAGE_NAME} (using $(which curl))..."
if ! curl --fail --silent -o ${SCRIPT_PATH}/${CURL_DL_PACKAGE_NAME} "${2}"; then
red; echo "failed to download a package from"
echo " \`${2}\`."
exit 1
fi
fi
if [[ ! ${CURL_DL_PACKAGE_NAME} == *"-cspy-device-support-"* ]]; then
BX_DEB_PATH=${SCRIPT_PATH}
BX_DEB_FILE=${CURL_DL_PACKAGE_NAME}
BX_PKG_BASE=${BX_DEB_FILE%.deb}
BX_PKG_NAME=$(echo ${BX_PKG_BASE,,} | cut -d- -f1)
BX_PKG_VERSION=$(echo ${BX_PKG_BASE} | cut -d- -f2)
BX_PKG_PKG=${BX_PKG_NAME#bx}
BX_PKG_ARCH=${BX_PKG_PKG%fs}
else
BX_DEV_DEB_PATH=${SCRIPT_PATH}
BX_DEV_DEB_FILE=${CURL_DL_PACKAGE_NAME}
BX_DEV_PKG_BASE=${BX_DEV_DEB_FILE%.deb}
fi
shift
;;
-b|--base)
case "$2" in
18|20|22|24)
BX_UBUNTU_VERSION=$2.04
;;
-*|--*)
red; printf "expected parameter \`--base\`. (%s -h for help).\n" "${SCRIPT_NAME}"
exit 1;
;;
*)
yellow; printf "check the system requirements for the chosen package (ubuntu:%s).\n" "${2}"
;;
esac
shift
;;
-t|--tag)
case "$2" in
-*|--*|"")
red; echo "expected parameter \`--tag\`. (${SCRIPT_NAME} -h for help)."
exit 1
;;
*)
BX_USER_TAG="$2"
;;
esac
shift
;;
-z|--no-cache)
DOCKER_CL_NOCACHE=--no-cache
;;
-c|--with-cmake)
BX_INCLUDE_CMAKE=1
;;
-g|--with-git)
BX_INCLUDE_GIT=1
;;
-r|--with-sudo)
BX_INCLUDE_SUDO=1
;;
-q|--no-cmsis)
BX_EXCLUDE_CMSIS=1
;;
-n|--no-docs)
BX_EXCLUDE_DOCS=1
;;
-s|--no-source)
BX_EXCLUDE_SRC=1
;;
-o|--no-translation)
BX_EXCLUDE_JPN_FILES=1
;;
-*|--*|*)
red; echo "illegal option \`${1}\`. (${SCRIPT_NAME} -h for help)" >&2
exit 1
;;
esac
shift $(( $# > 0 ? 1 : 0))
done
function _bx_build_docker_image() {
if [ -z "${BX_PKG_NAME}" ]; then
red; echo "insufficient parameters. (${SCRIPT_NAME} -h for help)" >&2
exit 1
fi
if [ -z "${BX_USER_TAG}" ]; then
BX_USER_TAG="iarsystems/${BX_PKG_NAME}:${BX_PKG_VERSION}"
fi
if [ -z "${BX_UBUNTU_VERSION}" ]; then
BX_UBUNTU_VERSION=${BX_DEFAULT_UBUNTU_VERSION}
fi
if [ ! -z "${BX_DEV_PKG_BASE}" ]; then
echo "-- C-SPY Device support package selected: \`${BX_DEV_DEB_PATH}/${BX_DEV_DEB_FILE}\`..."
fi
_check_docker;
case ${BX_PKG_ARCH} in
avr)
BX_ASM_EXEC=a
;;
arm|rh850|riscv|rl78|rx)
BX_ASM_EXEC=iasm
;;
esac
case ${BX_PKG_ARCH} in
arm|avr|rh850|riscv|rl78|rx)
echo "-- Building the container image \`${BX_USER_TAG}\` (using base image: \`ubuntu:${BX_UBUNTU_VERSION}\`)..."
${DOCKER_CL} ${DOCKER_CL_NOCACHE} \
--build-arg BX_UBUNTU_VERSION=${BX_UBUNTU_VERSION} \
--build-arg BX_DEB_FILE=${BX_DEB_FILE} \
--build-arg BX_DEV_DEB_FILE=${BX_DEV_DEB_FILE} \
--build-arg BX_PKG_ARCH=${BX_PKG_ARCH} \
--build-arg BX_ASM_EXEC=${BX_ASM_EXEC} \
--build-arg BX_INCLUDE_CMAKE=${BX_INCLUDE_CMAKE} \
--build-arg BX_INCLUDE_GIT=${BX_INCLUDE_GIT} \
--build-arg BX_INCLUDE_SUDO=${BX_INCLUDE_SUDO} \
--build-arg BX_EXCLUDE_CMSIS=${BX_EXCLUDE_CMSIS} \
--build-arg BX_EXCLUDE_DOCS=${BX_EXCLUDE_DOCS} \
--build-arg BX_EXCLUDE_SRC=${BX_EXCLUDE_SRC} \
--build-arg BX_EXCLUDE_JPN_FILES=${BX_EXCLUDE_JPN_FILES} \
--tag ${BX_USER_TAG} \
${DOCKER_CONTEXT}
;;
*)
red; echo "unrecognized package \`${BX_DEB_FILE}\`. (${SCRIPT_NAME} -h for help)" >&2
exit 1
;;
esac
}
_bx_build_docker_image
#
# >>> Cleanup
#
# If copied, erase temporary context's copy
#
if [ ${BX_CONTEXT_COPY} -eq 1 ]; then
echo "-- Erasing temporary copy: \`${BX_DEB_FILE}\`."
rm ${DOCKER_CONTEXT}/${BX_DEB_FILE} > /dev/null
fi
if [ ${BX_DEV_CONTEXT_COPY} -eq 1 ]; then
echo "-- Erasing temporary copy: \`${BX_DEV_DEB_FILE}\`."
rm ${DOCKER_CONTEXT}/${BX_DEV_DEB_FILE} > /dev/null
fi
#
# Show image creation summary
#
echo "-- Summary:"
docker images ${BX_USER_TAG}