From 53aa04647694a52cb44c9857602089416d997930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 30 Oct 2024 14:10:51 +0100 Subject: [PATCH] build: add a retry build mechanism on `make` in Debian packaging When the environment variable `RETRY_BUILD` is set to `1`, the file `debian/rules` is patched to run `dh_auto_build` multiple times, until the build succeeds. This is a workaround for an issue with the build in an arm64 chroot, where the compiler randomly segfaults. --- tools/build_debian.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/build_debian.sh b/tools/build_debian.sh index 5fb834d08..a10276f49 100755 --- a/tools/build_debian.sh +++ b/tools/build_debian.sh @@ -51,6 +51,10 @@ # PACKAGER_EMAIL E-mail of packager (for debian/changelog) # JOBS Number of simultaneous jobs (for dpkg-buildpackage) # (numeric or "auto" for dpkg >= 1.17.10) +# RETRY_BUILD Retry build with `make` multiple times in case of failure +# (default is 0: do not retry and exit with error); +# when set, this patches the file debian/rules to run +# dh_auto_build multiple times in case of failure # set -o errexit @@ -59,6 +63,7 @@ set -o errexit default_packager_name="Sébastien Helleu" default_packager_email="flashcode@flashtux.org" default_jobs="" +default_retry_build="0" usage () { @@ -132,6 +137,9 @@ fi # simultaneous jobs for compilation (dpkg-buildpackage -jN) [ -z "${JOBS}" ] && JOBS="${default_jobs}" +# retry build +[ -z "${RETRY_BUILD}" ] && RETRY_BUILD="${default_retry_build}" + # check git repository root_dir=$(git rev-parse --show-toplevel) if [ -z "${root_dir}" ] || [ ! -e "${root_dir}/.git" ] || [ ! -d "${root_dir}/debian-stable" ]; then @@ -244,6 +252,16 @@ fi echo " - Updating changelog: ${DEB_NAME} ${DEB_VERSION} (${DCH_DISTRO}, ${DCH_URGENCY}), ${PACKAGER_NAME} <${PACKAGER_EMAIL}>: ${DCH_CHANGELOG}" DEBFULLNAME="${PACKAGER_NAME}" DEBEMAIL="${PACKAGER_EMAIL}" dch "${DCH_CREATE}" --package "${DEB_NAME}" --newversion "${DEB_VERSION}" --distribution "${DCH_DISTRO}" --urgency "${DCH_URGENCY}" "${DCH_CHANGELOG}" +# if retry build is enabled, patch debian/rules to run dh_auto_build +# multiple times if needed +if [ "${RETRY_BUILD}" != "0" ]; then + cat <> debian/rules + +override_dh_auto_build: + dh_auto_build || dh_auto_build || dh_auto_build || dh_auto_build || dh_auto_build || dh_auto_build +EOF +fi + # build packages (without debug symbols) DEB_BUILD_OPTIONS="noddebs" dpkg-buildpackage -us -uc --jobs="${JOBS}"