debugflags: ensure to only append debug flags once when building
During a package build we call prepare_buildenv in multiple stages of the process. For debug packages, one of the hooks is buildenv_debugflags which populates the debug flags to the according variables. The issue is that the behavior of the current implementation of buildenv_debugflags is not idempotent, so consecutive calls will append the same flags again. In certain cases this isn't an issue, however for context aware build frontends like cargo any change of the build inputs leads to a fresh build. This means that any invocation of such a build ecosystem inside the package() function will trigger a full rebuild, which is not desired. To fix this issue, this commit makes buildenv_debugflags idempotent by only appending flags once to the target variables. Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
parent
0108e2c64e
commit
18e49f2c97
4 changed files with 22 additions and 9 deletions
|
@ -25,14 +25,15 @@ LIBMAKEPKG_BUILDENV_DEBUGFLAGS_SH=1
|
||||||
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
||||||
|
|
||||||
source "$MAKEPKG_LIBRARY/util/option.sh"
|
source "$MAKEPKG_LIBRARY/util/option.sh"
|
||||||
|
source "$MAKEPKG_LIBRARY/util/util.sh"
|
||||||
|
|
||||||
buildenv_functions+=('buildenv_debugflags')
|
buildenv_functions+=('buildenv_debugflags')
|
||||||
|
|
||||||
buildenv_debugflags() {
|
buildenv_debugflags() {
|
||||||
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
|
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
|
||||||
DEBUG_CFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
append_once DEBUG_CFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
||||||
DEBUG_CXXFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
append_once DEBUG_CXXFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
||||||
CFLAGS+=" $DEBUG_CFLAGS"
|
append_once CFLAGS "$DEBUG_CFLAGS"
|
||||||
CXXFLAGS+=" $DEBUG_CXXFLAGS"
|
append_once CXXFLAGS "$DEBUG_CXXFLAGS"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,15 @@ LIBMAKEPKG_BUILDENV_LTO_SH=1
|
||||||
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
||||||
|
|
||||||
source "$MAKEPKG_LIBRARY/util/option.sh"
|
source "$MAKEPKG_LIBRARY/util/option.sh"
|
||||||
|
source "$MAKEPKG_LIBRARY/util/util.sh"
|
||||||
|
|
||||||
build_options+=('lto')
|
build_options+=('lto')
|
||||||
buildenv_functions+=('buildenv_lto')
|
buildenv_functions+=('buildenv_lto')
|
||||||
|
|
||||||
buildenv_lto() {
|
buildenv_lto() {
|
||||||
if check_option "lto" "y" && ! check_option "buildflags" "n"; then
|
if check_option "lto" "y" && ! check_option "buildflags" "n"; then
|
||||||
CFLAGS+=" ${LTOFLAGS:--flto}"
|
append_once CFLAGS "${LTOFLAGS:--flto}"
|
||||||
CXXFLAGS+=" ${LTOFLAGS:--flto}"
|
append_once CXXFLAGS "${LTOFLAGS:--flto}"
|
||||||
LDFLAGS+=" ${LTOFLAGS:--flto}"
|
append_once LDFLAGS "${LTOFLAGS:--flto}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,14 @@ LIBMAKEPKG_BUILDENV_RUST_SH=1
|
||||||
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
||||||
|
|
||||||
source "$MAKEPKG_LIBRARY/util/option.sh"
|
source "$MAKEPKG_LIBRARY/util/option.sh"
|
||||||
|
source "$MAKEPKG_LIBRARY/util/util.sh"
|
||||||
|
|
||||||
buildenv_var+=('RUSTFLAGS' 'DEBUG_RUSTFLAGS')
|
buildenv_var+=('RUSTFLAGS' 'DEBUG_RUSTFLAGS')
|
||||||
buildenv_functions+=('buildenv_rust')
|
buildenv_functions+=('buildenv_rust')
|
||||||
|
|
||||||
buildenv_rust() {
|
buildenv_rust() {
|
||||||
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
|
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
|
||||||
DEBUG_RUSTFLAGS+=" --remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
append_once DEBUG_RUSTFLAGS "--remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
||||||
RUSTFLAGS+=" $DEBUG_RUSTFLAGS"
|
append_once RUSTFLAGS "$DEBUG_RUSTFLAGS"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
|
@ -112,3 +112,13 @@ source_safe() {
|
||||||
|
|
||||||
eval "$shellopts"
|
eval "$shellopts"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Append a string to a variable if the value is not already contained.
|
||||||
|
# usage : append_once( $ref, $value )
|
||||||
|
append_once() {
|
||||||
|
local -n var=$1
|
||||||
|
local value=$2
|
||||||
|
if [[ ! $var =~ (^| )"$value"($| ) ]]; then
|
||||||
|
var+=" $value"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue