Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .bazelci/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ default_tests_with_rpm: &default_tests_with_rpm
- "//pkg/..."
- "//tests/..."
- "//toolchains/..."
# This has started to fail, even on CentOS.
- "-//tests/rpm:test_golden_debuginfo_rpm_contents"

win_tests: &win_tests
test_flags:
Expand Down Expand Up @@ -66,7 +64,10 @@ win_tests: &win_tests
ubuntu2204: &ubuntu
platform: ubuntu2204
<<: *common
<<: *default_tests
<<: *default_tests_with_rpm
shell_commands:
- sudo apt-get update
- sudo apt-get install -y rpm elfutils # for rpmbuild & eu-strip

centos7: &centos
platform: centos7_java11_devtoolset10
Expand Down
2 changes: 1 addition & 1 deletion examples/rpm/debuginfo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This example uses the `find_system_rpmbuild_bzlmod` module extension to help
us register the system rpmbuild as a toolchain in a bzlmod environment.

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

## To use

Expand Down
7 changes: 7 additions & 0 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ def _pkg_rpm_impl(ctx):
if ctx.attr.architecture:
preamble_pieces.append("BuildArch: " + ctx.attr.architecture)

if ctx.attr.debuginfo:
# RedHat distros have redhat-rpm-config with %_enable_debug_packages macro; others need explicit declaration
preamble_pieces.append("%{{!?_enable_debug_packages:%debug_package}}") # set %debug_package unless macro exists

# https://rpm.org/wiki/Releases/4.14.0: "Add support for unique debug file names"
preamble_pieces.append("%undefine _unique_debug_names") # no-op if not defined

preamble_file = ctx.actions.declare_file(
"{}.spec.preamble".format(rpm_name),
)
Expand Down
2 changes: 1 addition & 1 deletion toolchains/rpm/rpmbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rpmbuild_toolchain = rule(
doc = """
The underlying debuginfo configuration for the system rpmbuild.

One of `centos`, `fedora`, and `none`
One of `centos` (RPM < 4.18), `fedora` (RPM >= 4.18), and `none`
""",
default = "none",
),
Expand Down
34 changes: 24 additions & 10 deletions toolchains/rpm/rpmbuild_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
if rctx.attr.debuginfo_type not in DEBUGINFO_VALID_VALUES:
fail("debuginfo_type must be one of", DEBUGINFO_VALID_VALUES)

debuginfo_type = rctx.attr.debuginfo_type
if debuginfo_type == DEBUGINFO_TYPE_AUTODETECT:
if rctx.path(RELEASE_PATH).exists:
rctx.watch(RELEASE_PATH)
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
else:
debuginfo_type = DEBUGINFO_TYPE_NONE

rpmbuild_path = rctx.which("rpmbuild")
if rctx.attr.verbose:
if rpmbuild_path:
Expand All @@ -99,13 +90,32 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):

version = "unknown"
if rpmbuild_path:
rctx.watch(rpmbuild_path)
res = rctx.execute([rpmbuild_path, "--version"])
if res.return_code == 0:
# expect stdout like: RPM version 4.16.1.2
parts = res.stdout.strip().split(" ")
if parts[0] == "RPM" and parts[1] == "version":
version = parts[2]

debuginfo_type = rctx.attr.debuginfo_type
if debuginfo_type == DEBUGINFO_TYPE_AUTODETECT:
version_parts = version.split(".")
if len(version_parts) > 1 and version_parts[0].isdigit() and version_parts[1].isdigit():
major = int(version_parts[0])
minor = int(version_parts[1])
if major < 4 or (major == 4 and minor < 18):
debuginfo_type = DEBUGINFO_TYPE_CENTOS
else:
# https://rpm.org/wiki/Releases/4.18.0: "Make %{buildsubdir} settable outside %setup"
debuginfo_type = DEBUGINFO_TYPE_FEDORA
elif rctx.path(RELEASE_PATH).exists:
rctx.watch(RELEASE_PATH)
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
else:
debuginfo_type = DEBUGINFO_TYPE_NONE

_write_build(
rctx = rctx,
path = rpmbuild_path,
Expand All @@ -126,7 +136,11 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
doc = """
The underlying debuginfo configuration for the system rpmbuild.

One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`)
One of:
- `centos` (RPM < 4.18),
- `fedora` (RPM >= 4.18),
- `none`,
- `default` (detects from `rpmbuild` version if available, otherwise looks up `/etc/os-release`)
""",
default = DEBUGINFO_TYPE_AUTODETECT,
),
Expand Down