@@ -194,6 +194,46 @@ function get_package_release_version {
194194 echo " $version -$offset$DEB_DISTRO "
195195}
196196
197+ # common cleanup tasks after building a package
198+ function common_cleanup {
199+ local exit_code=$1
200+ local deb_pkg_name=$2
201+ local src_folder=${3:- ..}
202+
203+ ici_label pwd
204+ ici_label ls -1lt ..
205+ ici_label ls -1lt ../log
206+ ici_label ls -1lt " $DEBS_PATH "
207+
208+ # # Rename .build log file, which has invalid characters (:) for artifact upload
209+ local log;
210+ # shellcheck disable=SC2010
211+ log=$( ls -1t " $DEBS_PATH /$( deb_pkg_name " ${pkg_name} " ) *.build" | grep -P ' (?<!Z)\.build' | head -1)
212+ ici_log " log file: $log $( readlink -f " $log " ) "
213+ mv " $( readlink -f " $log " ) " " ${log/ .build/ .log} " # rename actual log file
214+ rm -f " $log " # remove symlink
215+
216+ if [ " $exit_code " != 0 ] ; then
217+ # remove source files if the build failed
218+ rm -f " $src_folder " /* .{dsc,tar.* }
219+ return " $exit_code "
220+ fi
221+ # Move .dsc + .tar.* files from src_folder to $DEBS_PATH for deployment
222+ mv " $src_folder " /* .{dsc,tar.* } " $DEBS_PATH "
223+
224+ BUILT_PACKAGES+=(" $(( idx+ 1 )) /$total $deb_pkg_name : $( source_link " ${version% " $DEB_DISTRO " } " ) " )
225+
226+ if [ " $INSTALL_TO_CHROOT " == " true" ]; then
227+ ici_color_output BOLD " Install package within chroot"
228+ # shellcheck disable=SC2012
229+ cat << - EOF | "${APT_QUIET[@]} " ici_pipe_into_schroot sbuild-rw
230+ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -q -y \$ (ls -1 -t /build/repo/"$deb_pkg_name "*.deb | head -1)
231+ EOF
232+ fi
233+
234+ ici_label update_repo
235+ }
236+
197237function build_pkg {
198238 local old_path=$PWD
199239 local pkg_name=$1
@@ -217,8 +257,6 @@ function build_pkg {
217257 rosdep install --os=" $DISTRIBUTION :$DEB_DISTRO " --simulate -t build -t buildtool_export -t buildtool -t build_export -t exec --from-paths . > /dev/null || return 2
218258 ici_label " ${BLOOM_QUIET[@]} " bloom-generate " ${BLOOM_GEN_CMD} " --os-name=" $DISTRIBUTION " --os-version=" $DEB_DISTRO " --ros-distro=" $ROS_DISTRO " --skip-test-dependencies --skip-pip || return 2
219259
220- trap ' rm -f ../*.dsc ../*.tar.gz; cd "$old_path"' RETURN # cleanup on build failure
221-
222260 # Enable CATKIN_INSTALL_INTO_PREFIX_ROOT for catkin package
223261 if [ " $pkg_name " = " catkin" ]; then
224262 sed -i ' s@-DCATKIN_BUILD_BINARY_PACKAGE="1"@-DCATKIN_INSTALL_INTO_PREFIX_ROOT="1"@' debian/rules
@@ -241,9 +279,6 @@ function build_pkg {
241279 debchange -v " $version_stamped " \
242280 --preserve -m " Append timestamp when binarydeb was built." || return 3
243281
244- local version_link; version_link=$( source_link " ${version% " $DEB_DISTRO " } " ) || true
245- rm -rf .git
246-
247282 # Fetch sbuild options from .repos yaml file
248283 opts=" "
249284 if [ -f " $WS_SOURCE " ]; then
@@ -255,54 +290,8 @@ function build_pkg {
255290
256291 ici_log
257292 SBUILD_OPTS=" --verbose --chroot=sbuild --no-clean-source --no-run-lintian --dist=$DEB_DISTRO $opts "
258- ici_label " ${SBUILD_QUIET[@]} " ici_asroot -E -H -u " $USER " bash -lc " sbuild $SBUILD_OPTS " || return 4
259-
260- " ${CCACHE_QUIET[@]} " ici_label ccache -sv || return 1
261- BUILT_PACKAGES+=(" $(( idx+ 1 )) /$total $( deb_pkg_name " $pkg_name " ) : $version_link " )
262-
263- if [ " $INSTALL_TO_CHROOT " == " true" ]; then
264- ici_color_output BOLD " Install package within chroot"
265- # shellcheck disable=SC2012
266- cat << - EOF | "${APT_QUIET[@]} " ici_pipe_into_schroot sbuild-rw
267- DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -q -y \$ (ls -1 -t /build/repo/"$( deb_pkg_name " $pkg_name " ) "*.deb | head -1)
268- EOF
269- fi
270- # Move .dsc + .tar.gz files from workspace folder to $DEBS_PATH for deployment
271- mv ../* .dsc ../* .tar.gz " $DEBS_PATH "
272- trap ' cd "$old_path"' RETURN # cleanup on return
273-
274- # # Rename .build log file, which has invalid characters (:) for artifact upload
275- local log;
276- # shellcheck disable=SC2010
277- log=$( ls -1t " $DEBS_PATH /$( deb_pkg_name " ${pkg_name} " " $version_stamped " ) _" * .build | grep -P ' (?<!Z)\.build' | head -1)
278- mv " $( readlink -f " $log " ) " " ${log/ .build/ .log} " # rename actual log file
279- rm " $log " # remove symlink
280-
281- ici_label update_repo
282- }
283-
284- function get_git_release_version {
285- local version
286- local sha
287- local offset=" 0"
288-
289- git rev-parse --is-inside-work-tree & > /dev/null || return 1
290-
291- # Get version from preceding tag, stripping any prefix or suffix not contributing to x.y.z version string
292- version=$( git describe --tags --abbrev=0 2> /dev/null | sed -E ' s@^.*?[^0-9]([0-9]+\.[0-9]+\.[0-9]+).*$@\1@' )
293- if [ -n " $version " ]; then
294- # Get sha from this tag
295- sha=$( git rev-list --tags --max-count=1)
296- else # no tag available
297- # extract sha + version from latest version-like commit message instead
298- version=$( git log --pretty=format:' %h %s' | grep -E " ^.*?[^0-9]([0-9]+\.[0-9]+\.[0-9]+).*$" | head -n 1)
299- sha=$( echo " $version " | awk ' {print $1}' )
300- version=$( echo " $version " | sed -E ' s@^.*?[^0-9]([0-9]+\.[0-9]+\.[0-9]+).*$@\1@' )
301- fi
302- # commit offset from version to HEAD
303- offset=" $( git rev-list --count " $sha " ..HEAD) "
304-
305- echo " $version -$offset$DEB_DISTRO "
293+ ici_label " ${SBUILD_QUIET[@]} " ici_asroot -E -H -u " $USER " bash -lc " sbuild $SBUILD_OPTS "
294+ common_cleanup $? " $( deb_pkg_name " $pkg_name " ) "
306295}
307296
308297function sbuild_pkg {
@@ -328,9 +317,6 @@ function sbuild_pkg {
328317 debchange --create --package " $deb_pkg_name " -v " $version_stamped " \
329318 --preserve -m " $deb_pkg_name ${version% " $DEB_DISTRO " } release" || return 3
330319
331- local version_link; version_link=$( source_link " ${version% " $DEB_DISTRO " } " ) || true
332- rm -rf .git
333-
334320 # Fetch sbuild options from .repos yaml file
335321 opts=" "
336322 if [ -f " $WS_SOURCE " ]; then
@@ -343,21 +329,7 @@ function sbuild_pkg {
343329 ici_log
344330 SBUILD_OPTS=" --verbose --chroot=sbuild --no-clean-source --no-run-lintian --dist=$DEB_DISTRO $opts "
345331 ici_label " ${SBUILD_QUIET[@]} " ici_asroot -E -H -u " $USER " bash -lc " sbuild $SBUILD_OPTS " || return 4
346-
347- " ${CCACHE_QUIET[@]} " ici_label ccache -sv || return 1
348- BUILT_PACKAGES+=(" $(( idx+ 1 )) /$total $deb_pkg_name : $version_link " )
349-
350- if [ " $INSTALL_TO_CHROOT " == " true" ]; then
351- ici_color_output BOLD " Install package within chroot"
352- # shellcheck disable=SC2012
353- cat << - EOF | "${APT_QUIET[@]} " ici_pipe_into_schroot sbuild-rw
354- DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -q -y \$ (ls -1 -t /build/repo/"$( deb_pkg_name " $pkg_name " ) "*.deb | head -1)
355- EOF
356- fi
357- # Move .dsc + .tar.gz files from workspace folder to $DEBS_PATH for deployment
358- mv ../* .dsc ../* .tar.gz " $DEBS_PATH "
359-
360- ici_label update_repo
332+ common_cleanup $? " $deb_pkg_name "
361333}
362334
363335function get_python_release_version {
@@ -397,17 +369,13 @@ function build_python_pkg {
397369 local deb_pkg_name; deb_pkg_name=" python3-$( python3 setup.py --name) "
398370 pkg_exists " $deb_pkg_name " " $version " && return
399371
400- local version_link; version_link=$( source_link " ${version% " $DEB_DISTRO " } " ) || true
401- rm -rf .git
402-
403372 ici_label " ${SBUILD_QUIET[@]} " python3 setup.py --command-packages=stdeb.command sdist_dsc --debian-version " $debian_version " bdist_deb || return 4
373+ local err=$?
404374
405- BUILT_PACKAGES+=(" $(( idx+ 1 )) /$total $deb_pkg_name : $version_link " )
406-
407- # Move created files to $DEBS_PATH for deployment
408- mv deb_dist/* .dsc deb_dist/* .tar.? z deb_dist/* .deb deb_dist/* .changes deb_dist/* .buildinfo " $DEBS_PATH "
375+ # Move created files (except source distro) to $DEBS_PATH for deployment
376+ mv deb_dist/* .deb deb_dist/* .changes deb_dist/* .buildinfo " $DEBS_PATH "
409377
410- ici_label update_repo
378+ common_cleanup " $err " " $deb_pkg_name " deb_dist
411379}
412380
413381function known_to_fail {
0 commit comments