python-rpm-macros/brp-fix-pyc-reproducibility
Zbigniew Jędrzejewski-Szmek 1cf0ae1d4e brp-fix-pyc-reproducibility: suppress python2 files and errors
When %{py_reproducible_pyc_path} is used explicitly, then error our if
marshalparser returns an error. But when running in the automatic mode, only
warn. marshalparser fails for example for python2 pyc files.

Also, filter out the python2.7 directory. In Fedora, it's the major and only
source of python2 pyc files and it doesn't make much sense to try to do anything
with them.
2024-03-11 21:50:15 +01:00

43 lines
984 B
Bash

#!/bin/bash -eu
# If using normal root, avoid changing anything.
if [ -z "${RPM_BUILD_ROOT:-}" ] || [ "${RPM_BUILD_ROOT:-}" = "/" ]; then
exit 0
fi
automatic=
if [ "${1:?}" = "-a" ]; then
automatic=yes
shift
fi
path_to_fix=${1:?}
# First, check that the parser is available:
if [ ! -x /usr/bin/marshalparser ]; then
if [ -n "$automatic" ]; then
echo "WARNING: marshalparser is not installed"
exit 0
else
echo "ERROR: marshalparser is not installed"
exit 1
fi
fi
# Set pipefail so if $path_to_fix does not exist, the build fails
set -o pipefail
extra=()
if [ -n "$automatic" ]; then
extra+=(-name "python2.7" -prune -o)
fi
# Unset -e so that we can collect the return code below
set +e
find "$path_to_fix" "${extra[@]}" -type f -name "*.pyc" -print0 | xargs -0 /usr/bin/marshalparser --fix --overwrite
ret=$?
if [ "$ret" -eq 123 ]; then
echo "WARNING: some marshalparser invocations failed"
[ -n "$automatic" ] && exit 0
fi
exit $ret