-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-repo.sh
executable file
·399 lines (328 loc) · 9.89 KB
/
build-repo.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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#!/bin/sh
set -e
umask ${UMASK:-0000}
sudo chmod a+rwx \
/var/cache/apk \
${CCACHE_DIR} \
${HOME}/.ros \
${HOME}/.ros/rosdep
build_subdir=abuild
# Validate environment variables
case "${FORCE_LOCAL_VERSION}" in
"")
FORCE_LOCAL_VERSION=no
;;
yes)
;;
no)
;;
*)
echo "FORCE_LOCAL_VERSION must be one of: \"yes\", \"no\", \"\" (default: \"no\")"
exit 1
;;
esac
case "${VERSION_PER_SUBPACKAGE}" in
"")
VERSION_PER_SUBPACKAGE=no
;;
yes)
;;
full)
;;
no)
;;
*)
echo "VERSION_PER_SUBPACKAGE must be one of:"
echo " \"yes\": versioned based on the latest commit of the subpackage (merge commit is ignored)"
echo " \"full\": versioned based on the latest commit of the subpackage (including merge commit)"
echo " \"no\": versioned based on the latest commit of the repository"
echo " \"\": use default (\"no\")"
exit 1
;;
esac
case "${ENABLE_CCACHE}" in
"")
ENABLE_CCACHE=no
;;
yes)
;;
no)
;;
*)
echo "ENABLE_CCACHE must be one of: \"yes\", \"no\", \"\" (default: \"no\")"
exit 1
;;
esac
case "${SKIP_ROSDEP_UPDATE}" in
"")
SKIP_ROSDEP_UPDATE=false
;;
yes|true)
SKIP_ROSDEP_UPDATE=true
;;
no|false)
SKIP_ROSDEP_UPDATE=false
;;
*)
echo "SKIP_ROSDEP_UPDATE must be one of: \"yes\", \"no\", \"\" (default: \"no\")"
# Accept true/false as well for backward compatibility.
exit 1
;;
esac
generate_opts=
case "${ALPINE_VERSION}" in
3.20)
generate_opts="${generate_opts} --split-dev"
;;
*)
;;
esac
echo "generate_opts: ${generate_opts}"
# Setup environment variables
if [ ! -z "${JOBS}" ]; then
sudo sed -i "s/export JOBS=.*/export JOBS=${JOBS}/" /etc/abuild.conf
fi
sudo sed -i 's/export MAKEFLAGS=.*/export MAKEFLAGS="-j$JOBS -l$JOBS"/' /etc/abuild.conf
if [ ! -z "${CFLAGS}" ]; then
echo "Overwriting CFLAGS"
echo "original:"
echo "---"
head -n 4 /etc/abuild.conf
sudo sed -i "s/export CFLAGS=\"-Os -fomit-frame-pointer\"/export CFLAGS=\"${CFLAGS}\"/" /etc/abuild.conf
echo "---"
echo "updated:"
echo "---"
head -n 4 /etc/abuild.conf
echo "---"
echo
fi
if [ ${ENABLE_CCACHE} = "yes" ]
then
echo "ccache enabled (cache dir: ${CCACHE_DIR})"
export CC=/usr/lib/ccache/bin/gcc
export CXX=/usr/lib/ccache/bin/g++
fi
repo=${ROS_DISTRO}
if [ ! -f "${PACKAGER_PRIVKEY}" ]; then
abuild-keygen -a -i -n
# Re-sign packages if private key is updated
index=$(find ${REPODIR} -name APKINDEX.tar.gz || true)
if [ -f "${index}" ]; then
rm -f ${index}
apk index -o ${index} $(find $(dirname ${index}) -name '*.apk')
abuild-sign -k /home/builder/.abuild/*.rsa ${index}
fi
fi
mkdir -p ${APORTSDIR}/${repo}
mkdir -p ${REPODIR}
mkdir -p ${LOGDIR}
extsrc=${HOME}/extsrc
mkdir -p ${extsrc}
summary_file=${LOGDIR}/summary.log
full_log_file=${LOGDIR}/full.log
apk_list_file=${LOGDIR}/apk_list.log
case "${VERSION_PER_SUBPACKAGE}" in
"yes")
echo "VERSION_PER_SUBPACKAGE: enabled"
commit_date_option="."
ext_pkg_option=
;;
"full")
echo "VERSION_PER_SUBPACKAGE: enabled (including merge commit)"
commit_date_option="--full-history ."
ext_pkg_option=
;;
*)
commit_date_option=
ext_pkg_option="--shallow"
;;
esac
# Update repositories
if [ "${DISABLE_DEFAULT_ALPINE_ROS_REPOS}" = yes ]; then
sudo sed '/^http:\/\/alpine-ros\.seqsense\.org/d' -i /etc/apk/repositories
echo "NOTE: Default Alpine ROS repositories are disabled. You need to set them by CUSTOM_APK_REPO."
fi
if [ ! -z "${CUSTOM_APK_REPOS}" ]; then
for r in ${CUSTOM_APK_REPOS}; do
echo "CUSTOM_APK_REPO: ${r}"
echo $r | sudo tee -a /etc/apk/repositories
done
fi
echo "${REPODIR}/${repo}" | sudo tee -a /etc/apk/repositories
echo "/etc/apk/repositories"
echo "---"
cat /etc/apk/repositories
echo "---"
sudo apk update
if [ ! -f ${HOME}/.ros/rosdep/sources.cache/index ] || ! ${SKIP_ROSDEP_UPDATE:-false}; then
rosdep update
fi
# Clone packages if .rosinstall is provided
ext_deps=$(find ${SRCDIR} -name "*.rosinstall" || true)
for dep in ${ext_deps}; do
# skip empty and all commented out .rosinstall files
if [ $(cat ${dep} | sed '/^\s*#/d;/^\s*$/d' | wc -l) -eq 0 ]; then
echo "Skipping ${dep}: no repository found"
continue
fi
if ! vcs validate --input ${dep}; then
echo "${dep} is invalid"
exit 1
fi
vcs import --input ${dep} ${ext_pkg_option} ${VCS_OPTIONS} --workers 4 ${extsrc}
done
# Allow to handle git repositories owned by outer container user
for dir in $(find ${SRCDIR} -name ".git" -type d); do
git config --global --add safe.directory $(dirname ${dir})
done
# Generate APKBUILDs
error=false
manifests="$(find ${SRCDIR} -name "package.xml") $(find ${extsrc} -name "package.xml")"
for manifest in ${manifests}; do
echo +++++++++++++++++++++++++
echo "manifest: ${manifest}"
pkgpath=$(dirname ${manifest})
pkgname=$(basename ${pkgpath})
echo "latest commit:"
git_log_opts="-n1 HEAD ${commit_date_option}"
git --no-pager -C ${pkgpath} log ${git_log_opts} || true
echo
commit_date=$(git --no-pager -C ${pkgpath} log \
--format=%ad \
--date=format-local:'%Y%m%d%H%M%S' ${git_log_opts} || true)
if [ -n "${commit_date}" ]
then
ver_suffix="_git${commit_date}"
else
ver_suffix="_alpha$(date +'%Y%m%d%H%M%S')"
fi
# Copy files with filter
mkdir -p ${APORTSDIR}/${repo}/${pkgname}
files=$(ls -1A ${pkgpath})
for file in ${files}; do
if [ $file = ".git" ]; then continue; fi
cp -r ${pkgpath}/${file} ${APORTSDIR}/${repo}/${pkgname}/${file}
done
if ! (set -o pipefail && generate-rospkg-apkbuild \
${repo} ${APORTSDIR}/${repo}/${pkgname}/package.xml --src \
--ver-suffix=${ver_suffix} \
${generate_opts} \
| tee ${APORTSDIR}/${repo}/${pkgname}/APKBUILD); then
echo "## Package dependency failure" >> ${summary_file}
error=true
fi
done
rm -f $(find ${APORTSDIR} -name "ros-abuild-build.log")
rm -f $(find ${APORTSDIR} -name "ros-abuild-check.log")
rm -f $(find ${APORTSDIR} -name "ros-abuild-status.log")
# Tweak version constraints
if [ "${FORCE_LOCAL_VERSION}" = "yes" ]; then
echo "FORCE_LOCAL_VERSION: enabled"
# Find all package versions
apkbuilds="$(find ${APORTSDIR} -name "APKBUILD")"
for apkbuild in ${apkbuilds}; do
pkgname=$(. ${apkbuild}; echo "${pkgname}")
pkgver=$(. ${apkbuild}; echo "${pkgver}")
pkgrel=$(. ${apkbuild}; echo "${pkgrel}")
# Specify package versions
for apkbuild_subst in ${apkbuilds}; do
sed \
"/depends=/!b end; s/\([ \t\"']\)${pkgname}\([ \t\"']\)/\1${pkgname}=${pkgver}-r${pkgrel}\2/g; :end" \
-i ${apkbuild_subst}
done
done
echo
echo "Tweaked APKBUILD dependencies:"
grep -r "depends=" ${APORTSDIR}
echo
fi
# Build everything
GENERATE_BUILD_LOGS=yes buildrepo -k -d ${REPODIR} -a ${APORTSDIR} ${repo} 2>&1 | tee ${full_log_file}
# Summarize build result
function summarize_error() {
error_text=$(grep -A5 -i -E "$2" $1 || true)
lines=$(echo -n "${error_text}" | wc -l)
# print summary
if [ ${lines} -lt 1 ]; then
echo 'no build error detected'
else
echo "${error_text}" | head -n30
if [ ${lines} -gt 30 ]; then
echo "error log exceeded 30 lines (total ${lines} lines)"
fi
fi
}
rm -f ${summary_file} ${apk_list_file}
echo "## Summary" >> ${summary_file}
echo '```' >> ${summary_file}
tail -n6 ${full_log_file} >> ${summary_file}
echo '```' >> ${summary_file}
for manifest in ${manifests}; do
srcpath=$(dirname ${manifest})
pkgname=$(basename ${srcpath})
pkgpath=${APORTSDIR}/${repo}/${pkgname}
apk_filename=$(. ${pkgpath}/APKBUILD; echo "${pkgname}-${pkgver}-r${pkgrel}.apk")
echo >> ${summary_file}
echo "## $pkgname" >> ${summary_file}
echo "**${apk_filename}**" >> ${summary_file}
echo "${apk_filename}" >> ${apk_list_file}
if [ ! -f ${pkgpath}/${build_subdir}/ros-abuild-status.log ]; then
if [ -f ${REPODIR}/${repo}/*/${apk_filename} ]; then
echo "Already been built." >> ${summary_file}
else
echo "Failed to start build. The package might have unsatisfied dependencies." >> ${summary_file}
error=true
fi
continue
fi
if grep "finished" ${pkgpath}/${build_subdir}/ros-abuild-status.log > /dev/null; then
echo "Build succeeded." >> ${summary_file}
if grep "Check skipped" ${pkgpath}/${build_subdir}/ros-abuild-check.log > /dev/null; then
echo "(NOCHECK)" >> ${summary_file}
fi
if [ ! -f ${REPODIR}/${repo}/*/${apk_filename} ]; then
echo "Failed to generate package." >> ${summary_file}
error=true
fi
continue
fi
error=true
echo "### Build log" >> ${summary_file}
if [ ! -f ${pkgpath}/${build_subdir}/ros-abuild-build.log ]; then
echo "Build log not found" >> ${summary_file}
continue
fi
echo "\`\`\`" >> ${summary_file}
summarize_error ${pkgpath}/${build_subdir}/ros-abuild-build.log "error" >> ${summary_file}
echo "\`\`\`" >> ${summary_file}
if [ -f ${pkgpath}/${build_subdir}/ros-abuild-check.log ]; then
echo "### Check log" >> ${summary_file}
echo '```' >> ${summary_file}
summarize_error ${pkgpath}/${build_subdir}/ros-abuild-check.log "(error|failure)" >> ${summary_file}
echo '```' >> ${summary_file}
continue
fi
done
# Extract dependency error logs
dep_errors=$(sed -n '/^ERROR: unable to select packages/{p; :loop; n; /^\s/{p; b loop}; /^>>>/{b loop}}' ${full_log_file})
dep_error_lines=$(echo -n "${dep_errors}" | wc -l)
echo "${dep_error_lines}"
if [ ${dep_error_lines} -gt 0 ]; then
echo >> ${summary_file}
echo '---' >> ${summary_file}
echo >> ${summary_file}
echo "## Dependency logs" >> ${summary_file}
if [ ${dep_error_lines} -gt 50 ]; then
echo "error log exceeded 50 lines (total ${lines} lines)" >> ${summary_file}
fi
echo '```' >> ${summary_file}
echo "${dep_errors}" | head -n50 >> ${summary_file}
echo '```' >> ${summary_file}
fi
echo
echo "---"
cat ${summary_file}
if [ $error != "false" ]; then
exit 1
fi
exit 0