summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2024-02-15 12:23:16 -0800
committerYifan Hong <elsk@google.com>2024-03-06 11:20:20 -0800
commitc51f304b2a48f269c8e7489b00d10798a8a6900c (patch)
tree1cf377155655b535fb7e8b2f3447c69ad8549318
parente09d1c99f5990a15e94144d7eea3c3368e4f965c (diff)
downloadbuild-c51f304b2a48f269c8e7489b00d10798a8a6900c.tar.gz
kleaf: Add declare_kernel_prebuilts.
Port kernel_prebuilt_repo to bzlmod extension and put it in kernel_prebuilt_ext.bzl. build_number and artifact_url_fmt is removed from declare_kernel_prebuilts. We can add it back later if there's a need. For now, always require prebuilts to be pre-checked in. Bug: 291918087 Change-Id: Ie26eeb28e82f687522a226f0034ef56a4baebdbe
-rw-r--r--kleaf/BUILD.bazel1
-rw-r--r--kleaf/docs/BUILD.bazel1
-rw-r--r--kleaf/docs/api_reference/kernel_prebuilt_ext.md40
-rw-r--r--kleaf/impl/BUILD.bazel1
-rw-r--r--kleaf/impl/declare_kernel_prebuilts.bzl103
-rw-r--r--kleaf/kernel_prebuilt_ext.bzl33
6 files changed, 179 insertions, 0 deletions
diff --git a/kleaf/BUILD.bazel b/kleaf/BUILD.bazel
index 17b32a4..a0f08ca 100644
--- a/kleaf/BUILD.bazel
+++ b/kleaf/BUILD.bazel
@@ -768,6 +768,7 @@ exports_files(
"fail.bzl",
"hermetic_tools.bzl",
"kernel.bzl",
+ "kernel_prebuilt_ext.bzl",
"key_value_repo.bzl",
"print_debug.bzl",
"update_source_file.bzl",
diff --git a/kleaf/docs/BUILD.bazel b/kleaf/docs/BUILD.bazel
index 3260eab..9b60097 100644
--- a/kleaf/docs/BUILD.bazel
+++ b/kleaf/docs/BUILD.bazel
@@ -34,6 +34,7 @@ _SRCS = [
"//build/kernel/kleaf:fail.bzl",
"//build/kernel/kleaf:hermetic_tools.bzl",
"//build/kernel/kleaf:kernel.bzl",
+ "//build/kernel/kleaf:kernel_prebuilt_ext.bzl",
"//build/kernel/kleaf:key_value_repo.bzl",
"//build/kernel/kleaf:print_debug.bzl",
"//build/kernel/kleaf:update_source_file.bzl",
diff --git a/kleaf/docs/api_reference/kernel_prebuilt_ext.md b/kleaf/docs/api_reference/kernel_prebuilt_ext.md
new file mode 100644
index 0000000..fe939ac
--- /dev/null
+++ b/kleaf/docs/api_reference/kernel_prebuilt_ext.md
@@ -0,0 +1,40 @@
+<!-- Generated with Stardoc: http://skydoc.bazel.build -->
+
+Extension that helps building Android kernel and drivers.
+
+<a id="kernel_prebuilt_ext"></a>
+
+## kernel_prebuilt_ext
+
+<pre>
+kernel_prebuilt_ext = use_extension("@kleaf//build/kernel/kleaf:kernel_prebuilt_ext.bzl", "kernel_prebuilt_ext")
+kernel_prebuilt_ext.declare_kernel_prebuilts(<a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-name">name</a>, <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-artifact_url_fmt">artifact_url_fmt</a>, <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-auto_download_config">auto_download_config</a>,
+ <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-build_number">build_number</a>, <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-download_config">download_config</a>, <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-local_artifact_path">local_artifact_path</a>,
+ <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-mandatory">mandatory</a>, <a href="#kernel_prebuilt_ext.declare_kernel_prebuilts-target">target</a>)
+</pre>
+
+Extension that manages what prebuilts Kleaf should use.
+
+
+**TAG CLASSES**
+
+<a id="kernel_prebuilt_ext.declare_kernel_prebuilts"></a>
+
+### declare_kernel_prebuilts
+
+Declares a repo that contains kernel prebuilts
+
+**Attributes**
+
+| Name | Description | Type | Mandatory | Default |
+| :------------- | :------------- | :------------- | :------------- | :------------- |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-name"></a>name | name of repository | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-artifact_url_fmt"></a>artifact_url_fmt | API endpoint for Android CI artifacts.<br><br>The format may include anchors for the following properties: * {build_number} * {target} * {filename}<br><br>Its default value is the API endpoint for http://ci.android.com.<br><br>Regardless of whether you are downloading from a remote server with `http://` URLs or from local machine with `file://` URLs, `--config=internet` is needed. Hence, if you want to use local files, set `local_artifact_path`. | String | optional | `"https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds/{build_number}/{target}/attempts/latest/artifacts/{filename}/url?redirect=true"` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-auto_download_config"></a>auto_download_config | If `True`, infer `download_config` and `mandatory` from `target`. | Boolean | optional | `False` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-build_number"></a>build_number | build number to be used in `artifact_url_fmt`.<br><br>Unlike `kernel_prebuilt_repo`, the environment variable `KLEAF_DOWNLOAD_BUILD_NUMBER_MAP` is **NOT** respected. | String | optional | `""` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-download_config"></a>download_config | Configure the list of files to download.<br><br>Key: local file name.<br><br>Value: remote file name format string, with the following anchors: * {build_number} * {target} | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-local_artifact_path"></a>local_artifact_path | Directory to local artifacts.<br><br>If set, `artifact_url_fmt` is ignored.<br><br>Only the root module may call `declare()` with this attribute set.<br><br>If relative, it is interpreted against workspace root.<br><br>If absolute, this is similar to setting `artifact_url_fmt` to `file://<absolute local_artifact_path>/{filename}`, but avoids using `download()`. Files are symlinked not copied, and `--config=internet` is not necessary. | String | optional | `""` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-mandatory"></a>mandatory | Configure whether files are mandatory.<br><br>Key: local file name.<br><br>Value: Whether the file is mandatory.<br><br>If a file name is not found in the dictionary, default value is `True`. If mandatory, failure to download the file results in a build failure. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
+| <a id="kernel_prebuilt_ext.declare_kernel_prebuilts-target"></a>target | Name of the build target as identified by the remote build server.<br><br>This attribute has two effects:<br><br>* Replaces the `{target}` anchor in `artifact_url_fmt`. If `artifact_url_fmt` does not have the `{target}` anchor, this has no effect.<br><br>* If `auto_download_config` is `True`, `download_config` and `mandatory` is inferred from a list of known configs keyed on `target`. | String | optional | `"kernel_aarch64"` |
+
+
diff --git a/kleaf/impl/BUILD.bazel b/kleaf/impl/BUILD.bazel
index 285928f..79aa81b 100644
--- a/kleaf/impl/BUILD.bazel
+++ b/kleaf/impl/BUILD.bazel
@@ -60,6 +60,7 @@ bzl_library(
"ddk/makefiles.bzl",
"debug.bzl",
"declare_host_tools.bzl",
+ "declare_kernel_prebuilts.bzl",
"declare_toolchain_constants.bzl",
"file.bzl",
"file_selector.bzl",
diff --git a/kleaf/impl/declare_kernel_prebuilts.bzl b/kleaf/impl/declare_kernel_prebuilts.bzl
new file mode 100644
index 0000000..53c527b
--- /dev/null
+++ b/kleaf/impl/declare_kernel_prebuilts.bzl
@@ -0,0 +1,103 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Helper to kernel_prebuilt_ext to define kernel prebuilt repo."""
+
+load(":kernel_prebuilt_repo.bzl", "kernel_prebuilt_repo")
+
+visibility("//build/kernel/kleaf/...")
+
+_tag_class = tag_class(
+ doc = "Declares a repo that contains kernel prebuilts",
+ attrs = {
+ "name": attr.string(
+ doc = "name of repository",
+ mandatory = True,
+ ),
+ "local_artifact_path": attr.string(
+ doc = """Directory to local artifacts.
+
+ If set, `artifact_url_fmt` is ignored.
+
+ Only the root module may call `declare()` with this attribute set.
+
+ If relative, it is interpreted against workspace root.
+
+ If absolute, this is similar to setting `artifact_url_fmt` to
+ `file://<absolute local_artifact_path>/{filename}`, but avoids
+ using `download()`. Files are symlinked not copied, and
+ `--config=internet` is not necessary.
+ """,
+ ),
+ "auto_download_config": attr.bool(
+ doc = """If `True`, infer `download_config` and `mandatory`
+ from `target`.""",
+ ),
+ "download_config": attr.string_dict(
+ doc = """Configure the list of files to download.
+
+ Key: local file name.
+
+ Value: remote file name format string, with the following anchors:
+ * {build_number}
+ * {target}
+ """,
+ ),
+ "mandatory": attr.string_dict(
+ doc = """Configure whether files are mandatory.
+
+ Key: local file name.
+
+ Value: Whether the file is mandatory.
+
+ If a file name is not found in the dictionary, default
+ value is `True`. If mandatory, failure to download the
+ file results in a build failure.
+ """,
+ ),
+ "target": attr.string(
+ doc = """Name of the build target as identified by the remote build server.
+
+ This attribute has two effects:
+
+ * Replaces the `{target}` anchor in `artifact_url_fmt`.
+ If `artifact_url_fmt` does not have the `{target}` anchor,
+ this has no effect.
+
+ * If `auto_download_config` is `True`, `download_config`
+ and `mandatory` is inferred from a
+ list of known configs keyed on `target`.
+ """,
+ default = "kernel_aarch64",
+ ),
+ },
+)
+
+def _declare_repos(module_ctx, tag_name):
+ for module in module_ctx.modules:
+ for module_tag in getattr(module.tags, tag_name):
+ kernel_prebuilt_repo(
+ name = module_tag.name,
+ apparent_name = module_tag.name,
+ local_artifact_path = module_tag.local_artifact_path,
+ auto_download_config = module_tag.auto_download_config,
+ download_config = module_tag.download_config,
+ mandatory = module_tag.mandatory,
+ target = module_tag.target,
+ )
+
+declare_kernel_prebuilts = struct(
+ declare_repos = _declare_repos,
+ tag_class = _tag_class,
+)
diff --git a/kleaf/kernel_prebuilt_ext.bzl b/kleaf/kernel_prebuilt_ext.bzl
new file mode 100644
index 0000000..7b1d31f
--- /dev/null
+++ b/kleaf/kernel_prebuilt_ext.bzl
@@ -0,0 +1,33 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Extension that helps building Android kernel and drivers."""
+
+load(
+ "//build/kernel/kleaf/impl:declare_kernel_prebuilts.bzl",
+ "declare_kernel_prebuilts",
+)
+
+visibility("public")
+
+def _kernel_prebuilt_ext_impl(module_ctx):
+ declare_kernel_prebuilts.declare_repos(module_ctx, "declare_kernel_prebuilts")
+
+kernel_prebuilt_ext = module_extension(
+ doc = "Extension that manages what prebuilts Kleaf should use.",
+ implementation = _kernel_prebuilt_ext_impl,
+ tag_classes = {
+ "declare_kernel_prebuilts": declare_kernel_prebuilts.tag_class,
+ },
+)