From 8be2c8b5af71980d5c27ea1cf061699ced43a7d9 Mon Sep 17 00:00:00 2001 From: Ulises Mendez Martinez Date: Fri, 26 May 2023 18:02:05 +0000 Subject: kleaf: Support to keep a copy of Module.symvers Bug: 265923948 Change-Id: I9633c5a8380927de4bfe97b7862c72b2970a675f Signed-off-by: Ulises Mendez Martinez (cherry picked from commit 89625d0dd0befc78600aa141a26314484911da81) --- kleaf/impl/kernel_build.bzl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/kleaf/impl/kernel_build.bzl b/kleaf/impl/kernel_build.bzl index 3da608db..4a0e4732 100644 --- a/kleaf/impl/kernel_build.bzl +++ b/kleaf/impl/kernel_build.bzl @@ -64,6 +64,7 @@ def kernel_build( name, build_config, outs, + keep_module_symvers = None, srcs = None, module_outs = None, implicit_outs = None, @@ -103,6 +104,10 @@ def kernel_build( name: The final kernel target name, e.g. `"kernel_aarch64"`. build_config: Label of the build.config file, e.g. `"build.config.gki.aarch64"`. kconfig_ext: Label of an external Kconfig.ext file sourced by the GKI kernel. + keep_module_symvers: If set to True, a copy of the default output `Module.symvers` is kept. + * To avoid collisions in mixed build distribution packages, the file is renamed + as `$(name)_Module.symvers`. + * Default is False. srcs: The kernel sources (a `glob()`). If unspecified or `None`, it is the following: ``` glob( @@ -418,6 +423,7 @@ def kernel_build( _kernel_build( name = name, config = config_target_name, + keep_module_symvers = keep_module_symvers, srcs = srcs, outs = kernel_utils.transform_kernel_build_outs(name, "outs", outs), module_outs = kernel_utils.transform_kernel_build_outs(name, "module_outs", module_outs), @@ -701,6 +707,20 @@ def _kernel_build_impl(ctx): symtypes_dir = symtypes_dir.path, ) + copy_module_symvers_cmd = "" + module_symvers_copy = None + if ctx.attr.keep_module_symvers: + module_symvers_copy = ctx.actions.declare_file("{}/{}_Module.symvers".format( + ctx.label.name, + ctx.label.name, + )) + command_outputs.append(module_symvers_copy) + copy_module_symvers_cmd = """ + cp -f ${{OUT_DIR}}/Module.symvers {module_symvers_copy} + """.format( + module_symvers_copy = module_symvers_copy.path, + ) + command += """ # Actual kernel build {interceptor_command_prefix} make -C ${{KERNEL_DIR}} ${{TOOL_ARGS}} O=${{OUT_DIR}} ${{MAKE_GOALS}} @@ -729,6 +749,8 @@ def _kernel_build_impl(ctx): {grab_intree_modules_cmd} # Grab unstripped in-tree modules {grab_unstripped_intree_modules_cmd} + # Make a copy of Module.symvers + {copy_module_symvers_cmd} # Check if there are remaining *.ko files remaining_ko_files=$({check_declared_output_list} \\ --declared $(cat {all_module_names_file} {base_kernel_all_module_names_file_path}) \\ @@ -762,6 +784,7 @@ def _kernel_build_impl(ctx): out_dir_kernel_headers_tar = out_dir_kernel_headers_tar.path, interceptor_command_prefix = interceptor_command_prefix, label = ctx.label, + copy_module_symvers_cmd = copy_module_symvers_cmd, ) debug.print_scripts(ctx, command) @@ -855,6 +878,8 @@ def _kernel_build_impl(ctx): default_info_files.append(all_module_names_file) if kmi_strict_mode_out: default_info_files.append(kmi_strict_mode_out) + if ctx.attr.keep_module_symvers: + default_info_files.append(module_symvers_copy) default_info = DefaultInfo( files = depset(default_info_files), # For kernel_build_test @@ -884,6 +909,9 @@ _kernel_build = rule( aspects = [kernel_toolchain_aspect], doc = "the kernel_config target", ), + "keep_module_symvers": attr.bool( + doc = "If true, a copy of `Module.symvers` is kept, with the name `{name}_Module.symvers`", + ), "srcs": attr.label_list(mandatory = True, doc = "kernel sources", allow_files = True), "outs": attr.string_list(), "module_outs": attr.string_list(doc = "output *.ko files"), -- cgit v1.2.3