Skip to content

Commit 5df7fb1

Browse files
authored
Generic debuginfo RPM platform support (#942)
This change splits the `debuginfo` RPM support into `fedora` and `centos`, and bundles `almalinux` into the `centos` category. This facilitates future support as more versions are being added as opposed to hardcoding every individual OS name and version combination. The fedora and centos specific logic remains unchanged.
1 parent f68b1de commit 5df7fb1

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

pkg/make_rpm.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ class RpmBuilder(object):
178178
RPMS_DIR = 'RPMS'
179179
DIRS = [SOURCE_DIR, BUILD_DIR, RPMS_DIR, TEMP_DIR]
180180

181+
# `debuginfo` RPM types as defined in `toolchains/rpm/rpmbuild_configure.bzl`
182+
DEBUGINFO_TYPE_NONE = "none"
183+
DEBUGINFO_TYPE_CENTOS = "centos"
184+
DEBUGINFO_TYPE_FEDORA = "fedora"
185+
SUPPORTED_DEBUGINFO_TYPES = {
186+
DEBUGINFO_TYPE_CENTOS,
187+
DEBUGINFO_TYPE_FEDORA,
188+
}
189+
181190
def __init__(self, name, version, release, arch, rpmbuild_path,
182191
source_date_epoch=None,
183192
debug=False):
@@ -362,7 +371,7 @@ def CallRpmBuild(self, dirname, rpmbuild_args, debuginfo_type):
362371
if self.debug:
363372
args.append('-vv')
364373

365-
if debuginfo_type == "fedora40":
374+
if debuginfo_type == RpmBuilder.DEBUGINFO_TYPE_FEDORA:
366375
os.makedirs(f'{dirname}/{RpmBuilder.BUILD_DIR}/{RpmBuilder.BUILD_SUBDIR}')
367376

368377
# Common options
@@ -375,13 +384,13 @@ def CallRpmBuild(self, dirname, rpmbuild_args, debuginfo_type):
375384
'--define', '_builddir %s/BUILD' % dirname,
376385
]
377386

378-
if debuginfo_type in ["fedora40", "centos7", "centos9", "almalinux9.3"]:
387+
if debuginfo_type in RpmBuilder.SUPPORTED_DEBUGINFO_TYPES:
379388
args += ['--undefine', '_debugsource_packages']
380389

381-
if debuginfo_type in ["centos7", "centos9", "almalinux9.3"]:
390+
if debuginfo_type == RpmBuilder.DEBUGINFO_TYPE_CENTOS:
382391
args += ['--define', 'buildsubdir .']
383392

384-
if debuginfo_type == "fedora40":
393+
if debuginfo_type == RpmBuilder.DEBUGINFO_TYPE_FEDORA:
385394
args += ['--define', f'buildsubdir {RpmBuilder.BUILD_SUBDIR}']
386395

387396
args += [
@@ -399,7 +408,7 @@ def CallRpmBuild(self, dirname, rpmbuild_args, debuginfo_type):
399408
if self.file_list_path:
400409
# %files -f is taken relative to the package root
401410
base_path = os.path.basename(self.file_list_path)
402-
if debuginfo_type == "fedora40":
411+
if debuginfo_type == RpmBuilder.DEBUGINFO_TYPE_FEDORA:
403412
base_path = os.path.join("..", base_path)
404413

405414
args += ['--define', 'build_rpm_files %s' % base_path]
@@ -556,30 +565,31 @@ def main(argv):
556565
parser.add_argument('--install_script',
557566
help='Installer script')
558567
parser.add_argument('--file_list',
559-
help='File containing a list of files to include with rpm spec %files -f')
568+
help='File containing a list of files to include with rpm spec %%files -f')
560569
parser.add_argument('--preamble',
561570
help='File containing the RPM Preamble')
562571
parser.add_argument('--description',
563-
help='File containing the RPM %description text')
572+
help='File containing the RPM %%description text')
564573
parser.add_argument('--subrpms',
565574
help='File containing the RPM subrpm details')
566575
parser.add_argument('--pre_scriptlet',
567-
help='File containing the RPM %pre scriptlet, if to be substituted')
576+
help='File containing the RPM %%pre scriptlet, if to be substituted')
568577
parser.add_argument('--post_scriptlet',
569-
help='File containing the RPM %post scriptlet, if to be substituted')
578+
help='File containing the RPM %%post scriptlet, if to be substituted')
570579
parser.add_argument('--preun_scriptlet',
571-
help='File containing the RPM %preun scriptlet, if to be substituted')
580+
help='File containing the RPM %%preun scriptlet, if to be substituted')
572581
parser.add_argument('--postun_scriptlet',
573-
help='File containing the RPM %postun scriptlet, if to be substituted')
582+
help='File containing the RPM %%postun scriptlet, if to be substituted')
574583
parser.add_argument('--posttrans_scriptlet',
575-
help='File containing the RPM %posttrans scriptlet, if to be substituted')
584+
help='File containing the RPM %%posttrans scriptlet, if to be substituted')
576585
parser.add_argument('--changelog',
577586
help='File containing the RPM changelog text')
578587

