diff --git a/pkg/rpm_pfg.bzl b/pkg/rpm_pfg.bzl index 9f4adccc..53a86268 100644 --- a/pkg/rpm_pfg.bzl +++ b/pkg/rpm_pfg.bzl @@ -25,11 +25,6 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild") ``` """ -load( - "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", - "DEBUGINFO_TYPE_FEDORA", - "DEBUGINFO_TYPE_NONE", -) load( "//pkg:providers.bzl", "PackageDirsInfo", @@ -39,6 +34,11 @@ load( "PackageVariablesInfo", ) load("//pkg/private:util.bzl", "setup_output_files", "substitute_package_variables") +load( + "//toolchains/rpm:rpmbuild_configure.bzl", + "DEBUGINFO_TYPE_FEDORA", + "DEBUGINFO_TYPE_NONE", +) rpm_filetype = [".rpm"] diff --git a/toolchains/rpm/rpmbuild_configure.bzl b/toolchains/rpm/rpmbuild_configure.bzl index ffa45194..e11f94c4 100644 --- a/toolchains/rpm/rpmbuild_configure.bzl +++ b/toolchains/rpm/rpmbuild_configure.bzl @@ -57,6 +57,9 @@ def _parse_release_info(release_info): return os_name, os_version +DEBUGINFO_TYPE_DEFAULT = "default" + +# The below are also defined in `pkg/make_rpm.py` DEBUGINFO_TYPE_NONE = "none" DEBUGINFO_TYPE_CENTOS = "centos" DEBUGINFO_TYPE_FEDORA = "fedora" @@ -67,11 +70,25 @@ DEBUGINFO_TYPE_BY_OS_RELEASE = { "fedora": DEBUGINFO_TYPE_FEDORA, } +DEBUGINFO_VALID_VALUES = [ + DEBUGINFO_TYPE_FEDORA, + DEBUGINFO_TYPE_CENTOS, + DEBUGINFO_TYPE_NONE, + DEBUGINFO_TYPE_DEFAULT, +] + def _build_repo_for_rpmbuild_toolchain_impl(rctx): - debuginfo_type = DEBUGINFO_TYPE_NONE - if rctx.path(RELEASE_PATH).exists: - os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH)) - debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type) + if rctx.attr.debuginfo_type not in DEBUGINFO_VALID_VALUES: + fail("debuginfo_type must be one of", DEBUGINFO_VALID_VALUES) + + debuginfo_type = rctx.attr.debuginfo_type + if debuginfo_type == DEBUGINFO_TYPE_DEFAULT: + rctx.watch(RELEASE_PATH) + if rctx.path(RELEASE_PATH).exists: + os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH)) + debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type) + else: + debuginfo_type = DEBUGINFO_TYPE_NONE rpmbuild_path = rctx.which("rpmbuild") if rctx.attr.verbose: @@ -80,9 +97,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx): else: print("No system rpmbuild found.") # buildifier: disable=print - if rctx.attr.debuginfo_type not in ["centos7", "fedora40", "none"]: - fail("debuginfo_type must be one of centos7, fedora40, or none") - version = "unknown" if rpmbuild_path: res = rctx.execute([rpmbuild_path, "--version"]) @@ -112,9 +126,9 @@ build_repo_for_rpmbuild_toolchain = repository_rule( doc = """ The underlying debuginfo configuration for the system rpmbuild. - One of `centos`, `fedora`, and `none` + One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`) """, - default = "none", + default = DEBUGINFO_TYPE_DEFAULT, ), }, )