From c4fd80cd08b6100c8db0069648738873cd4f0b13 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Tue, 28 Jul 2020 03:26:31 -0400 Subject: [PATCH] import redhat-rpm-config-123-1.el8 --- SOURCES/brp-mangle-shebangs | 62 +++++++++++++++++++++++------------- SOURCES/kmod.prov | 35 +++++++++++++------- SOURCES/macros | 2 +- SPECS/redhat-rpm-config.spec | 9 +++++- 4 files changed, 71 insertions(+), 37 deletions(-) diff --git a/SOURCES/brp-mangle-shebangs b/SOURCES/brp-mangle-shebangs index b4341a2..fe28768 100755 --- a/SOURCES/brp-mangle-shebangs +++ b/SOURCES/brp-mangle-shebangs @@ -70,13 +70,17 @@ done cd "$RPM_BUILD_ROOT" -trim() { - printf '%s' "$*" -} - +# Large packages such as kernel can have thousands of executable files. +# We take care to not fork/exec thousands of "file"s and "grep"s, +# but run just two of them. +# (Take care to exclude filenames which would mangle "file" output). +find -executable -type f ! -path '*:*' ! -path $'*\n*' \ +| file -N --mime-type -f - \ +| grep -P ".+(?=: text/)" \ +| { fail=0 -while IFS= read -r -d $'\0' f; do - file -N --mime-type "$f" | grep -q -P ".+(?=: text/)" || continue +while IFS= read -r line; do + f=${line%%:*} # Remove the dot path="${f#.}" @@ -88,24 +92,34 @@ while IFS= read -r -d $'\0' f; do echo "$path" | grep -q -E -f "$exclude_files_from" && continue fi - ts=$(stat -c %y "$f") - read shebang_line < "$f" || : - orig_shebang=$(trim $(echo "$shebang_line" | grep -Po "#!\K.*" || echo)) - shebang="$orig_shebang" - if [ -n "$exclude_shebangs" ]; then - echo "$shebang" | grep -q -E "$exclude_shebangs" && continue - fi - if [ -n "$exclude_shebangs_from" ]; then - echo "$shebang" | grep -q -E -f "$exclude_shebangs_from" && continue - fi - - if [ -z "$shebang" ]; then - echo >&2 "*** WARNING: $f is executable but has empty or no shebang, removing executable bit" + read shebang_line < "$f" + orig_shebang="${shebang_line#\#!}" + if [ "$orig_shebang" = "$shebang_line" ]; then + echo >&2 "*** WARNING: $f is executable but has no shebang, removing executable bit" + ts=$(stat -c %y "$f") chmod -x "$f" touch -d "$ts" "$f" continue - elif [ -n "${shebang##/*}" ]; then + fi + + # Trim spaces + while shebang="${orig_shebang// / }"; [ "$shebang" != "$orig_shebang" ]; do + orig_shebang="$shebang" + done + # Treat "#! /path/to " as "#!/path/to" + orig_shebang="${orig_shebang# }" + + shebang="$orig_shebang" + + if [ -z "$shebang" ]; then + echo >&2 "*** WARNING: $f is executable but has empty shebang, removing executable bit" + ts=$(stat -c %y "$f") + chmod -x "$f" + touch -d "$ts" "$f" + continue + fi + if [ -n "${shebang##/*}" ]; then echo >&2 "*** ERROR: $f has shebang which doesn't start with '/' ($shebang)" fail=1 continue @@ -134,11 +148,13 @@ while IFS= read -r -d $'\0' f; do echo >&2 "*** ERROR: ambiguous python shebang in $path: #!$orig_shebang. Change it to python3 (or python2) explicitly." fail=1 elif [ "#!$shebang" != "#!$orig_shebang" ]; then - sed -i -e "1c #!$shebang" "$f" echo "mangling shebang in $path from $orig_shebang to #!$shebang" + ts=$(stat -c %y "$f") + sed -i -e "1c #!$shebang" "$f" + touch -d "$ts" "$f" fi - touch -d "$ts" "$f" -done < <(find -executable -type f -print0) +done exit $fail +} diff --git a/SOURCES/kmod.prov b/SOURCES/kmod.prov index f02d8a0..bbe5aa0 100644 --- a/SOURCES/kmod.prov +++ b/SOURCES/kmod.prov @@ -1,17 +1,28 @@ #!/bin/sh +x +# Kernel build can have many thousands of modules. +# kmod.prov is run for every one of them. +# Try to make this script run as fast as we can. +# For example, use shell string ops instead of external programs +# where possible. IFS=$'\n' -for i in $(grep -E '(/lib/modules/.*\.ko|/lib/modules/.*/modules.builtin)'); -do - kmod=$(basename $i | sed -e 's/.[xg]z//'); +read -r fname || exit - if [ $kmod == "modules.builtin" ]; then - for j in $(cat $i); do - j=$(basename $j); - echo "kmod($j)" - done - else - echo "kmod($kmod)" - fi -done +# Only process files from .../lib/modules/... subtree +[ "${fname#*/lib/modules/*}" != "$fname" ] || exit 0 + +kmod=${fname##*/} # like basename, but faster + +if [ "$kmod" = "modules.builtin" ]; then + for j in $(cat -- "$fname"); do + echo "kmod(${j##*/})" + done + exit 0 +fi + +kmod=${kmod%.gz} +kmod=${kmod%.xz} +if [ "${kmod%.ko}" != "$kmod" ]; then + echo "kmod($kmod)" +fi diff --git a/SOURCES/macros b/SOURCES/macros index 73dc5a2..2cbb14e 100644 --- a/SOURCES/macros +++ b/SOURCES/macros @@ -157,7 +157,7 @@ print(result) %__brp_strip /usr/lib/rpm/brp-strip %{__strip} %__brp_strip_comment_note /usr/lib/rpm/brp-strip-comment-note %{__strip} %{__objdump} %__brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip} -%__brp_python_bytecompile /usr/lib/rpm/brp-python-bytecompile %{?_python_bytecompile_errors_terminate_build} +%__brp_python_bytecompile /usr/lib/rpm/brp-python-bytecompile "" %{?_python_bytecompile_errors_terminate_build} %__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink # __brp_mangle_shebangs_exclude - shebangs to exclude # __brp_mangle_shebangs_exclude_file - file from which to get shebangs to exclude diff --git a/SPECS/redhat-rpm-config.spec b/SPECS/redhat-rpm-config.spec index 2a8f63d..7f8b443 100644 --- a/SPECS/redhat-rpm-config.spec +++ b/SPECS/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 121 +Version: 123 Release: 1%{?dist} # No version specified. License: GPL+ @@ -198,6 +198,13 @@ install -p -m 755 %{SOURCE21} %{buildroot}%{_rpmconfigdir}/kabi.sh %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Tue Jun 16 2020 Florian Festi - 123-1 +- Update kmod.prov for better performance (#1794491) +- Backport performance improvements for brp-mangle-shebangs (#1794779) + +* Mon Feb 24 2020 Michal Domonkos - 122-1 +- Fix argument shift in %%__brp_python_bytecompile (#1724567) + * Tue Nov 26 2019 Eugene Syromiatnikov - 121-1 - macros.kmp: add post-install hooks for kmod processing (#1664478, #1673200)