Skip to content

Commit 85bada1

Browse files
committed
fix(rpm): debuginfo support on more distributions
This enables RPM debuginfo package generation across different Linux distributions (tested on Rocky and Ubuntu in CI) by implementing RPM version-based detection if possible, and falling back to the existing OS release-based detection otherwise. There's indeed a clear pivot in RPM versions for that matter: - RPM < 4.18 uses `buildsubdir .` (which happens to be called the "CENTOS" type in the present project), - RPM >= 4.18 is incompatible with the former: ``` rm: refusing to remove '.' or '..' directory: skipping '.' ``` It therefore uses `buildsubdir BUILD_SUB` (called the "FEDORA" type here). RedHat distros have `redhat-rpm-config` with `%_enable_debug_packages` that auto-invokes `%debug_package` (rpm-software-management/rpm#2204). Debian/Ubuntu ship vanilla upstream RPM without this configuration: ``` output 'tests/rpm/test_debuginfo_rpm-debuginfo-1-0..rpm' was not created ``` The present change therefore adds `%debug_package` only when applicable: `%{!?_enable_debug_packages:%debug_package}`. Also, since RPM 4.14, unique debug package filenames are enabled by default, leading to variadic filenames being generated: ``` Executing tests from //tests/rpm:test_golden_debuginfo_rpm_contents ----------------------------------------------------------------------------- 29c29 < /usr/lib/debug/test_debuginfo-1-0.x86_64.debug --- > /usr/lib/debug/test_debuginfo.debug FAIL: files "tests/rpm/test_debuginfo_rpm_contents.txt" and "tests/rpm/test_debuginfo_rpm_contents.txt.golden" differ ``` The change makes debug package filenames consistent across distributions by means of: `%undefine _unique_debug_names` (safe no-op on older RPM versions).
1 parent 3bbfc0b commit 85bada1

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

.bazelci/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ default_tests_with_rpm: &default_tests_with_rpm
3737
- "//pkg/..."
3838
- "//tests/..."
3939
- "//toolchains/..."
40-
# This has started to fail, even on CentOS.
41-
- "-//tests/rpm:test_golden_debuginfo_rpm_contents"
4240

4341
win_tests: &win_tests
4442
test_flags:
@@ -66,7 +64,10 @@ win_tests: &win_tests
6664
ubuntu2204: &ubuntu
6765
platform: ubuntu2204
6866
<<: *common
69-
<<: *default_tests
67+
<<: *default_tests_with_rpm
68+
shell_commands:
69+
- sudo apt-get update
70+
- sudo apt-get install -y rpm elfutils # for rpmbuild & eu-strip
7071

7172
centos7: &centos
7273
platform: centos7_java11_devtoolset10

pkg/rpm_pfg.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,13 @@ def _pkg_rpm_impl(ctx):
604604
if ctx.attr.architecture:
605605
preamble_pieces.append("BuildArch: " + ctx.attr.architecture)
606606

607+
if ctx.attr.debuginfo:
608+
# RedHat distros have redhat-rpm-config with %_enable_debug_packages macro; others need explicit declaration
609+
preamble_pieces.append("%{{!?_enable_debug_packages:%debug_package}}") # set %debug_package unless macro exists
610+
611+
# https://rpm.org/wiki/Releases/4.14.0: "Add support for unique debug file names"
612+
preamble_pieces.append("%undefine _unique_debug_names") # no-op if not defined
613+
607614
preamble_file = ctx.actions.declare_file(
608615
"{}.spec.preamble".format(rpm_name),
609616
)

toolchains/rpm/rpmbuild_configure.bzl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
8181
if rctx.attr.debuginfo_type not in DEBUGINFO_VALID_VALUES:
8282
fail("debuginfo_type must be one of", DEBUGINFO_VALID_VALUES)
8383

84-
debuginfo_type = rctx.attr.debuginfo_type
85-
if debuginfo_type == DEBUGINFO_TYPE_AUTODETECT:
86-
if rctx.path(RELEASE_PATH).exists:
87-
rctx.watch(RELEASE_PATH)
88-
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
89-
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
90-
else:
91-
debuginfo_type = DEBUGINFO_TYPE_NONE
92-
9384
rpmbuild_path = rctx.which("rpmbuild")
9485
if rctx.attr.verbose:
9586
if rpmbuild_path:
@@ -99,13 +90,32 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
9990

10091
version = "unknown"
10192
if rpmbuild_path:
93+
rctx.watch(rpmbuild_path)
10294
res = rctx.execute([rpmbuild_path, "--version"])
10395
if res.return_code == 0:
10496
# expect stdout like: RPM version 4.16.1.2
10597
parts = res.stdout.strip().split(" ")
10698
if parts[0] == "RPM" and parts[1] == "version":
10799
version = parts[2]
108100

101+
debuginfo_type = rctx.attr.debuginfo_type
102+
if debuginfo_type == DEBUGINFO_TYPE_AUTODETECT:
103+
version_parts = version.split(".")
104+
if len(version_parts) > 1 and version_parts[0].isdigit() and version_parts[1].isdigit():
105+
major = int(version_parts[0])
106+
minor = int(version_parts[1])
107+
if major < 4 or (major == 4 and minor < 18):
108+
debuginfo_type = DEBUGINFO_TYPE_CENTOS
109+
else:
110+
# https://rpm.org/wiki/Releases/4.18.0: "Make %{buildsubdir} settable outside %setup"
111+
debuginfo_type = DEBUGINFO_TYPE_FEDORA
112+
elif rctx.path(RELEASE_PATH).exists:
113+
rctx.watch(RELEASE_PATH)
114+
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
115+
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
116+
else:
117+
debuginfo_type = DEBUGINFO_TYPE_NONE
118+
109119
_write_build(
110120
rctx = rctx,
111121
path = rpmbuild_path,

0 commit comments

Comments
 (0)