From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 75DF33858D33 for ; Wed, 1 Feb 2023 18:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75DF33858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id CCA11304D69A; Wed, 1 Feb 2023 19:34:52 +0100 (CET) Received: by r6.localdomain (Postfix, from userid 1000) id 88D8F340166; Wed, 1 Feb 2023 19:34:52 +0100 (CET) Message-ID: <2bf6f490ec07e8215faba944703b24f41d648197.camel@klomp.org> Subject: Re: [PATCH] find-debuginfo: Stop depending on RPM_* environment variables From: Mark Wielaard To: Adrian Vovk , debugedit@sourceware.org Date: Wed, 01 Feb 2023 19:34:52 +0100 In-Reply-To: References: <20220611212217.4297-1-adrianvovk@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-3036.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Adrian, On Wed, 2023-02-01 at 12:16 -0500, Adrian Vovk wrote: > I'm bumping this again to make sure it's not lost. Is there anything I > need to do to get this merged? O, so sorry, yes, this got "lost". I started looking at it. Then got a little scared because I realized we don't have any testcases for find- debuginfo. And then I kind of forgot to review it. Thanks for the reminder. So one question is: how did you test this? Thanks, Mark > On Sat, Jun 11, 2022 at 5:22 PM Adrian Vovk wrote: > >=20 > > This should fix https://sourceware.org/bugzilla/show_bug.cgi?id=3D27637 > >=20 > > I've implemented this in such a way that it should remain backwards-com= patible. > > In other words, it should just continue working in the RPM build enviro= nment as > > before with no changes, though I haven't tested this. > >=20 > > After RPM transitions to the new way of invoking the script, the backwa= rds > > compatibility should be simple to strip out > >=20 > > Signed-off-by: Adrian Vovk > > --- > > scripts/find-debuginfo.in | 154 +++++++++++++++++++++++++------------- > > 1 file changed, 102 insertions(+), 52 deletions(-) > >=20 > > 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 > >=20 > > Options: > > @@ -39,7 +39,6 @@ Options: > > [--unique-debug-suffix SUFFIX] > > [--unique-debug-src-base BASE] > > [[-l filelist]... [-p 'pattern'] -o debuginfo.list] > > -[builddir] > >=20 > > 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 sam= e package. > > If --unique-debug-suffix SUFFIX is given then the debug files created > > for will be named -.debug. This makes sure .debu= g > > are unique between package version, release and architecture. > > -(Use --unique-debug-suffix "-%{VERSION}-%{RELEASE}.%{_arch}".) > > +(Use --unique-debug-suffix "-%{VERSION}-%{RELEASE}.%{_arch}") > >=20 > > -If --unique-debug-src-base BASE is given then the source directory > > -will be called /usr/debug/src/. This makes sure the debug sourc= e > > -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 sourc= e > > +dirs are unique between package version, release and achitecture. Thi= s > > +option defaults to the nevra, unless RPM_BUILD_DIR is set, in which ca= se > > +it defaults to legacy RPM-specific behavior to maintain compatibility. > >=20 > > -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 > > } > >=20 > > @@ -138,6 +145,7 @@ build_id_seed=3D > > unique_debug_suffix=3D > >=20 > > # Base given by --unique-debug-src-base > > +unique_debug_src_base_legacy=3Dundecided > > unique_debug_src_base=3D > >=20 > > # Number of parallel jobs to spawn > > @@ -146,7 +154,9 @@ n_jobs=3D1 > > # exit early on --version or --help > > done=3Dfalse > >=20 > > -BUILDDIR=3D. > > +BUILDDIR=3D > > +DESTDIR=3D > > +NEVRA=3D > > out=3Ddebugfiles.list > > srcout=3D > > nout=3D0 > > @@ -179,6 +189,7 @@ while [ $# -gt 0 ]; do > > ;; > > --unique-debug-src-base) > > unique_debug_src_base=3D$2 > > + unique_debug_src_base_legacy=3Dno > > shift > > ;; > > --g-libs) > > @@ -249,6 +260,8 @@ while [ $# -gt 0 ]; do > > ;; > > *) > > BUILDDIR=3D$1 > > + DESTDIR=3D$2 > > + NEVRA=3D$3 > > shift > > break > > ;; > > @@ -259,17 +272,52 @@ done > > # version or help given > > if [ "$done" =3D "true" ]; then exit 0; fi > >=20 > > -# 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=3D"$RPM_BUILD_ROOT" > > + echo >&2 "WARNING: Using legacy RPM_BUILD_ROOT env var. Please pas= s 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=3Dtrue > > + for var in RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE = RPM_ARCH; do > > + if test -z "${!var}"; then > > + using_rpm=3Dfalse > > + fi > > + done > > + if [ "$using_rpm" =3D "true" ]; then > > + NEVRA=3D"${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-${RPM_PACKAGE_= RELEASE}.${RPM_ARCH}" > > + echo >&2 "WARNING: Using legacy RPM nevra env vars. Please pass ne= vra 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_DI= R is set > > +if [ "$unique_debug_src_base_legacy" =3D "undecided" ]; then > > + if test -z "$RPM_BUILD_DIR"; then > > + unique_debug_src_base_legacy=3Dno > > + else > > + unique_debug_src_base_legacy=3Dyes > > + fi > > +fi > > + > > +# Handle unique_debug_src_base's default > > +if test -z "$unique_debug_src_base"; then > > + unique_debug_src_base=3D"$NEVRA" > > +fi > >=20 > > if test -n "$build_id_seed" -a "$no_recompute_build_id" =3D "true"; th= en > > echo >&2 "*** ERROR: --build-id-seed (unique build-ids) and -n (do n= ot recompute build-id) cannot be used together" > > @@ -302,7 +350,7 @@ ELFBINSFILE=3D"$BUILDDIR/elfbins.list" > > > "$LINKSFILE" > > > "$ELFBINSFILE" > >=20 > > -debugdir=3D"${RPM_BUILD_ROOT}/usr/lib/debug" > > +debugdir=3D"${DESTDIR}/usr/lib/debug" > >=20 > > strip_to_debug() > > { > > @@ -390,12 +438,12 @@ debug_link() > > local l=3D"/usr/lib/debug$2" > > local t=3D"$1" > > echo >> "$LINKSFILE" "$l $t" > > - link_relative "$t" "$l" "$RPM_BUILD_ROOT" > > + link_relative "$t" "$l" "$DESTDIR" > > } > >=20 > > get_debugfn() > > { > > - dn=3D$(dirname "${1#$RPM_BUILD_ROOT}") > > + dn=3D$(dirname "${1#$DESTDIR}") > > bn=3D$(basename "$1" .debug)${unique_debug_suffix}.debug > > debugdn=3D${debugdir}${dn} > > debugfn=3D${debugdn}/${bn} > > @@ -411,7 +459,7 @@ trap 'rm -rf "$temp"' EXIT > >=20 > > # 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=3DC sort | > > file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p'= | > > @@ -439,9 +487,10 @@ do_file() > >=20 > > echo "extracting debug info from $f" > > # See also cpio SOURCEFILE copy. Directories must match up. > > - debug_base_name=3D"$RPM_BUILD_DIR" > > - debug_dest_name=3D"/usr/src/debug" > > - if [ ! -z "$unique_debug_src_base" ]; then > > + if [ "$unique_debug_src_base_legacy" =3D "yes" ]; then > > + debug_base_name=3D"$RPM_BUILD_DIR" > > + debug_dest_name=3D"/usr/src/debug" > > + else > > debug_base_name=3D"$BUILDDIR" > > debug_dest_name=3D"/usr/src/debug/${unique_debug_src_base}" > > fi > > @@ -505,7 +554,7 @@ do_file() > > $skip_mini || add_minidebug "${debugfn}" "$f" > > fi > >=20 > > - echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE" > > + echo "./${f#$DESTDIR}" >> "$ELFBINSFILE" > >=20 > > # If this file has multiple links, make the corresponding .debug fil= es > > # all links to one file too. > > @@ -573,14 +622,14 @@ fi > >=20 > > # 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=3DC sort) > > + && [ -d "${DESTDIR}/usr/lib/debug" ]; then > > + readarray dwz_files < <(cd "${DESTDIR}/usr/lib/debug"; find -type f = -name \*.debug | LC_ALL=3DC sort) > > if [ ${#dwz_files[@]} -gt 0 ]; then > > - size_before=3D$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1) > > - dwz_multifile_name=3D"${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-$= {RPM_PACKAGE_RELEASE}.${RPM_ARCH}" > > + size_before=3D$(du -sk ${DESTDIR}/usr/lib/debug | cut -f1) > > + dwz_multifile_name=3D"$NEVRA" > > dwz_multifile_suffix=3D > > dwz_multifile_idx=3D0 > > - while [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_n= ame}${dwz_multifile_suffix}" ]; do > > + while [ -f "${DESTDIR}/usr/lib/debug/.dwz/${dwz_multifile_name}${d= wz_multifile_suffix}" ]; do > > let ++dwz_multifile_idx > > dwz_multifile_suffix=3D".${dwz_multifile_idx}" > > done > > @@ -588,37 +637,37 @@ if $run_dwz \ > > dwz_opts=3D"-h -q -r" > > [ ${#dwz_files[@]} -gt 1 ] && [ "$dwz_single_file_mode" =3D "false= " ] \ > > && dwz_opts=3D"${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=3D"${dwz_opts} -l ${dwz_low_mem_die_limit}" > > [ -n "${dwz_max_die_limit}" ] \ > > && dwz_opts=3D"${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_fi= les[@]} ) > > + ( cd "${DESTDIR}/usr/lib/debug" && dwz $dwz_opts ${dwz_files[@]}= ) > > else > > echo >&2 "*** ERROR: DWARF compression requested, but no dwz ins= talled" > > exit 2 > > fi > > - size_after=3D$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1) > > + size_after=3D$(du -sk ${DESTDIR}/usr/lib/debug | cut -f1) > > echo "original debug info size: ${size_before}kB, size after compr= ession: ${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 > >=20 > > # 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/deb= ug) > > fi > > fi > >=20 > > # 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=3D$(readlink -m "$f").debug > > - f=3D${f#$RPM_BUILD_ROOT} > > - t=3D${t#$RPM_BUILD_ROOT} > > + f=3D${f#$DESTDIR} > > + t=3D${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 > >=20 > > if [ -s "$SOURCEFILE" ]; then > > # See also debugedit invocation. Directories must match up. > > - debug_base_name=3D"$RPM_BUILD_DIR" > > - debug_dest_name=3D"/usr/src/debug" > > - if [ ! -z "$unique_debug_src_base" ]; then > > + if [ "$unique_debug_src_base_legacy" =3D "yes" ]; then > > + debug_base_name=3D"$RPM_BUILD_DIR" > > + debug_dest_name=3D"/usr/src/debug" > > + else > > debug_base_name=3D"$BUILDDIR" > > debug_dest_name=3D"/usr/src/debug/${unique_debug_src_base}" > > fi > >=20 > > - 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=3DC 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 > >=20 > > -if [ -d "${RPM_BUILD_ROOT}/usr/lib" ] || [ -d "${RPM_BUILD_ROOT}/usr/s= rc" ]; 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" > >=20 > > - (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=3D"$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=3D0 > > -- > > 2.36.1 > >=20