@@ -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`
6063DEBUGINFO_TYPE_NONE = "none"
6164DEBUGINFO_TYPE_CENTOS = "centos"
6265DEBUGINFO_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+
7080def _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