From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by sourceware.org (Postfix) with ESMTPS id 846143836668 for ; Sat, 11 Jun 2022 21:22:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 846143836668 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x82e.google.com with SMTP id hh4so1625845qtb.10 for ; Sat, 11 Jun 2022 14:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Rz3OxR2pwQka3Mkmu6hdVx/i4uoULlBKuj42TS7Q0Q8=; b=aIT1ALdhY8fzjdPHTKfNDPEB0ZNQ43H2tNQ5cieLMOER/hEvz0la8bS++UvwmyE65b I3vGT4UT9lcXjXzpvZHNB43LJ7MLP7JRMHInU1HV/dEaTLMxwkC0coYBQY4kL8Y9sdvi mA+egFXCVksade+dcU7JqWtGZe2jhRTA4dn/rcJau+gO8DILDzks5KxtnL/MSSQGNYE7 EdWzeWEMq1EQQGKUSoQ1krqfR6BRhBpQEQU6XQiB6z+8vMiaefqNofmvb/jWSx3b7WSP sKr3Po7tewkvwwuvvlWVPJe/iZ9xVDwN1kqgxUCcBYGGb7QzftbF2CXHVQS/PgLFCRH+ xrSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Rz3OxR2pwQka3Mkmu6hdVx/i4uoULlBKuj42TS7Q0Q8=; b=nLYIZt42RxgpglICR09oW8zL/o0ZKABPO0ASVRdFfSKr/ISbsqev9Kqpv2POlPMefC eKUFSBxnVyhFVy8qHgITe84OqOlzdFfWFGQJH1Nz3tmdX5Yppf23UBhUfe9PwJIuqCka H2FGp2W6ivEMc4IK15hpW7ip7JOHRQEHV2RbUJq+W60/YJkFlBTMFCncxX1OZyhmbQmB o4oeUHCasFRuvN2Et7xPcuA1+7978KhbsYtJgoPkZ6vWOLIT3JiJ5YQ8HKRoppk3nTKo 67Qryui/i7sxzuzw8eeqO74794jge4jSrRLbIa5UrJGqZ8dFLwiz89STklJke5Gx4cmH /mLg== X-Gm-Message-State: AOAM533ymvmJHFtsVr49JOv3uaYPJgmRmzfaAXzQn+NVKbfWVZG0TC+J NayA/KP/JkkPEKOgjny0sPD1wwB3AaMcyA== X-Google-Smtp-Source: ABdhPJwLc6ist9831KE+VGGXgKlWbOLrLqnENFejriGs8uk2nGfveoKc+FBYGEGyaxsI+Hr4MZ8UBA== X-Received: by 2002:ac8:7dd0:0:b0:301:a2d9:5cd9 with SMTP id c16-20020ac87dd0000000b00301a2d95cd9mr41187314qte.127.1654982569588; Sat, 11 Jun 2022 14:22:49 -0700 (PDT) Received: from adrians-laptop.adrianvovk.github.beta.tailscale.net (rrcs-76-190-80-35.central.biz.rr.com. [76.190.80.35]) by smtp.gmail.com with ESMTPSA id ey13-20020a05622a4c0d00b00304e1709b1esm1903427qtb.43.2022.06.11.14.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 14:22:49 -0700 (PDT) From: Adrian Vovk To: debugedit@sourceware.org Cc: Adrian Vovk Subject: [PATCH] find-debuginfo: Stop depending on RPM_* environment variables Date: Sat, 11 Jun 2022 17:22:17 -0400 Message-Id: <20220611212217.4297-1-adrianvovk@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: debugedit@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: debugedit development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jun 2022 21:22:53 -0000 This should fix https://sourceware.org/bugzilla/show_bug.cgi?id=27637 I've implemented this in such a way that it should remain backwards-compatible. In other words, it should just continue working in the RPM build environment as before with no changes, though I haven't tested this. After RPM transitions to the new way of invoking the script, the backwards compatibility should be simple to strip out Signed-off-by: Adrian Vovk --- scripts/find-debuginfo.in | 154 +++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 52 deletions(-) diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in index b07a52f..9bc6232 100755 --- a/scripts/find-debuginfo.in +++ b/scripts/find-debuginfo.in @@ -22,7 +22,7 @@ help() { cat <<'EOF' -Usage: find-debuginfo [OPTION]... [builddir] +Usage: find-debuginfo [OPTION]... builddir destdir nevra automagically generates debug info and file lists Options: @@ -39,7 +39,6 @@ Options: [--unique-debug-suffix SUFFIX] [--unique-debug-src-base BASE] [[-l filelist]... [-p 'pattern'] -o debuginfo.list] -[builddir] The -g flag says to use strip -g instead of full strip on DSOs or EXEs. The --g-libs flag says to use strip -g instead of full strip ONLY on @@ -87,14 +86,22 @@ are unique between versions and releases of the same package. If --unique-debug-suffix SUFFIX is given then the debug files created for will be named -.debug. This makes sure .debug are unique between package version, release and architecture. -(Use --unique-debug-suffix "-%{VERSION}-%{RELEASE}.%{_arch}".) +(Use --unique-debug-suffix "-%{VERSION}-%{RELEASE}.%{_arch}") -If --unique-debug-src-base BASE is given then the source directory -will be called /usr/debug/src/. This makes sure the debug source -dirs are unique between package version, release and achitecture (Use ---unique-debug-src-base "%{name}-%{VERSION}-%{RELEASE}.%{_arch}") +If --unique-debug-src-base BASE is given, then the source directory +will be called /usr/src/debug/. This makes sure the debug source +dirs are unique between package version, release and achitecture. This +option defaults to the nevra, unless RPM_BUILD_DIR is set, in which case +it defaults to legacy RPM-specific behavior to maintain compatibility. -All file names in switches are relative to builddir ('.' if not given). +All file names in switches are relative to builddir. +(if unsure, use ".") + +All output files are placed into destdir. +(Use $RPM_BUILD_ROOT or equivalent) + +The nevra should uniquely identify the current package and version. +(Use %{name}-%{VERSION}-%{RELEASE}.%{_arch} or equivalent) EOF } @@ -138,6 +145,7 @@ build_id_seed= unique_debug_suffix= # Base given by --unique-debug-src-base +unique_debug_src_base_legacy=undecided unique_debug_src_base= # Number of parallel jobs to spawn @@ -146,7 +154,9 @@ n_jobs=1 # exit early on --version or --help done=false -BUILDDIR=. +BUILDDIR= +DESTDIR= +NEVRA= out=debugfiles.list srcout= nout=0 @@ -179,6 +189,7 @@ while [ $# -gt 0 ]; do ;; --unique-debug-src-base) unique_debug_src_base=$2 + unique_debug_src_base_legacy=no shift ;; --g-libs) @@ -249,6 +260,8 @@ while [ $# -gt 0 ]; do ;; *) BUILDDIR=$1 + DESTDIR=$2 + NEVRA=$3 shift break ;; @@ -259,17 +272,52 @@ done # version or help given if [ "$done" = "true" ]; then exit 0; fi -# Currently this scripts depends on some RPM environment variables -# being set. RPM_BUILD_ROOT as the installation root directory. -# RPM_BUILD_DIR as the top build dir (usually one above BUILDDIR). -# And RPM_PACKAGE_NAME, RPM_PACKAGE_VERSION, RPM_PACKAGE_RELEASE, -# RPM_ARCH to create an unique (dir) name. Warn if they aren't set. -for n in RPM_BUILD_ROOT RPM_BUILD_DIR RPM_PACKAGE_NAME; do - if eval test -z \"\${$n-}\"; then - echo >&2 "$n is not set" +# Ensure that BUILDDIR, DESTDIR, and NEVRA are set, with fallbacks +# into the legacy RPM_* environment variables +if test -z "$BUILDDIR"; then + echo >&2 "ERROR: builddir was not provided" + exit 1 +fi +if test -z "$DESTDIR"; then + # Check for legacy RPM_BUILD_ROOT env var + if test -n "$RPM_BUILD_ROOT"; then + DESTDIR="$RPM_BUILD_ROOT" + echo >&2 "WARNING: Using legacy RPM_BUILD_ROOT env var. Please pass destdir directly" + else + echo >&2 "ERROR: destdir was not provided" exit 1 fi -done +fi +if test -z "$NEVRA"; then + # Check for legacy nevra env vars + using_rpm=true + for var in RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE RPM_ARCH; do + if test -z "${!var}"; then + using_rpm=false + fi + done + if [ "$using_rpm" = "true" ]; then + NEVRA="${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-${RPM_PACKAGE_RELEASE}.${RPM_ARCH}" + echo >&2 "WARNING: Using legacy RPM nevra env vars. Please pass nevra directly" + else + echo >&2 "ERROR: nevra was not provided" + exit 1 + fi +fi + +# Fall back to unique_debug_src_base's legacy behavior if RPM_BUILD_DIR is set +if [ "$unique_debug_src_base_legacy" = "undecided" ]; then + if test -z "$RPM_BUILD_DIR"; then + unique_debug_src_base_legacy=no + else + unique_debug_src_base_legacy=yes + fi +fi + +# Handle unique_debug_src_base's default +if test -z "$unique_debug_src_base"; then + unique_debug_src_base="$NEVRA" +fi if test -n "$build_id_seed" -a "$no_recompute_build_id" = "true"; then echo >&2 "*** ERROR: --build-id-seed (unique build-ids) and -n (do not recompute build-id) cannot be used together" @@ -302,7 +350,7 @@ ELFBINSFILE="$BUILDDIR/elfbins.list" > "$LINKSFILE" > "$ELFBINSFILE" -debugdir="${RPM_BUILD_ROOT}/usr/lib/debug" +debugdir="${DESTDIR}/usr/lib/debug" strip_to_debug() { @@ -390,12 +438,12 @@ debug_link() local l="/usr/lib/debug$2" local t="$1" echo >> "$LINKSFILE" "$l $t" - link_relative "$t" "$l" "$RPM_BUILD_ROOT" + link_relative "$t" "$l" "$DESTDIR" } get_debugfn() { - dn=$(dirname "${1#$RPM_BUILD_ROOT}") + dn=$(dirname "${1#$DESTDIR}") bn=$(basename "$1" .debug)${unique_debug_suffix}.debug debugdn=${debugdir}${dn} debugfn=${debugdn}/${bn} @@ -411,7 +459,7 @@ trap 'rm -rf "$temp"' EXIT # Build a list of unstripped ELF files and their hardlinks touch "$temp/primary" -find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \ +find "$DESTDIR" ! -path "${debugdir}/*.debug" -type f \ \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \ -print | LC_ALL=C sort | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' | @@ -439,9 +487,10 @@ do_file() echo "extracting debug info from $f" # See also cpio SOURCEFILE copy. Directories must match up. - debug_base_name="$RPM_BUILD_DIR" - debug_dest_name="/usr/src/debug" - if [ ! -z "$unique_debug_src_base" ]; then + if [ "$unique_debug_src_base_legacy" = "yes" ]; then + debug_base_name="$RPM_BUILD_DIR" + debug_dest_name="/usr/src/debug" + else debug_base_name="$BUILDDIR" debug_dest_name="/usr/src/debug/${unique_debug_src_base}" fi @@ -505,7 +554,7 @@ do_file() $skip_mini || add_minidebug "${debugfn}" "$f" fi - echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE" + echo "./${f#$DESTDIR}" >> "$ELFBINSFILE" # If this file has multiple links, make the corresponding .debug files # all links to one file too. @@ -573,14 +622,14 @@ fi # Invoke the DWARF Compressor utility. if $run_dwz \ - && [ -d "${RPM_BUILD_ROOT}/usr/lib/debug" ]; then - readarray dwz_files < <(cd "${RPM_BUILD_ROOT}/usr/lib/debug"; find -type f -name \*.debug | LC_ALL=C sort) + && [ -d "${DESTDIR}/usr/lib/debug" ]; then + readarray dwz_files < <(cd "${DESTDIR}/usr/lib/debug"; find -type f -name \*.debug | LC_ALL=C sort) if [ ${#dwz_files[@]} -gt 0 ]; then - size_before=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1) - dwz_multifile_name="${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-${RPM_PACKAGE_RELEASE}.${RPM_ARCH}" + size_before=$(du -sk ${DESTDIR}/usr/lib/debug | cut -f1) + dwz_multifile_name="$NEVRA" dwz_multifile_suffix= dwz_multifile_idx=0 - while [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}${dwz_multifile_suffix}" ]; do + while [ -f "${DESTDIR}/usr/lib/debug/.dwz/${dwz_multifile_name}${dwz_multifile_suffix}" ]; do let ++dwz_multifile_idx dwz_multifile_suffix=".${dwz_multifile_idx}" done @@ -588,37 +637,37 @@ if $run_dwz \ dwz_opts="-h -q -r" [ ${#dwz_files[@]} -gt 1 ] && [ "$dwz_single_file_mode" = "false" ] \ && dwz_opts="${dwz_opts} -m .dwz/${dwz_multifile_name}" - mkdir -p "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" + mkdir -p "${DESTDIR}/usr/lib/debug/.dwz" [ -n "${dwz_low_mem_die_limit}" ] \ && dwz_opts="${dwz_opts} -l ${dwz_low_mem_die_limit}" [ -n "${dwz_max_die_limit}" ] \ && dwz_opts="${dwz_opts} -L ${dwz_max_die_limit}" if type dwz >/dev/null 2>&1; then - ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts ${dwz_files[@]} ) + ( cd "${DESTDIR}/usr/lib/debug" && dwz $dwz_opts ${dwz_files[@]} ) else echo >&2 "*** ERROR: DWARF compression requested, but no dwz installed" exit 2 fi - size_after=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1) + size_after=$(du -sk ${DESTDIR}/usr/lib/debug | cut -f1) echo "original debug info size: ${size_before}kB, size after compression: ${size_after}kB" # Remove .dwz directory if empty - rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null + rmdir "${DESTDIR}/usr/lib/debug/.dwz" 2>/dev/null # dwz invalidates .gnu_debuglink CRC32 in the main files. cat "$ELFBINSFILE" | - (cd "$RPM_BUILD_ROOT"; \ + (cd "$DESTDIR"; \ tr '\n' '\0' | xargs -0 ${install_dir}/sepdebugcrcfix usr/lib/debug) fi fi # For each symlink whose target has a .debug file, # make a .debug symlink to that file. -find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*" -type l -print | +find "$DESTDIR" ! -path "${debugdir}/*" -type l -print | while read f do t=$(readlink -m "$f").debug - f=${f#$RPM_BUILD_ROOT} - t=${t#$RPM_BUILD_ROOT} + f=${f#$DESTDIR} + t=${t#$DESTDIR} if [ -f "$debugdir$t" ]; then echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug" debug_link "/usr/lib/debug$t" "${f}.debug" @@ -627,33 +676,34 @@ done if [ -s "$SOURCEFILE" ]; then # See also debugedit invocation. Directories must match up. - debug_base_name="$RPM_BUILD_DIR" - debug_dest_name="/usr/src/debug" - if [ ! -z "$unique_debug_src_base" ]; then + if [ "$unique_debug_src_base_legacy" = "yes" ]; then + debug_base_name="$RPM_BUILD_DIR" + debug_dest_name="/usr/src/debug" + else debug_base_name="$BUILDDIR" debug_dest_name="/usr/src/debug/${unique_debug_src_base}" fi - mkdir -p "${RPM_BUILD_ROOT}${debug_dest_name}" + mkdir -p "${DESTDIR}${debug_dest_name}" # Filter out anything compiler generated which isn't a source file. # e.g. , , <__thread_local_inner macros>. # Some compilers generate them as if they are part of the working # directory (which is why we match against ^ or /). LC_ALL=C sort -z -u "$SOURCEFILE" | grep -E -v -z '(^|/)<[a-z _-]+>$' | - (cd "${debug_base_name}"; cpio -pd0mL "${RPM_BUILD_ROOT}${debug_dest_name}") + (cd "${debug_base_name}"; cpio -pd0mL "${DESTDIR}${debug_dest_name}") # stupid cpio creates new directories in mode 0700, # and non-standard modes may be inherented from original directories, fixup - find "${RPM_BUILD_ROOT}${debug_dest_name}" -type d -print0 | + find "${DESTDIR}${debug_dest_name}" -type d -print0 | xargs --no-run-if-empty -0 chmod 0755 fi -if [ -d "${RPM_BUILD_ROOT}/usr/lib" ] || [ -d "${RPM_BUILD_ROOT}/usr/src" ]; then +if [ -d "${DESTDIR}/usr/lib" ] || [ -d "${DESTDIR}/usr/src" ]; then ((nout > 0)) || - test ! -d "${RPM_BUILD_ROOT}/usr/lib" || - (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) | + test ! -d "${DESTDIR}/usr/lib" || + (cd "${DESTDIR}/usr/lib"; find debug -type d) | sed 's,^,%dir /usr/lib/,' >> "$LISTFILE" - (cd "${RPM_BUILD_ROOT}/usr" + (cd "${DESTDIR}/usr" test ! -d lib/debug || find lib/debug ! -type d test ! -d src/debug -o -n "$srcout" || find src/debug -mindepth 1 -maxdepth 1 ) | sed 's,^,/usr/,' >> "$LISTFILE" @@ -662,8 +712,8 @@ fi if [ -n "$srcout" ]; then srcout="$BUILDDIR/$srcout" > "$srcout" - if [ -d "${RPM_BUILD_ROOT}/usr/src/debug" ]; then - (cd "${RPM_BUILD_ROOT}/usr" + if [ -d "${DESTDIR}/usr/src/debug" ]; then + (cd "${DESTDIR}/usr" find src/debug -mindepth 1 -maxdepth 1 ) | sed 's,^,/usr/,' >> "$srcout" fi @@ -735,7 +785,7 @@ if ((nout > 0)); then done | \ sort -u | \ while read -r line; do - test -d "${RPM_BUILD_ROOT}$line" && printf '%%dir %s\n' "$line" + test -d "${DESTDIR}$line" && printf '%%dir %s\n' "$line" done } i=0 -- 2.36.1