Skip to content

Commit

Permalink
Add proper logic for debuginfo enablement
Browse files Browse the repository at this point in the history
All these years, enabling debuginfo has required distros to hijack the
spec %install section with a macro like this:

    %install %{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}\
    %%install\
    %{nil}

This for a widely used, longtime upstream supported feature is just
gross, and also very non-obvious, feeble and whatnot. And totally
prevents the new append/prepend options from being used with %install.

Take advantage of several newish features to make this happen: we need
expressions to properly handle the numeric %_enable_debug_packages value
from a macro, and if enabled, output the debuginfo template as a dynamic
.specpart.

Enable debuginfo on Linux by default in the platform configuration.
Notably noarch should not have debuginfo so it's disabled in the
platform configuration - since 96467dc
we can now actually rely on the platform configuration being valid,
so we can drop the "%ifnarch noarch" from the debug package check.
Further streamlining should be possible.

Note that the old %install hack MUST BE REMOVED from distros now.

As a nice bonus, this makes debuginfo work for packages that don't use
%setup. Add an explicit test for this in the "rpmbuild %caps" test.
specstep.spec needs to be made noarch here, otherwise it'll now try
to produce debuginfo and fail.

Co-authored-by: Florian Festi <ffesti@redhat.com>

Fixes: rpm-software-management#2204
Fixes: rpm-software-management#1878
  • Loading branch information
pmatilai authored and ffesti committed May 13, 2024
1 parent f3f9f2c commit 8535694
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions installplatform
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ for ARCH in noarch `grep ^arch_canon $RPMRC | cut -d: -f2` ${RPM_CUSTOM_ARCH:+cu
ISABITS=
CANONARCH=
CANONCOLOR=
DEBUGINFO=0
FILTER=cat
case "${ARCH}" in
custom)
Expand Down Expand Up @@ -207,6 +208,10 @@ for ARCH in noarch `grep ^arch_canon $RPMRC | cut -d: -f2` ${RPM_CUSTOM_ARCH:+cu
LIB=${LIB}64
fi

if [ "$OS" = "linux" ] && [ "$CANONARCH" != "noarch" ]; then
DEBUGINFO=1
fi

PPD="${DESTDIR}/${platformdir}/${ARCH}-${OS}"
[ -d $PPD ] || mkdir -p $PPD

Expand All @@ -215,6 +220,7 @@ for ARCH in noarch `grep ^arch_canon $RPMRC | cut -d: -f2` ${RPM_CUSTOM_ARCH:+cu
-e "s,=RPMCANONARCH=,$CANONARCH,g" \
-e "s,=RPMCANONCOLOR=,$CANONCOLOR," \
-e "s,=RPMRC_GNU=,$RPMRC_GNU," \
-e "s,=RPMDEBUGINFO=,$DEBUGINFO," \
-e "s,=LIB=,$LIB," \
-e "s,=ARCH_INSTALL_POST=,$ARCH_INSTALL_POST," \
-e '/\${\w*:-/!s,\${,%{_,' \
Expand Down
2 changes: 0 additions & 2 deletions macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ package or when debugging this package.\
%{nil}

%debug_package \
%ifnarch noarch\
%global __debug_package 1\
%_debuginfo_template\
%{?_debugsource_packages:%_debugsource_template}\
%endif\
%{nil}

%_langpack_template() \
Expand Down
3 changes: 3 additions & 0 deletions platform.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

%_defaultdocdir %{_datadir}/doc

%_enable_debug_packages =RPMDEBUGINFO=

#==============================================================================
# ---- Build policy macros.
#
Expand Down Expand Up @@ -86,6 +88,7 @@
%{nil}

%__spec_install_post\
%[ 0%{?_enable_debug_packages} > 0 ? "%(echo "%{debug_package}" > %{specpartsdir}/rpm-debuginfo.specpart)" : "" ]\
%{?__debug_package:%{__debug_install_post}}\
%{__arch_install_post}\
%{__os_install_post}\
Expand Down
1 change: 1 addition & 0 deletions tests/data/SPECS/specstep.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 1.0
Release: 1
Summary: Testing spec steps
License: GPL
BuildArch: noarch
%{?preamble}

%description
Expand Down
10 changes: 0 additions & 10 deletions tests/data/macros.debug
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@
%{_rpmconfigdir}/brp-strip-static-archive %{__strip} \
%{nil}

%__spec_install_post\
%{?__debug_package:%{__debug_install_post}}\
%{__arch_install_post}\
%{__os_install_post}\
%{nil}

%install %{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}\
%%install\
%{nil}

# Should missing buildids terminate a build?
%_missing_build_ids_terminate_build 1

Expand Down
9 changes: 9 additions & 0 deletions tests/rpmbuild.at
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,15 @@ runroot rpmbuild --quiet -bb /data/SPECS/caps.spec
[],
[])

RPMTEST_CHECK([
runroot rpm -qp --qf "%{name}\n" /build/RPMS/*/*.rpm|sort
],
[0],
[caps
caps-debuginfo
],
[])

RPMTEST_CHECK([
runroot rpm -q --filecaps /build/RPMS/*/caps-1.0-1.*.rpm | grep -v build-id
],
Expand Down

0 comments on commit 8535694

Please sign in to comment.