diff options
author | Yifan Hong <elsk@google.com> | 2024-03-06 15:23:43 -0800 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2024-03-07 19:34:35 +0000 |
commit | 87a8024fd576d979d34f48ab35dbe9b251966f12 (patch) | |
tree | 904bf9d1218d2caa4fb0e0774fa7cc79c185bbaa | |
parent | 581012a5e44d116defcaf436ca5edbac02753637 (diff) | |
download | build-87a8024fd576d979d34f48ab35dbe9b251966f12.tar.gz |
kleaf: Skip declare_toolchain_constants if using defaults.
If using //common:build.config.constants, simply
skip the declare_toolchain_constants call.
This simplifies the Kleaf's MODULE.bazel, or the
root MODULE.bazel when using Kleaf as the root module.
Test: TH
Bug: 328465178
Change-Id: I16c4e8c15e2ad9e0180100b6485e7dab2075d0ac
-rw-r--r-- | kleaf/bzlmod/bazel.MODULE.bazel | 1 | ||||
-rw-r--r-- | kleaf/impl/declare_toolchain_constants.bzl | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/kleaf/bzlmod/bazel.MODULE.bazel b/kleaf/bzlmod/bazel.MODULE.bazel index 8ea802b..fe47b94 100644 --- a/kleaf/bzlmod/bazel.MODULE.bazel +++ b/kleaf/bzlmod/bazel.MODULE.bazel @@ -55,7 +55,6 @@ new_kleaf_local_repository( ) kernel_toolchain_ext = use_extension("//build/kernel/kleaf:kernel_toolchain_ext.bzl", "kernel_toolchain_ext") -kernel_toolchain_ext.declare_toolchain_constants(toolchain_constants = "//common:build.config.constants") use_repo(kernel_toolchain_ext, "kernel_toolchain_info") use_repo(kernel_toolchain_ext, "kleaf_clang_toolchain") use_repo(kernel_toolchain_ext, "kleaf_host_tools") diff --git a/kleaf/impl/declare_toolchain_constants.bzl b/kleaf/impl/declare_toolchain_constants.bzl index ac99bbb..869efc9 100644 --- a/kleaf/impl/declare_toolchain_constants.bzl +++ b/kleaf/impl/declare_toolchain_constants.bzl @@ -19,6 +19,11 @@ load("//prebuilts/clang/host/linux-x86/kleaf:clang_toolchain_repository.bzl", "c visibility("public") +# Usually we do not refer to //common in build/kernel. This is an exception because +# - It is a sensible default +# - It may be overridden by calling declare_toolchain_constants at the root module +_DEFAULT_TOOLCHAIN_CONSTANTS = "//common:build.config.constants" + def _declare_repos(module_ctx, tag_name): root_toolchain_constants = [] kleaf_toolchain_constants = [] @@ -40,7 +45,7 @@ def _declare_repos(module_ctx, tag_name): toolchain_constants = kleaf_toolchain_constants[0] if not toolchain_constants: - fail("kernel_toolchain_ext is not installed") + toolchain_constants = _DEFAULT_TOOLCHAIN_CONSTANTS key_value_repo( name = "kernel_toolchain_info", @@ -53,7 +58,13 @@ def _declare_repos(module_ctx, tag_name): _tag_class = tag_class( doc = "Declares a potential location that contains toolchain information.", attrs = { - "toolchain_constants": attr.label(mandatory = True), + "toolchain_constants": attr.label( + doc = """Label to `build.config.constants`. + + If `declare_toolchain_constants()` is never called, or called + with `toolchain_constants = None`, default is `{}`. + """.format(repr(_DEFAULT_TOOLCHAIN_CONSTANTS)), + ), }, ) |