Duplicate build environment variable in .BUILDINFO
Description:
While examining the reproducibility of packages such as python-fakeredis
, I noticed that the !check
buildenv variable is duplicated in the .BUILDINFO
file, as seen in this diffoscope output. This duplication occurs when repro
or makerepropkg
create a makepkg.conf
from the .BUILDINFO
file and the !check
buildenv is appended again while sourcing the PKGBUILD
. This results in a duplicate !check
entry in the rebuilt package's .BUILDINFO
file.
Though the last occurrence of a buildenv is the one considered, having duplicate entries in the .BUILDINFO
file seems unnecessary and could potentially lead to confusion.
I've talked about this issue in the #archlinux-reproducible
IRC channel and it was agreed that this is a bug. However, it was also pointed out that package maintainers should not be disabling checks by adding the !check
buildenv in the PKGBUILD
.
Proposed Solution:
To prevent this duplication, package maintainers could comment out the check()
function instead of adding the !check
buildenv. However, as there are no restrictions on maintainers using the buildenv, I propose the addition of a clean_buildenv
function in the makepkg
script to remove duplicate entries while preserving the last occurrence of each variable in the BUILDENV
array.
Here's the suggested function:
clean_buildenv() {
for i in "${!BUILDENV[@]}"; do
REV_BUILDENV[i]=${BUILDENV[-i-1]}
done
declare -A map
TEMP_BUILDENV=()
for key in "${REV_BUILDENV[@]}"; do
if [[ -z "${map[$key]}" ]]; then
TEMP_BUILDENV+=("$key")
map["$key"]=1
fi
done
unset BUILDENV
for i in "${!TEMP_BUILDENV[@]}"; do
BUILDENV[i]=${TEMP_BUILDENV[-i-1]}
done
}
This function reverses the BUILDENV
array, adds its entries to a map (skipping duplicates), and then reverses the array again, restoring the original order but without any duplicates. By including this function in the makepkg
script, we can ensure the BUILDENV
array is clean and free of unnecessary duplicate entries.