forked from bazelbuild/rules_pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pkg_sub_rpm rule for RPM subpackages (bazelbuild#824)
* rpm: Add support for sub packages to make_rpm.py script Before we can enable support for sub RPM building as part of a single `pkg_rpm()` rule we must add the underlying support to make_pkg.py which is the underlying driver for `pkg_rpm()`. This covers three pieces: * specifying `buildsubdir` rpm variable * capturing multiple RPM files as outputs * injecting sub RPM definitions into specfile * rpm: Factor out rpm_ctx helper The various processing functions pass around a bunch of collections everywhere which is a bit fragile. This collects them together into a struct to make it a bit less messy. * rpm: Factor out _process_dep() helper function _process_dep() handles processing an individual dep and is currently called from the processing loop. We'll need to re-use this logic for processing individual sub RPMs as well so we want it in a helper. * rpm: Capture generated output RPM files in rpm_ctx Currently we only generate one RPM file, but once we generate sub RPM files we'll need to be able to capture those outputs as well. This prepares us for that step. * rpm: Add args for make_rpm to rpm_ctx We'll need to add additional arguments to make_rpm for sub RPM building. It's easier to capture this in our context object than to try to shuttle these bits around. * rpm: Pass correct `--name` argument to make_rpm If we don't pass the correct RPM name to `make_rpm.py` than we won't be able to correctly determine the subrpm names. Currently, the name is only used by `make_rpm` to generate some progress output, so this shouldn't break anything internally. * rpm: Implementation of `pkg_sub_rpm` rule This introduces a `pkg_sub_rpm` rule that allows us to generate and capture RPM subpackages and generate them as part of a single RPM invocation in lieu of cobbling this together from multiple RPM rules. This has a few benefits: - faster execution due to single rpmbuild invocation - sharing configuration between RPMs in the same fashion as vanilla RPM building from a specfile - will enable the proper construction of debuginfo RPMs in a later PR The current implementation *only* works with non-specfile based rules and currently allows for a subset of the general RPM configuration. Internally, the process is for `pkg_sub_rpm` to generate a PackageSubRPMInfo provider that will subsequently get consumed by the `pkg_rpm` rule that generates the actual RPMs. We re-use the internal dependency processing logic that's used by the top-level RPM to generate the content related to the sub-RPM. * rpm: Update entry points for RPM rules to include pkg_sub_rpm This change updates `rpm.bzl` in two ways to account for sub RPMs: - it adds an entrypoint for `pkg_sub_rpm` - it adds a check in `pkg_rpm` to assert incompatibility with `spec_file` * examples: Add an example of how to use the subrpm rule This provides a basic example using the `pkg_sub_rpm` rule to generate multiple RPMs. * Fix buildifier noise * Fix make_rpm failures * doc: Clean up sub-RPM docstring and add to doc_build The initial docstring for pkg_sub_rpm is not great, so this change fixes that while adding this to the list of rules to have documentation generated for them. * doc: Additional documentation for subrpms in pkg_rpm This clarifies the `subrpms` attribute usage as well as indicating the incompatibility with `spec_file` mode. * Fix issue in subrpm passthrough When adding the check to verify if we can use subrpms, this pass through wasn't added. * Add a basic test for pkg_sub_rpm This introduces a basic test with a single sub RPM and main RPM each containing a single source file. * Tweaks to test * Test fixes for CentOS 7 The `rpm` version on CentOS 7 doesn't work exactly the same way as newer versions of rpm and requires a `-p` parameter to inspect non-installed RPMs. CentOS 7 also inserts a `Relocations` field that we didn't see on other platforms so we'll filter that out to make our test a bit more portable. * Move PackageSubRPMInfoProvider into rpm_pfg.bzl This is private to the RPM rules so should probably live there.
- Loading branch information
Showing
11 changed files
with
659 additions
and
190 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,79 @@ | ||
# 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. | ||
# -*- coding: utf-8 -*- | ||
|
||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files") | ||
load("@rules_pkg//pkg:rpm.bzl", "pkg_sub_rpm", "pkg_rpm") | ||
|
||
pkg_files( | ||
name = "subrpm_files", | ||
srcs = [ | ||
"BUILD", | ||
], | ||
) | ||
|
||
pkg_sub_rpm( | ||
name = "subrpm", | ||
package_name = "subrpm", | ||
summary = "Test subrpm", | ||
description = "Test subrpm description", | ||
requires = [ | ||
"somerpm", | ||
], | ||
provides = [ | ||
"someprovision", | ||
], | ||
srcs = [ | ||
":subrpm_files", | ||
], | ||
) | ||
|
||
pkg_files( | ||
name = "rpm_files", | ||
srcs = [ | ||
"MODULE.bazel", | ||
"README.md", | ||
], | ||
) | ||
|
||
pkg_rpm( | ||
name = "test-rpm", | ||
srcs = [ | ||
":rpm_files", | ||
], | ||
release = "0", | ||
version = "1", | ||
summary = "rules_pkg example RPM", | ||
description = "This is a package description.", | ||
license = "Apache License, v2.0", | ||
architecture = "x86_64", | ||
requires = [ | ||
"somerpm", | ||
], | ||
provides = [ | ||
"somefile", | ||
], | ||
subrpms = [ | ||
":subrpm", | ||
], | ||
) | ||
|
||
# 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,14 @@ | ||
# Using system rpmbuild with bzlmod | ||
|
||
## Summary | ||
|
||
This example builds an RPM using the system `rpmbuild` from a pure bazel | ||
`pkg_rpm()` definition instead of using a separate specfile. | ||
|
||
## 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
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 |
---|---|---|
|
@@ -21,4 +21,6 @@ ${POSTUN_SCRIPTLET} | |
|
||
${POSTTRANS_SCRIPTLET} | ||
|
||
${SUBRPMS} | ||
|
||
${CHANGELOG} |
Oops, something went wrong.