Skip to content

Commit 15732c6

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 15732c6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

toolchains/rpm/rpmbuild_configure.bzl

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

5858
return os_name, os_version
5959

60+
DEBUGINFO_TYPE_DEFAULT = "default"
6061
DEBUGINFO_TYPE_NONE = "none"
6162
DEBUGINFO_TYPE_CENTOS = "centos"
6263
DEBUGINFO_TYPE_FEDORA = "fedora"
@@ -67,11 +68,25 @@ DEBUGINFO_TYPE_BY_OS_RELEASE = {
6768
"fedora": DEBUGINFO_TYPE_FEDORA,
6869
}
6970

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

7691
rpmbuild_path = rctx.which("rpmbuild")
7792
if rctx.attr.verbose:
@@ -80,9 +95,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
8095
else:
8196
print("No system rpmbuild found.") # buildifier: disable=print
8297

83-
if rctx.attr.debuginfo_type not in ["centos7", "fedora40", "none"]:
84-
fail("debuginfo_type must be one of centos7, fedora40, or none")
85-
8698
version = "unknown"
8799
if rpmbuild_path:
88100
res = rctx.execute([rpmbuild_path, "--version"])
@@ -112,9 +124,9 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
112124
doc = """
113125
The underlying debuginfo configuration for the system rpmbuild.
114126
115-
One of `centos`, `fedora`, and `none`
127+
One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`)
116128
""",
117-
default = "none",
129+
default = DEBUGINFO_TYPE_DEFAULT,
118130
),
119131
},
120132
)

0 commit comments

Comments
 (0)