579588
parser.add_argument('--rpmbuild_arg', dest='rpmbuild_args', action='append',
580589
help='Any additional arguments to pass to rpmbuild')
581-
parser.add_argument('--debuginfo_type', dest='debuginfo_type', default='none',
582-
help='debuginfo type to use (centos7, fedora40, or none)')
590+
parser.add_argument('--debuginfo_type', default=RpmBuilder.DEBUGINFO_TYPE_NONE,
591+
choices=sorted(RpmBuilder.SUPPORTED_DEBUGINFO_TYPES) + [RpmBuilder.DEBUGINFO_TYPE_NONE],
592+
help='debuginfo type to use')
583593
parser.add_argument('files', nargs='*')
584594

585595
options = parser.parse_args(argv or ())

pkg/rpm_pfg.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild")
2525
```
2626
"""
2727

28+
load(
29+
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl",
30+
"DEBUGINFO_TYPE_FEDORA",
31+
"DEBUGINFO_TYPE_NONE",
32+
)
2833
load(
2934
"//pkg:providers.bzl",
3035
"PackageDirsInfo",
@@ -223,7 +228,7 @@ def _process_files(pfi, origin_label, grouping_label, file_base, rpm_ctx, debugi
223228
rpm_ctx.rpm_files_list.append(_FILE_MODE_STANZA_FMT.format(file_base, abs_dest))
224229

225230
install_stanza_fmt = _INSTALL_FILE_STANZA_FMT
226-
if debuginfo_type == "fedora40":
231+
if debuginfo_type == DEBUGINFO_TYPE_FEDORA:
227232
install_stanza_fmt = _INSTALL_FILE_STANZA_FMT_FEDORA40_DEBUGINFO
228233

229234
rpm_ctx.install_script_pieces.append(install_stanza_fmt.format(
@@ -470,7 +475,7 @@ def _pkg_rpm_impl(ctx):
470475

471476
files = []
472477
tools = []
473-
debuginfo_type = "none"
478+
debuginfo_type = DEBUGINFO_TYPE_NONE
474479
name = ctx.attr.package_name if ctx.attr.package_name else ctx.label.name
475480
rpm_ctx.make_rpm_args.append("--name=" + name)
476481

@@ -755,7 +760,7 @@ def _pkg_rpm_impl(ctx):
755760
files.append(subrpm_file)
756761
rpm_ctx.make_rpm_args.append("--subrpms=" + subrpm_file.path)
757762

758-
if debuginfo_type != "none":
763+
if debuginfo_type != DEBUGINFO_TYPE_NONE:
759764
debuginfo_default_file = ctx.actions.declare_file(
760765
"{}-debuginfo.rpm".format(rpm_name),
761766
)

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 centos7, fedora40, or none
63+
One of `centos`, `fedora`, and `none`
6464
""",
6565
default = "none",
6666
),

toolchains/rpm/rpmbuild_configure.bzl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,21 @@ def _parse_release_info(release_info):
5757

5858
return os_name, os_version
5959

60-
KNOWN_DEBUGINFO_VERSIONS = {
61-
"almalinux": ["9.3"],
62-
"centos": ["7", "9"],
63-
"fedora": ["40"],
60+
DEBUGINFO_TYPE_NONE = "none"
61+
DEBUGINFO_TYPE_CENTOS = "centos"
62+
DEBUGINFO_TYPE_FEDORA = "fedora"
63+
64+
DEBUGINFO_TYPE_BY_OS_RELEASE = {
65+
"almalinux": DEBUGINFO_TYPE_CENTOS,
66+
"centos": DEBUGINFO_TYPE_CENTOS,
67+
"fedora": DEBUGINFO_TYPE_FEDORA,
6468
}
6569

6670
def _build_repo_for_rpmbuild_toolchain_impl(rctx):
67-
debuginfo_type = "none"
71+
debuginfo_type = DEBUGINFO_TYPE_NONE
6872
if rctx.path(RELEASE_PATH).exists:
69-
os_name, os_version = _parse_release_info(rctx.read(RELEASE_PATH))
70-
if (os_name in KNOWN_DEBUGINFO_VERSIONS and
71-
os_version in KNOWN_DEBUGINFO_VERSIONS[os_name]):
72-
debuginfo_type = os_name + os_version
73+
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
74+
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
7375

7476
rpmbuild_path = rctx.which("rpmbuild")
7577
if rctx.attr.verbose:
@@ -110,7 +112,7 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
110112
doc = """
111113
The underlying debuginfo configuration for the system rpmbuild.
112114
113-
One of centos7, fedora40, or none
115+
One of `centos`, `fedora`, and `none`
114116
""",
115117
default = "none",
116118
),

0 commit comments

Comments
 (0)