summaryrefslogtreecommitdiff
path: root/kleaf
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2024-04-15 19:02:06 -0700
committerTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-04-19 13:13:27 +0000
commit4fdadc8706d505365457a67439514c6c475acb3e (patch)
tree0b4141a980d2cf72e67aa30affbc1f1679b6d80d /kleaf
parent39a504ded7ae7bdde0383f0e30487c3da3e8c5b6 (diff)
downloadbuild-4fdadc8706d505365457a67439514c6c475acb3e.tar.gz
kleaf: Clean up module_outs_file.
Instead of creating a file that has all of module_outs and module_implicit_outs, pass the list directly everywhere. kernel_build also pass the list to kernel_filegroup directly. This makes the representation of kernel_filegroup more straightforward to follow. Test: TH Bug: 332386858 Change-Id: I97a67e8ee5f343fe045b79a2016a34436c32621b
Diffstat (limited to 'kleaf')
-rw-r--r--kleaf/common_kernels.bzl11
-rw-r--r--kleaf/impl/abi/base_kernel_utils.bzl4
-rw-r--r--kleaf/impl/common_providers.bzl7
-rw-r--r--kleaf/impl/constants.bzl8
-rw-r--r--kleaf/impl/kernel_build.bzl85
-rw-r--r--kleaf/impl/kernel_filegroup.bzl9
-rw-r--r--kleaf/impl/kernel_filegroup_declaration.bzl10
-rw-r--r--kleaf/tests/kernel_build_test/kernel_toolchain_test.bzl6
-rw-r--r--kleaf/tests/merged_kernel_uapi_headers_test/order_test.bzl1
9 files changed, 47 insertions, 94 deletions
diff --git a/kleaf/common_kernels.bzl b/kleaf/common_kernels.bzl
index c6de721..3269365 100644
--- a/kleaf/common_kernels.bzl
+++ b/kleaf/common_kernels.bzl
@@ -22,10 +22,6 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//build/kernel/kleaf/artifact_tests:device_modules_test.bzl", "device_modules_test")
load("//build/kernel/kleaf/artifact_tests:kernel_test.bzl", "initramfs_modules_options_test")
-load(
- "//build/kernel/kleaf/impl:constants.bzl",
- "MODULE_OUTS_FILE_OUTPUT_GROUP",
-)
load("//build/kernel/kleaf/impl:gki_artifacts.bzl", "gki_artifacts", "gki_artifacts_prebuilts")
load("//build/kernel/kleaf/impl:kernel_filegroup_declaration.bzl", "kernel_filegroup_declaration")
load(
@@ -981,13 +977,6 @@ def _define_prebuilts(**kwargs):
deprecation = deprecate_msg,
)
- native.filegroup(
- name = name + "_module_outs_file",
- srcs = [":" + name],
- output_group = MODULE_OUTS_FILE_OUTPUT_GROUP,
- deprecation = not_available_msg,
- )
-
# A kernel_filegroup that:
# - If --use_prebuilt_gki_num is set, use downloaded prebuilt of kernel_aarch64
# - Otherwise build kernel_aarch64 from sources.
diff --git a/kleaf/impl/abi/base_kernel_utils.bzl b/kleaf/impl/abi/base_kernel_utils.bzl
index c13aa26..9a3355c 100644
--- a/kleaf/impl/abi/base_kernel_utils.bzl
+++ b/kleaf/impl/abi/base_kernel_utils.bzl
@@ -53,7 +53,7 @@ def _get_base_kernel(ctx):
return None
return ctx.attr.base_kernel
-def _get_base_kernel_for_module_outs(ctx):
+def _get_base_kernel_for_module_names(ctx):
"""Returns base_kernel for getting the list of module_outs in the base kernel (GKI modules)."""
# base_kernel_for_module_outs ignores _force_ignore_base_kernel
@@ -69,6 +69,6 @@ base_kernel_utils = struct(
config_settings_raw = _base_kernel_config_settings_raw,
non_config_attrs = _base_kernel_non_config_attrs,
get_base_kernel = _get_base_kernel,
- get_base_kernel_for_module_outs = _get_base_kernel_for_module_outs,
+ get_base_kernel_for_module_names = _get_base_kernel_for_module_names,
get_base_modules_staging_archive = _get_base_modules_staging_archive,
)
diff --git a/kleaf/impl/common_providers.bzl b/kleaf/impl/common_providers.bzl
index 9b78baa..1f4636c 100644
--- a/kleaf/impl/common_providers.bzl
+++ b/kleaf/impl/common_providers.bzl
@@ -216,7 +216,9 @@ KernelBuildInTreeModulesInfo = provider(
doc = """A provider that specifies the expectations of a [`kernel_build`](kernel.md#kernel_build) on its
[`base_kernel`](kernel.md#kernel_build-base_kernel) for the list of in-tree modules in the `base_kernel`.""",
fields = {
- "module_outs_file": "A file containing `[kernel_build.module_outs]`(kernel.md#kernel_build-module_outs) and `[kernel_build.module_implicit_outs]`(kernel.md#kernel_build-module_implicit_outs).",
+ "all_module_names": """`[kernel_build.module_outs]`(kernel.md#kernel_build-module_outs)
+ and `[kernel_build.module_implicit_outs]`(kernel.md#kernel_build-module_implicit_outs).
+ """,
},
)
@@ -243,8 +245,7 @@ KernelBuildFilegroupDeclInfo = provider(
"filegroup_srcs": """[depset](https://bazel.build/extending/depsets) of
[`File`](https://bazel.build/rules/lib/File)s that the
`kernel_filegroup` should return as default outputs.""",
- # TODO(b/291918087): This may be embedded in the generated BUILD file directly
- "module_outs_file": """A file containing
+ "all_module_names": """
`[kernel_build.module_outs]`(kernel.md#kernel_build-module_outs) and
`[kernel_build.module_implicit_outs]`(kernel.md#kernel_build-module_implicit_outs).""",
"modules_staging_archive": "Archive containing staging kernel modules. ",
diff --git a/kleaf/impl/constants.bzl b/kleaf/impl/constants.bzl
index c4f74e3..33f1b41 100644
--- a/kleaf/impl/constants.bzl
+++ b/kleaf/impl/constants.bzl
@@ -16,14 +16,6 @@
visibility("//build/kernel/kleaf/...")
-# The suffix of the file in the default outputs of kernel_build that stores
-# the list of `module_outs` for that kernel_build.
-MODULE_OUTS_FILE_SUFFIX = "_modules"
-
-# The output group of the file of a kernel_build that stores
-# the list of `module_outs` for that kernel_build.
-MODULE_OUTS_FILE_OUTPUT_GROUP = "module_outs_file"
-
# List of images produced by non-x86 kernels.
DEFAULT_IMAGES = [
"Image",
diff --git a/kleaf/impl/kernel_build.bzl b/kleaf/impl/kernel_build.bzl
index 02f6cdb..7ddca76 100644
--- a/kleaf/impl/kernel_build.bzl
+++ b/kleaf/impl/kernel_build.bzl
@@ -55,8 +55,6 @@ load(
":constants.bzl",
"MODULES_STAGING_ARCHIVE",
"MODULE_ENV_ARCHIVE_SUFFIX",
- "MODULE_OUTS_FILE_OUTPUT_GROUP",
- "MODULE_OUTS_FILE_SUFFIX",
)
load(":debug.bzl", "debug")
load(":file.bzl", "file")
@@ -846,12 +844,6 @@ def _uniq(lst):
"""Deduplicates items in lst."""
return sets.to_list(sets.make(lst))
-def _path_or_empty(file):
- """Returns path of the file if it is not `None`, otherwise empty string."""
- if not file:
- return ""
- return file.path
-
def _progress_message_suffix(ctx):
"""Returns suffix for all progress messages for kernel_build."""
return "{}{}".format(
@@ -910,15 +902,12 @@ def _create_kbuild_mixed_tree(ctx):
arg = arg,
)
-def _get_base_kernel_all_module_names_file(ctx):
- """Returns the file containing all module names from the base kernel or None if there's no base_kernel."""
- base_kernel_for_module_outs = base_kernel_utils.get_base_kernel_for_module_outs(ctx)
- if base_kernel_for_module_outs:
- base_kernel_all_module_names_file = base_kernel_for_module_outs[KernelBuildInTreeModulesInfo].module_outs_file
- if not base_kernel_all_module_names_file:
- fail("{}: base_kernel {} does not provide module_outs_file.".format(ctx.label, base_kernel_utils.get_base_kernel(ctx).label))
- return base_kernel_all_module_names_file
- return None
+def _get_base_kernel_all_module_names(ctx):
+ """Returns the file containing all module names from the base kernel or `[]` if there's no base_kernel."""
+ base_kernel_for_module_names = base_kernel_utils.get_base_kernel_for_module_names(ctx)
+ if base_kernel_for_module_names:
+ return base_kernel_for_module_names[KernelBuildInTreeModulesInfo].all_module_names
+ return []
def _get_out_attr_vals(ctx):
"""Common implementation for getting all ctx.attr.*out.
@@ -1015,7 +1004,7 @@ def _get_interceptor_step(ctx):
output_file = interceptor_output,
)
-def _get_grab_intree_modules_step(ctx, has_any_modules, modules_staging_dir, ruledir, all_module_names_file):
+def _get_grab_intree_modules_step(ctx, has_any_modules, modules_staging_dir, ruledir, all_module_names):
"""Returns a step for grabbing the in-tree modules from `OUT_DIR`.
Returns:
@@ -1031,12 +1020,12 @@ def _get_grab_intree_modules_step(ctx, has_any_modules, modules_staging_dir, rul
if has_any_modules:
tools.append(ctx.executable._search_and_cp_output)
grab_intree_modules_cmd = """
- {search_and_cp_output} --srcdir {modules_staging_dir}/lib/modules/*/kernel --dstdir {ruledir} $(cat {all_module_names_file})
+ {search_and_cp_output} --srcdir {modules_staging_dir}/lib/modules/*/kernel --dstdir {ruledir} {all_module_names}
""".format(
search_and_cp_output = ctx.executable._search_and_cp_output.path,
modules_staging_dir = modules_staging_dir,
ruledir = ruledir,
- all_module_names_file = all_module_names_file.path,
+ all_module_names = " ".join(all_module_names),
)
return struct(
inputs = [],
@@ -1090,8 +1079,8 @@ def _get_grab_unstripped_modules_step(ctx, has_any_modules, all_module_basenames
def _get_check_remaining_modules_step(
ctx,
- all_module_names_file,
- base_kernel_all_module_names_file,
+ all_module_names,
+ base_kernel_all_module_names,
modules_staging_dir):
"""Returns a step for checking remaining '*.ko' files in `OUT_DIR`.
@@ -1122,7 +1111,7 @@ def _get_check_remaining_modules_step(
cmd = """
remaining_ko_files=$({check_declared_output_list} \\
- --declared $(cat {all_module_names_file} {base_kernel_all_module_names_file_path}) \\
+ --declared {all_module_names} {base_kernel_all_module_names} \\
--actual $(cd {modules_staging_dir}/lib/modules/*/kernel && find . -type f -name '*.ko' | sed 's:^[.]/::'))
if [[ ${{remaining_ko_files}} ]]; then
echo "{message_type}: The following kernel modules are built but not copied. Add these lines to the module_outs attribute of {label}:" >&2
@@ -1137,20 +1126,17 @@ def _get_check_remaining_modules_step(
""".format(
message_type = message_type,
check_declared_output_list = ctx.executable._check_declared_output_list.path,
- all_module_names_file = all_module_names_file.path,
- base_kernel_all_module_names_file_path = _path_or_empty(base_kernel_all_module_names_file),
+ all_module_names = " ".join(all_module_names),
+ base_kernel_all_module_names = " ".join(base_kernel_all_module_names),
modules_staging_dir = modules_staging_dir,
label = ctx.label,
epilog = epilog,
)
- inputs = [all_module_names_file]
- if base_kernel_all_module_names_file:
- inputs.append(base_kernel_all_module_names_file)
tools = [ctx.executable._check_declared_output_list]
return struct(
cmd = cmd,
- inputs = inputs,
+ inputs = [],
tools = tools,
outputs = [],
)
@@ -1422,10 +1408,9 @@ def _build_main_action(
ctx,
kbuild_mixed_tree_ret,
all_output_names,
- all_module_names_file,
all_module_basenames_file):
"""Adds the main action for the `kernel_build`."""
- base_kernel_all_module_names_file = _get_base_kernel_all_module_names_file(ctx)
+ base_kernel_all_module_names = _get_base_kernel_all_module_names(ctx)
# Declare outputs.
## Declare outputs based on the *outs attributes
@@ -1471,7 +1456,7 @@ def _build_main_action(
has_any_modules = bool(all_output_names.modules),
modules_staging_dir = modules_staging_dir,
ruledir = ruledir,
- all_module_names_file = all_module_names_file,
+ all_module_names = all_output_names.modules,
)
grab_unstripped_modules_step = _get_grab_unstripped_modules_step(
ctx = ctx,
@@ -1487,8 +1472,8 @@ def _build_main_action(
copy_module_symvers_step = _get_copy_module_symvers_step(ctx)
check_remaining_modules_step = _get_check_remaining_modules_step(
ctx = ctx,
- all_module_names_file = all_module_names_file,
- base_kernel_all_module_names_file = base_kernel_all_module_names_file,
+ all_module_names = all_output_names.modules,
+ base_kernel_all_module_names = base_kernel_all_module_names,
modules_staging_dir = modules_staging_dir,
)
steps = (
@@ -1740,7 +1725,7 @@ def _get_serialized_env_info_setup_restore_outputs_command(outputs, fake_system_
def _create_infos(
ctx,
kbuild_mixed_tree_ret,
- all_module_names_file,
+ all_module_names,
main_action_ret,
modules_staging_archive,
kmi_strict_mode_out,
@@ -1752,7 +1737,7 @@ def _create_infos(
Args:
ctx: ctx
kbuild_mixed_tree_ret: from `_create_kbuild_mixed_tree`
- all_module_names_file: A file containing all module names
+ all_module_names: `module_outs` + `module_implicit_outs`
main_action_ret: from `_build_main_action`
modules_staging_archive: from `_repack_modules_staging_archive`
kmi_strict_mode_out: from `_kmi_symbol_list_strict_mode`
@@ -1904,7 +1889,7 @@ def _create_infos(
)
in_tree_modules_info = KernelBuildInTreeModulesInfo(
- module_outs_file = all_module_names_file,
+ all_module_names = all_module_names,
)
images_info = KernelImagesInfo(
@@ -1925,7 +1910,6 @@ def _create_infos(
# TODO(b/291918087): Drop after common_kernels no longer use kernel_filegroup.
# These files should already be in kernel_filegroup_declaration.
output_group_kwargs["modules_staging_archive"] = depset([modules_staging_archive])
- output_group_kwargs[MODULE_OUTS_FILE_OUTPUT_GROUP] = depset([all_module_names_file])
output_group_info = OutputGroupInfo(**output_group_kwargs)
kbuild_mixed_tree_files = all_output_files["outs"].values() + all_output_files["module_outs"].values()
@@ -1948,7 +1932,7 @@ def _create_infos(
filegroup_decl_info = KernelBuildFilegroupDeclInfo(
filegroup_srcs = depset(all_output_files["outs"].values() +
all_output_files["module_outs"].values()),
- module_outs_file = all_module_names_file,
+ all_module_names = all_module_names,
modules_staging_archive = modules_staging_archive,
toolchain_version = ctx.attr.config[KernelToolchainInfo].toolchain_version,
kernel_release = all_output_files["internal_outs"]["include/config/kernel.release"],
@@ -2008,13 +1992,6 @@ def _kernel_build_impl(ctx):
all_output_names = _split_out_attrs(ctx)
- # A file containing all module names
- all_module_names_file = _write_module_names_to_file(
- ctx,
- ctx.label.name + MODULE_OUTS_FILE_SUFFIX,
- all_output_names.modules,
- )
-
# A file containing the basenames of the modules
all_module_basenames_file = _write_module_names_to_file(
ctx,
@@ -2026,7 +2003,6 @@ def _kernel_build_impl(ctx):
ctx = ctx,
kbuild_mixed_tree_ret = kbuild_mixed_tree_ret,
all_output_names = all_output_names,
- all_module_names_file = all_module_names_file,
all_module_basenames_file = all_module_basenames_file,
)
@@ -2037,9 +2013,9 @@ def _kernel_build_impl(ctx):
)
kmi_strict_mode_out = _kmi_symbol_list_strict_mode(
- ctx,
- main_action_ret.all_output_files,
- all_module_names_file,
+ ctx = ctx,
+ all_output_files = main_action_ret.all_output_files,
+ all_module_names = all_output_names.modules,
)
kmi_symbol_list_violations_check_out = _kmi_symbol_list_violations_check(ctx, modules_staging_archive)
@@ -2054,7 +2030,7 @@ def _kernel_build_impl(ctx):
infos = _create_infos(
ctx = ctx,
kbuild_mixed_tree_ret = kbuild_mixed_tree_ret,
- all_module_names_file = all_module_names_file,
+ all_module_names = all_output_names.modules,
main_action_ret = main_action_ret,
modules_staging_archive = modules_staging_archive,
kmi_strict_mode_out = kmi_strict_mode_out,
@@ -2202,7 +2178,7 @@ ERROR: `toolchain_version` is "{this_toolchain}" for "{this_label}", but
base_toolchain = base_toolchain,
))
-def _kmi_symbol_list_strict_mode(ctx, all_output_files, all_module_names_file):
+def _kmi_symbol_list_strict_mode(ctx, all_output_files, all_module_names):
"""Run for `KMI_SYMBOL_LIST_STRICT_MODE`.
"""
if not ctx.attr._use_kmi_symbol_list_strict_mode[BuildSettingInfo].value:
@@ -2232,7 +2208,6 @@ def _kmi_symbol_list_strict_mode(ctx, all_output_files, all_module_names_file):
inputs = [
module_symvers,
- all_module_names_file,
]
inputs += ctx.files.raw_kmi_symbol_list # This is 0 or 1 file
transitive_inputs = [ctx.attr.config[KernelSerializedEnvInfo].inputs]
@@ -2249,11 +2224,11 @@ def _kmi_symbol_list_strict_mode(ctx, all_output_files, all_module_names_file):
{verify_ksymtab} \\
--symvers-file {module_symvers} \\
--raw-kmi-symbol-list {raw_kmi_symbol_list} \\
- --objects {vmlinux_base} $(cat {all_module_names_file} | sed 's/\\.ko$//')
+ --objects {vmlinux_base} {all_module_names}
touch {out}
""".format(
vmlinux_base = vmlinux.basename, # A fancy way of saying "vmlinux"
- all_module_names_file = all_module_names_file.path,
+ all_module_names = " ".join([m.removesuffix(".ko") for m in all_module_names]),
verify_ksymtab = ctx.executable._verify_ksymtab.path,
module_symvers = module_symvers.path,
raw_kmi_symbol_list = ctx.files.raw_kmi_symbol_list[0].path,
diff --git a/kleaf/impl/kernel_filegroup.bzl b/kleaf/impl/kernel_filegroup.bzl
index cb93eba..7c758d6 100644
--- a/kleaf/impl/kernel_filegroup.bzl
+++ b/kleaf/impl/kernel_filegroup.bzl
@@ -371,7 +371,7 @@ def _kernel_filegroup_impl(ctx):
src_protected_modules_list = protected_modules_list,
modules_staging_archive = utils.find_file(MODULES_STAGING_ARCHIVE, all_deps, what = ctx.label),
)
- in_tree_modules_info = KernelBuildInTreeModulesInfo(module_outs_file = ctx.file.module_outs_file)
+ in_tree_modules_info = KernelBuildInTreeModulesInfo(all_module_names = ctx.attr.all_module_names)
images_info = KernelImagesInfo(
base_kernel_label = None,
@@ -504,10 +504,9 @@ default, which in turn sets `collect_unstripped_modules` to `True` by default.
"strip_modules": attr.bool(
doc = """See [`kernel_build.strip_modules`](#kernel_build-strip_modules).""",
),
- "module_outs_file": attr.label(
- allow_single_file = True,
- doc = """A file containing `module_outs` of the original [`kernel_build`](#kernel_build) target.""",
- mandatory = True,
+ "all_module_names": attr.string_list(
+ doc = """`module_outs` and `module_implicit_outs` of the original
+ [`kernel_build`](#kernel_build) target.""",
),
"images": attr.label(
allow_files = True,
diff --git a/kleaf/impl/kernel_filegroup_declaration.bzl b/kleaf/impl/kernel_filegroup_declaration.bzl
index 085de58..a196791 100644
--- a/kleaf/impl/kernel_filegroup_declaration.bzl
+++ b/kleaf/impl/kernel_filegroup_declaration.bzl
@@ -103,7 +103,7 @@ kernel_filegroup(
kernel_uapi_headers = {uapi_headers_repr},
collect_unstripped_modules = {collect_unstripped_modules_repr},
strip_modules = {strip_modules_repr},
- module_outs_file = {module_outs_repr},
+ all_module_names = {all_module_names_repr},
kernel_release = {kernel_release_repr},
protected_modules_list = {protected_modules_repr},
ddk_module_defconfig_fragments = {ddk_module_defconfig_fragments_repr},
@@ -159,7 +159,12 @@ def _write_filegroup_decl_file(ctx, info, deps_files, kernel_uapi_headers, templ
sub.add_joined("{uapi_headers_repr}", depset([kernel_uapi_headers]), **(one | extra))
sub.add("{collect_unstripped_modules_repr}", repr(info.collect_unstripped_modules))
sub.add("{strip_modules_repr}", repr(info.strip_modules))
- sub.add_joined("{module_outs_repr}", depset([info.module_outs_file]), **(one | pkg))
+ sub.add_joined(
+ "{all_module_names_repr}",
+ depset(info.all_module_names),
+ map_each = repr,
+ **join
+ )
sub.add_joined("{kernel_release_repr}", depset([info.kernel_release]), **(one | pkg))
sub.add_joined(
"{protected_modules_repr}",
@@ -232,7 +237,6 @@ def _create_archive(ctx, info, deps_files, kernel_uapi_headers, filegroup_decl_f
))
direct_inputs = deps_files + [
filegroup_decl_file,
- info.module_outs_file,
info.kernel_release,
kernel_uapi_headers,
info.config_out_dir,
diff --git a/kleaf/tests/kernel_build_test/kernel_toolchain_test.bzl b/kleaf/tests/kernel_build_test/kernel_toolchain_test.bzl
index 2495b8d..f6454ca 100644
--- a/kleaf/tests/kernel_build_test/kernel_toolchain_test.bzl
+++ b/kleaf/tests/kernel_build_test/kernel_toolchain_test.bzl
@@ -63,11 +63,6 @@ def kernel_toolchain_test(name):
)
write_file(
- name = filegroup_name + "_module_outs_file",
- out = filegroup_name + "_module_outs_file/my_modules",
- )
-
- write_file(
name = filegroup_name + "_gki_info",
out = filegroup_name + "_gki_info/gki-info.txt",
content = [
@@ -100,7 +95,6 @@ def kernel_toolchain_test(name):
filegroup_name + "_unstripped_modules",
filegroup_name + "_staging_archive",
],
- module_outs_file = filegroup_name + "_module_outs_file",
gki_artifacts = filegroup_name + "_gki_info",
target_platform = filegroup_name + "_target_platform",
exec_platform = filegroup_name + "_exec_platform",
diff --git a/kleaf/tests/merged_kernel_uapi_headers_test/order_test.bzl b/kleaf/tests/merged_kernel_uapi_headers_test/order_test.bzl
index 66d4397..7d658af 100644
--- a/kleaf/tests/merged_kernel_uapi_headers_test/order_test.bzl
+++ b/kleaf/tests/merged_kernel_uapi_headers_test/order_test.bzl
@@ -129,7 +129,6 @@ def order_test(name):
name + "_base_modules_staging_archive",
],
kernel_uapi_headers = name + "_base_uapi_headers",
- module_outs_file = name + "_module_outs_file",
gki_artifacts = name + "_gki_info",
target_platform = Label("//build/kernel/kleaf/impl:android_arm64"),
exec_platform = Label("//build/kernel/kleaf/impl:linux_x86_64"),