-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for generating debuginfo RPMs (#842)
* Enable creation and capture of debuginfo RPMs This change enables the creation and capture of debuginfo RPMs on Fedora40 and CentOS7. See: https://docs.fedoraproject.org/en-US/packaging-guidelines/Debuginfo/ Fedora 40 expects the RPM contents to be located in a subdirectory which is specified using the `buildsubdir` variable. In order to account for this, we need to tweak some of the location details if debuginfo is enabled. CentOS expects `buildsubdir` to have a value like `.` instead. In both cases, we disable debugsource packages by ensuring that we undefine `_debugsource_packages`, otherwise we'll try to generate them alongside the debuginfo packages and will fail. We only want this method of producing debuginfo to apply when we're using the system `rpmbuild` because the underlying behaviour is controlled by a combination of the rpmbuild version, macro definitions, find-debuginfo.sh, and debugedit. If we were to expand this to use a hermetic debuginfo then a different approach might be desirable. * Add an RPM example that generates debuginfo This provides a basic example that generates a debuginfo RPM configured to run on CentOS7. * Upgrade rules_python to 0.31.0 rules_python seems to fail us when we're generating debuginfo RPMs unless we upgrade to a version more recent than 0.24.0. * Only generate debuginfo RPM when pkg_rpm() asks for it In lieu of enabling this behaviour by default on the supported platforms, we add an additional argument to the pkg_rpm() rule that will allow us to enable it for pkg_rpm() targets. This prevents us from enabling it in cases where it's not desired. * Add test for building debuginfo RPM This test is modelled on the subrpm test. In lieu of using a simple text file as an input it instead generates a binary that includes debug symbosl from a C source file and includes that in the RPM. The baseline comparison strips out the `.build-id` paths because the hashes that are generated may not be stable.x * Remove architecture and size from debuginfo test output These values may vary depending on the platform that this is being run on and we don't really care about them. * Add period to docstring * Enable debuginfo support for CentOS Stream 9 CentOS Stream 9 appears to work more or less the same for debuginfo generation as CentOS 7. `os-release` describes it as os == `centos` and version == `9`. This change creates an extra token for `centos9` and sticks it in the places where we currently have controls for `centos7`.
- Loading branch information
Showing
13 changed files
with
354 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files") | ||
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") | ||
|
||
cc_binary( | ||
name = "test", | ||
copts = ["-g"], | ||
srcs = [ | ||
"test.c", | ||
], | ||
) | ||
|
||
pkg_files( | ||
name = "rpm_files", | ||
srcs = [ | ||
":test", | ||
], | ||
) | ||
|
||
pkg_rpm( | ||
name = "test-rpm", | ||
srcs = [ | ||
":rpm_files", | ||
], | ||
release = "0", | ||
version = "1", | ||
license = "Some license", | ||
summary = "Summary", | ||
description = "Description", | ||
debuginfo = True, | ||
) | ||
|
||
# If you have rpmbuild, you probably have rpm2cpio too. | ||
# Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain | ||
genrule( | ||
name = "inspect_content", | ||
srcs = [":test-rpm"], | ||
outs = ["content.txt"], | ||
cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") | ||
|
||
bazel_dep(name = "rules_pkg") | ||
|
||
local_path_override( | ||
module_name = "rules_pkg", | ||
path = "../../..", | ||
) | ||
|
||
find_rpmbuild = use_extension( | ||
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", | ||
"find_system_rpmbuild_bzlmod", | ||
) | ||
use_repo(find_rpmbuild, "rules_pkg_rpmbuild") | ||
|
||
register_toolchains( | ||
"@rules_pkg_rpmbuild//:all", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Using system rpmbuild with bzlmod and generating debuginfo | ||
|
||
## Summary | ||
|
||
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 | ||
|
||
``` | ||
bazel build :* | ||
rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt | ||
cat bazel-bin/content.txt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main() { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.