Allow to opt-out from shebang mangling for specific paths/shebangs

Introduces __brp_mangle_shebangs_exclude_from and __brp_mangle_shebangs_exclude

 * the first allows to explude specific paths from the mangling
 * the second allows to exlude specific shebangs

Both are used with `grep -E`. Similar escaping rules as in [1] apply.

[1] https://fedoraproject.org/wiki/Packaging:AutoProvidesAndRequiresFiltering
This commit is contained in:
Miro Hrončok 2018-02-14 20:09:03 +01:00 committed by Igor Gnatenko
parent 6bc9480501
commit fb05a239d2
No known key found for this signature in database
GPG Key ID: 695714BD1BBC5F4C
3 changed files with 21 additions and 4 deletions

View File

@ -5,6 +5,9 @@ if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
exit 0
fi
exclude_files="${1:-}"
exclude_shebangs="${2:-}"
cd "$RPM_BUILD_ROOT"
trim() {
@ -14,10 +17,21 @@ trim() {
fail=0
for f in $(find -executable -type f | xargs --no-run-if-empty file -N --mime-type | grep -Po "^\K.+(?=: text/)"); do
# Remove the dot
path="${f#.}"
if [ -n "$exclude_files" ]; then
echo "$path" | grep -q -E "$exclude_files" && continue
fi
ts=$(stat -c %y "$f")
read orig_shebang < "$f" || :
shebang=$(trim $(echo "$orig_shebang" | grep -Po "#!\K.*" || echo))
if [ -n "$exclude_shebangs" ]; then
echo "$shebang" | grep -q -E "$exclude_shebangs" && continue
fi
if [ -z "$shebang" ]; then
echo >&2 "*** WARNING: $f is executable but has empty or no shebang, removing executable bit"
chmod -x "$f"
@ -44,10 +58,10 @@ for f in $(find -executable -type f | xargs --no-run-if-empty file -N --mime-typ
if [ "$shebang" != "$py_shebang" ]; then
sed -i -e "1c #!$py_shebang" "$f"
echo >&2 "*** WARNING: mangling shebang in $f from $orig_shebang to #!$py_shebang. This will become an ERROR, fix it manually!"
echo >&2 "*** WARNING: mangling shebang in $path from $orig_shebang to #!$py_shebang. This will become an ERROR, fix it manually!"
elif [ "#!$shebang" != "$orig_shebang" ]; then
sed -i -e "1c #!$shebang" "$f"
echo "mangling shebang in $f from $orig_shebang to #!$shebang"
echo "mangling shebang in $path from $orig_shebang to #!$shebang"
fi
touch -d "$ts" "$f"

2
macros
View File

@ -143,7 +143,7 @@
%__brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip}
%__brp_python_bytecompile /usr/lib/rpm/brp-python-bytecompile %{__python} %{?_python_bytecompile_errors_terminate_build}
%__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink
%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs
%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs "%{?__brp_mangle_shebangs_exclude_from}" "%{?__brp_mangle_shebangs_exclude}"
%__os_install_post \
%{?__brp_ldconfig} \

View File

@ -6,7 +6,7 @@
Summary: Red Hat specific rpm configuration files
Name: redhat-rpm-config
Version: 96
Version: 97
Release: 1%{?dist}
# No version specified.
License: GPL+
@ -183,6 +183,9 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov
%{_rpmconfigdir}/macros.d/macros.kmp
%changelog
* Wed Feb 14 2018 Miro Hrončok <mhroncok@redhat.com> - 97-1
- Allow to opt-out from shebang mangling for specific paths/shebangs
* Thu Feb 08 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 96-1
- Simplify/Fix check for shebang starting with "/"