diff options
author | Jaehyoung Choi <jkkkkk.choi@samsung.com> | 2024-03-07 16:17:25 +0900 |
---|---|---|
committer | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-03-19 23:20:28 +0000 |
commit | 7bceb21ce4aa772d733a6172bde0bf9b7bc197d4 (patch) | |
tree | 1fa1f3c92fc90f95132c7fe75b9609762145f682 | |
parent | 5003de911644e1e8d04d6b0c7f4b027825cb5a21 (diff) | |
download | build-7bceb21ce4aa772d733a6172bde0bf9b7bc197d4.tar.gz |
kleaf: Add outs attr in kernel_modules_install
kernel_modules_install performs depmod on all modules.
However, since the result of the depmod can't be obtained,
an outs attribute was created and changed
so that it can be obtained using copy_to_dist_dir.
To avoid being abused, output is limited to modules.* files
_OUT_ALLOWLIST = [
"modules.dep",
"modules.alias",
"modules.builtin",
"modules.symbols",
"modules.softdep",
]
It can be used as below:
kernel_modules_install(
name = "foo_modules_install",
kernel_modules = [":foo_module_list"],
outs = [
"modules.dep",
"modules.alias"
],
)
copy_to_dist_dir(
name = "foo_dist",
data = [
":foo_modules_install",
],
)
Test: bazel build //common:kernel_aarch64
Bug: 327533166
Change-Id: Ia9efb26183553f72b5c27b8b0e1564702934b86a
Signed-off-by: Jaehyoung Choi <jkkkkk.choi@samsung.com>
Signed-off-by: Yifan Hong <elsk@google.com>
-rw-r--r-- | kleaf/impl/kernel_modules_install.bzl | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/kleaf/impl/kernel_modules_install.bzl b/kleaf/impl/kernel_modules_install.bzl index 7c8595a..f9718d7 100644 --- a/kleaf/impl/kernel_modules_install.bzl +++ b/kleaf/impl/kernel_modules_install.bzl @@ -15,6 +15,7 @@ A rule that runs depmod in the module installation directory. """ +load("@bazel_skylib//lib:paths.bzl", "paths") load("//build/kernel/kleaf:directory_with_structure.bzl", dws = "directory_with_structure") load( ":common_providers.bzl", @@ -34,6 +35,15 @@ load( visibility("//build/kernel/kleaf/...") +# To avoid being abused, output is limited to modules.* files +_OUT_ALLOWLIST = [ + "modules.dep", + "modules.alias", + "modules.builtin", + "modules.symbols", + "modules.softdep", +] + def _kernel_modules_install_impl(ctx): kernel_build_infos = None if ctx.attr.kernel_build: @@ -53,6 +63,9 @@ def _kernel_modules_install_impl(ctx): # A list of declared files for outputs of kernel_module rules external_modules = [] + # A list of additional files other than kernel modules. + outs = [] + # TODO(b/256688440): Avoid depset[directory_with_structure] to_list modules_staging_dws_depset = depset(transitive = [ kernel_module[KernelModuleInfo].modules_staging_dws_depset @@ -76,6 +89,19 @@ def _kernel_modules_install_impl(ctx): declared_file = ctx.actions.declare_file("{}/{}".format(ctx.label.name, module_file.basename)) external_modules.append(declared_file) + for out in ctx.attr.outs: + if out not in _OUT_ALLOWLIST: + fail( + """{}: {} is not allowed in outs. + Please refer to the list of allowed files {}""".format( + ctx.label, + out, + _OUT_ALLOWLIST, + ), + ) + out_file = ctx.actions.declare_file("{}/{}".format(ctx.label.name, out)) + outs.append(out_file) + transitive_inputs = [ kernel_build_infos.ext_module_info.modinst_env.inputs, ] @@ -158,6 +184,17 @@ def _kernel_modules_install_impl(ctx): search_and_cp_output = ctx.executable._search_and_cp_output.path, ) + command += """ + # Move additional files to declared output location + for out in {outs}; do + cp -pL {modules_staging_dir}/lib/modules/*/${{out}} {outdir} + done + """.format( + modules_staging_dir = modules_staging_dws.directory.path, + outdir = paths.join(utils.package_bin_dir(ctx), ctx.attr.name), + outs = " ".join(ctx.attr.outs), + ) + command += dws.record(modules_staging_dws) debug.print_scripts(ctx, command) @@ -165,7 +202,7 @@ def _kernel_modules_install_impl(ctx): mnemonic = "KernelModulesInstall", inputs = depset(inputs, transitive = transitive_inputs), tools = depset(tools, transitive = transitive_tools), - outputs = external_modules + dws.files(modules_staging_dws), + outputs = external_modules + dws.files(modules_staging_dws) + outs, command = command, progress_message = "Running depmod {}".format(ctx.label), ) @@ -181,7 +218,7 @@ def _kernel_modules_install_impl(ctx): ) return [ - DefaultInfo(files = depset(external_modules)), + DefaultInfo(files = depset(external_modules + outs)), KernelModuleInfo( kernel_build_infos = kernel_build_infos, modules_staging_dws_depset = depset([modules_staging_dws]), @@ -260,5 +297,27 @@ In `foo_dist`, specifying `foo_modules_install` in `data` won't include executable = True, doc = "Label referring to the script to process outputs", ), + "outs": attr.string_list( + doc = """ A list of additional outputs from `make modules_install`. + +Since external modules are returned by default, +it can be used to obtain modules.* related files (results of depmod). +Only files with allowed names can be added to outs. (`_OUT_ALLOWLIST`) +``` +_OUT_ALLOWLIST = {} +``` +Example: +``` +kernel_modules_install( + name = "foo_modules_install", + kernel_modules = [":foo_module_list"], + outs = [ + "modules.dep", + "modules.alias", + ], +) +``` +""".format(repr(_OUT_ALLOWLIST)), + ), }, ) |