Skip to content

Commit 4ea728f

Browse files
committed
Overridable debuginfo type
This change enables the override of the auto-detected `/etc/os-release`-based `debuginfo` type and allows the auto-detection by means of a new `default` option. This also enables the use of` none` as an override option.
1 parent cd7e108 commit 4ea728f

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

pkg/rpm_pfg.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild")
2626
"""
2727

2828
load(
29-
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl",
29+
"//toolchains/rpm:rpmbuild_configure.bzl",
3030
"DEBUGINFO_TYPE_FEDORA",
3131
"DEBUGINFO_TYPE_NONE",
3232
)

toolchains/rpm/rpmbuild_configure.bzl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def _parse_release_info(release_info):
5757

5858
return os_name, os_version
5959

60+
DEBUGINFO_TYPE_DEFAULT = "default"
61+
62+
# The below are also defined in `pkg/make_rpm.py`
6063
DEBUGINFO_TYPE_NONE = "none"
6164
DEBUGINFO_TYPE_CENTOS = "centos"
6265
DEBUGINFO_TYPE_FEDORA = "fedora"
@@ -67,11 +70,25 @@ DEBUGINFO_TYPE_BY_OS_RELEASE = {
6770
"fedora": DEBUGINFO_TYPE_FEDORA,
6871
}
6972

73+
DEBUGINFO_VALID_VALUES = [
74+
DEBUGINFO_TYPE_FEDORA,
75+
DEBUGINFO_TYPE_CENTOS,
76+
DEBUGINFO_TYPE_NONE,
77+
DEBUGINFO_TYPE_DEFAULT,
78+
]
79+
7080
def _build_repo_for_rpmbuild_toolchain_impl(rctx):
71-
debuginfo_type = DEBUGINFO_TYPE_NONE
72-
if rctx.path(RELEASE_PATH).exists:
73-
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
74-
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
81+
if rctx.attr.debuginfo_type not in DEBUGINFO_VALID_VALUES:
82+
fail("debuginfo_type must be one of", DEBUGINFO_VALID_VALUES)
83+
84+
debuginfo_type = rctx.attr.debuginfo_type
85+
if debuginfo_type == DEBUGINFO_TYPE_DEFAULT:
86+
rctx.watch(RELEASE_PATH)
87+
if rctx.path(RELEASE_PATH).exists:
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
7592

7693
rpmbuild_path = rctx.which("rpmbuild")
7794
if rctx.attr.verbose:
@@ -80,9 +97,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
8097
else:
8198
print("No system rpmbuild found.") # buildifier: disable=print
8299

83-
if rctx.attr.debuginfo_type not in ["centos7", "fedora40", "none"]:
84-
fail("debuginfo_type must be one of centos7, fedora40, or none")
85-
86100
version = "unknown"
87101
if rpmbuild_path:
88102
res = rctx.execute([rpmbuild_path, "--version"])
@@ -112,9 +126,9 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
112126
doc = """
113127
The underlying debuginfo configuration for the system rpmbuild.
114128
115-
One of `centos`, `fedora`, and `none`
129+
One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`)
116130
""",
117-
default = "none",
131+
default = DEBUGINFO_TYPE_DEFAULT,
118132
),
119133
},
120134
)

0 commit comments

Comments
 (0)