Skip to content

Commit 46c531f

Browse files
committed
fix(rpm): debuginfo support on some 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. RPM 4.18.0 introduced changes to make `%{buildsubdir}` independent of the `%setup` macro: - commit: `Make %{buildsubdir} more independent of %setup` (rpm-software-management/rpm@6caca84c904423) - since: `rpm-4.18.0-alpha1` - release: https://rpm.org/wiki/Releases/4.18.0 While this change enabled setting `buildsubdir` as a regular macro rather than a `spec` object property, it had the side effect of altering the relative path handling in install scripts. This requires different file path formats in the `%install` section: - RPM < 4.18, corresponding to the project's "centos" type: ``` cp 'bazel-out/k8-fastbuild/bin/tests/rpm/test_debuginfo' '%{buildroot}/test_debuginfo' ``` - RPM >= 4.18, corresponding to the project's "fedora" type: ``` cp '../bazel-out/k8-fastbuild/bin/tests/rpm/test_debuginfo' '%{buildroot}/test_debuginfo' ``` Using the wrong "type" causes build failures: - "fedora" with RPM < 4.18: ``` cp: cannot stat '../bazel-out/k8-fastbuild/bin/tests/rpm/test_debuginfo': No such file or directory ``` - "centos" with RPM >= 4.18: ``` rm: refusing to remove '.' or '..' directory: skipping '.' ``` The present change therefore implements version detection to automatically select the appropriate "type". **Additional fixes for cross-distribution compatibility** 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 ``` That's why the change adds `%debug_package` only when applicable: - `%{!?_enable_debug_packages:%debug_package}`. Also, since RPM [4.14](https://rpm.org/wiki/Releases/4.14.0), 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 ``` That's why the change makes debug package filenames consistent across distributions by means of: - `%undefine _unique_debug_names` (safe no-op on older RPM versions). Note: I also verified the change locally with: - RPM 4.17.1 on Fedora 35 ("centos" type) - RPM 4.18.2 on Ubuntu 24.04.3 ("fedora" type) - RPM 4.19.1.1 on Fedora 40 ("fedora" type)
1 parent 24055fa commit 46c531f

5 files changed

Lines changed: 37 additions & 15 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

examples/rpm/debuginfo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This example uses the `find_system_rpmbuild_bzlmod` module extension to help
66
us register the system rpmbuild as a toolchain in a bzlmod environment.
77

88
It configures the system toolchain to be aware of which debuginfo configuration
9-
to use (defaults to "none", the example uses "centos7").
9+
to use (defaults to "none", the example uses "centos" for RPM < 4.18).
1010

1111
## To use
1212

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.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ rpmbuild_toolchain = rule(
6060
doc = """
6161
The underlying debuginfo configuration for the system rpmbuild.
6262
63-
One of `centos`, `fedora`, and `none`
63+
One of `centos` (RPM < 4.18), `fedora` (RPM >= 4.18), and `none`
6464
""",
6565
default = "none",
6666
),

toolchains/rpm/rpmbuild_configure.bzl

Lines changed: 24 additions & 10 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,
@@ -126,7 +136,11 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
126136
doc = """
127137
The underlying debuginfo configuration for the system rpmbuild.
128138
129-
One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`)
139+
One of:
140+
- `centos` (RPM < 4.18),
141+
- `fedora` (RPM >= 4.18),
142+
- `none`,
143+
- `default` (detects from `rpmbuild` version if available, otherwise looks up `/etc/os-release`)
130144
""",
131145
default = DEBUGINFO_TYPE_AUTODETECT,
132146
),

0 commit comments

Comments
 (0)