summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2024-03-14 18:00:48 -0700
committerYifan Hong <elsk@google.com>2024-03-15 20:45:21 +0000
commitc3f8d7d9252dbdb5edd20ee29d6815770826d194 (patch)
tree44073fd7e8d81791130eabd2dc6c7cd88c15afae
parentd4d063963778f294f747f778cf75692aeacf9106 (diff)
downloadbuild-c3f8d7d9252dbdb5edd20ee29d6815770826d194.tar.gz
kleaf: kernel_prebuilt_repo specifies kernel_filegroup
After this change, usually, @gki_prebuilts//kernel_aarch64 points to the kernel_filegroup. This target replaces the @kleaf//common:kernel_aarch64_downloaded_or_build targets. The targets in @kleaf//common requires the following declaration in MODULE.bazel to work: use_repo(kernel_prebuilt_ext, "gki_prebuilts") However, per design, the name "gki_prebuilts" is defined by the MODULE.bazel of the root module (the Bazel module that holds the DDK drivers), and it does not need to have this specific name. Hence, move the target to @gki_prebuilts so the root module can use the @gki_prebuilts//kernel_aarch64 target directly. Test: TH Bug: 291918087 Change-Id: If93827580a2d70bf68dee1f787477034ecfd0b6c
-rw-r--r--kleaf/impl/kernel_prebuilt_repo.bzl46
-rw-r--r--kleaf/impl/kernel_prebuilt_utils.bzl2
2 files changed, 48 insertions, 0 deletions
diff --git a/kleaf/impl/kernel_prebuilt_repo.bzl b/kleaf/impl/kernel_prebuilt_repo.bzl
index 38b4ce0..6882752 100644
--- a/kleaf/impl/kernel_prebuilt_repo.bzl
+++ b/kleaf/impl/kernel_prebuilt_repo.bzl
@@ -15,6 +15,11 @@
"""Repository for kernel prebuilts."""
load(
+ ":constants.bzl",
+ "FILEGROUP_DEF_ARCHIVE_SUFFIX",
+ "FILEGROUP_DEF_TEMPLATE_NAME",
+)
+load(
":kernel_prebuilt_utils.bzl",
"CI_TARGET_MAPPING",
"GKI_DOWNLOAD_CONFIGS",
@@ -254,10 +259,51 @@ filegroup(
)
repository_ctx.file(_join(local_filename, "BUILD.bazel"), content)
+ _create_top_level_files(repository_ctx, download_config)
+
+def _create_top_level_files(repository_ctx, download_config):
+ bazel_target_name = repository_ctx.attr.target
repository_ctx.file("""WORKSPACE.bazel""", """\
workspace({})
""".format(repr(repository_ctx.attr.name)))
+ filegroup_decl_archives = []
+ for local_filename in download_config:
+ if _basename(local_filename).endswith(FILEGROUP_DEF_ARCHIVE_SUFFIX):
+ local_path = repository_ctx.path(_join(local_filename, _basename(local_filename)))
+ filegroup_decl_archives.append(local_path)
+
+ if not filegroup_decl_archives:
+ return
+ if len(filegroup_decl_archives) > 1:
+ fail("Multiple files with suffix {}: {}".format(
+ FILEGROUP_DEF_ARCHIVE_SUFFIX,
+ filegroup_decl_archives,
+ ))
+
+ filegroup_decl_archive = filegroup_decl_archives[0]
+ repository_ctx.extract(
+ # If local_artifact_path is set, filegroup_decl_archive is a symlink.
+ # The symlink is under the working directory so we can't set
+ # watch_archive = "yes".
+ # Use realpath (which may point outside the working directory) and
+ # watch_archive = "auto" (the default) achieves optimal effect.
+ archive = filegroup_decl_archive.realpath,
+ output = repository_ctx.path(bazel_target_name),
+ )
+
+ template_path = repository_ctx.path(_join(bazel_target_name, FILEGROUP_DEF_TEMPLATE_NAME))
+ template_content = repository_ctx.read(template_path)
+
+ repository_ctx.file(repository_ctx.path(_join(bazel_target_name, "BUILD.bazel")), """\
+load({kernel_bzl_repr}, "kernel_filegroup")
+
+{template_content}
+""".format(
+ kernel_bzl_repr = repr(str(Label("//build/kernel/kleaf:kernel.bzl"))),
+ template_content = template_content,
+ ))
+
kernel_prebuilt_repo = repository_rule(
implementation = _kernel_prebuilt_repo_impl,
attrs = {
diff --git a/kleaf/impl/kernel_prebuilt_utils.bzl b/kleaf/impl/kernel_prebuilt_utils.bzl
index 4da59e0..82028c6 100644
--- a/kleaf/impl/kernel_prebuilt_utils.bzl
+++ b/kleaf/impl/kernel_prebuilt_utils.bzl
@@ -20,6 +20,7 @@ load(
)
load(
":constants.bzl",
+ "FILEGROUP_DEF_ARCHIVE_SUFFIX",
"GKI_ARTIFACTS_AARCH64_OUTS",
"MODULES_STAGING_ARCHIVE",
"MODULE_OUTS_FILE_SUFFIX",
@@ -91,6 +92,7 @@ GKI_DOWNLOAD_CONFIGS = [
{
"target_suffix": "ddk_artifacts",
"outs": [
+ "kernel_aarch64" + FILEGROUP_DEF_ARCHIVE_SUFFIX,
# TODO(b/291918087): Drop after common_kernels no longer use kernel_filegroup.
# These files should already be in kernel_filegroup_declaration.
# _modules_prepare