diff options
author | Ulises Mendez Martinez <umendez@google.com> | 2024-01-31 11:19:43 +0000 |
---|---|---|
committer | Ulises Mendez Martinez <umendez@google.com> | 2024-02-08 11:11:13 +0000 |
commit | 72026a25a1055af8a4ae4860142a28e31264923c (patch) | |
tree | 30884d9f70c376dcb1f404c27bb1777ab71f2842 | |
parent | 3bfcca35cd5542946c7956103a7f8ead7c70f328 (diff) | |
download | build-72026a25a1055af8a4ae4860142a28e31264923c.tar.gz |
Kleaf: Add support to create a modules.order files for images
* This is done by keeping a local copy of the make generated one, for
each ddk_module or kernel_module. For kernel_module_group or
kernel_modules_install this becomes a depset which is traversed in
postorder (dependencies first) when needed.
* With this change kernel_images (initiramfs, (system|vendor)_dlkm) can
control whether to use this new approach or keep the old behavior with
the variable `create_modules_order` (set to True by default).
Bug: 306122000
Change-Id: Ic636c2da8d77e6c25e7eb9c8f6de68904828a9ad
Signed-off-by: Ulises Mendez Martinez <umendez@google.com>
(cherry picked from commit 1d3379dd0e0bb660bff2903ce7e93bd93e696700)
-rw-r--r-- | build_utils.sh | 6 | ||||
-rw-r--r-- | kleaf/impl/common_providers.bzl | 4 | ||||
-rw-r--r-- | kleaf/impl/image/image_utils.bzl | 20 | ||||
-rw-r--r-- | kleaf/impl/image/kernel_images.bzl | 9 | ||||
-rw-r--r-- | kleaf/impl/kernel_module.bzl | 17 | ||||
-rw-r--r-- | kleaf/impl/kernel_module_group.bzl | 4 | ||||
-rw-r--r-- | kleaf/impl/kernel_modules_install.bzl | 4 |
7 files changed, 61 insertions, 3 deletions
diff --git a/build_utils.sh b/build_utils.sh index cdf7c85..6f02361 100644 --- a/build_utils.sh +++ b/build_utils.sh @@ -193,7 +193,11 @@ function create_modules_staging() { cp ${src_dir}/modules.builtin ${dest_dir}/modules.builtin cp ${src_dir}/modules.builtin.modinfo ${dest_dir}/modules.builtin.modinfo - if [[ -n "${EXT_MODULES}" ]] || [[ -n "${EXT_MODULES_MAKEFILE}" ]]; then + if [[ -n "${KLEAF_MODULES_ORDER}" ]] && [[ -d "${src_dir}/extra" ]]; then + mkdir -p ${dest_dir}/extra/ + cp -r ${src_dir}/extra/* ${dest_dir}/extra/ + cat ${KLEAF_MODULES_ORDER} >> ${dest_dir}/modules.order + elif [[ -n "${EXT_MODULES}" ]] || [[ -n "${EXT_MODULES_MAKEFILE}" ]]; then mkdir -p ${dest_dir}/extra/ cp -r ${src_dir}/extra/* ${dest_dir}/extra/ diff --git a/kleaf/impl/common_providers.bzl b/kleaf/impl/common_providers.bzl index 8dd23e5..994eca5 100644 --- a/kleaf/impl/common_providers.bzl +++ b/kleaf/impl/common_providers.bzl @@ -289,6 +289,10 @@ KernelModuleInfo = provider( names of all external modules in an unspecified order. This corresponds to `EXT_MODULES` in `build.sh`.""", "label": "Label to the `kernel_module` target.", + "modules_order": """A [depset](https://bazel.build/extending/depsets) of `modules.order` + files from ddk_module's, kernel_module, etc. + It uses [`postorder`](https://bazel.build/rules/lib/builtins/depset) ordering (dependencies + first).""", }, ) diff --git a/kleaf/impl/image/image_utils.bzl b/kleaf/impl/image/image_utils.bzl index c577e9d..3357fa5 100644 --- a/kleaf/impl/image/image_utils.bzl +++ b/kleaf/impl/image/image_utils.bzl @@ -164,6 +164,18 @@ def _build_modules_image_impl_common( options = "-al --chmod=F+w --include=source --include=build --exclude='*'", ) + modules_order_cmd = "" + if ctx.attr.create_modules_order: + modules_order_depset = ctx.attr.kernel_modules_install[KernelModuleInfo].modules_order + modules_order_depset_list = modules_order_depset.to_list() + inputs += modules_order_depset_list + modules_order_cmd = """ + cat {modules_order} > kleaf_modules.order + KLEAF_MODULES_ORDER=kleaf_modules.order + """.format( + modules_order = " ".join([modules_order.path for modules_order in modules_order_depset_list]), + ) + if set_ext_modules and ctx.attr._set_ext_modules[BuildSettingInfo].value: ext_modules = ctx.attr.kernel_modules_install[KernelModuleInfo].packages.to_list() command += """EXT_MODULES={quoted_ext_modules}""".format( @@ -181,9 +193,11 @@ file a bug.""") mkdir -p ${{DIST_DIR}} cp {system_map} ${{DIST_DIR}}/System.map + {modules_order_cmd} {build_command} """.format( system_map = system_map.path, + modules_order_cmd = modules_order_cmd, build_command = build_command, ) @@ -214,6 +228,12 @@ def _build_modules_image_attrs_common(additional = None): "_set_ext_modules": attr.label( default = "//build/kernel/kleaf:set_ext_modules", ), + "create_modules_order": attr.bool( + default = True, + doc = """Whether to create and keep a modules.order file generated + by a postorder traversal of the `kernel_modules_install` sources. + It defaults to `True`.""", + ), } if additional != None: ret.update(additional) diff --git a/kleaf/impl/image/kernel_images.bzl b/kleaf/impl/image/kernel_images.bzl index 1d0b4ce..f2b7360 100644 --- a/kleaf/impl/image/kernel_images.bzl +++ b/kleaf/impl/image/kernel_images.bzl @@ -66,6 +66,7 @@ def kernel_images( avb_boot_algorithm = None, avb_boot_partition_name = None, dedup_dlkm_modules = None, + create_modules_order = None, **kwargs): """Build multiple kernel images. @@ -302,7 +303,10 @@ def kernel_images( If set, **additional changes in the userspace is required** so that `system_dlkm` modules are loaded before `vendor_dlkm` modules. - + create_modules_order: Whether to create and keep a modules.order file + generated by a postorder traversal of the `kernel_modules_install` sources. + It applies to building `initramfs` and `vendor_dlkm` where previously + `$EXT_MODULES` was used. It defaults to `True`. **kwargs: Additional attributes to the internal rule, e.g. [`visibility`](https://docs.bazel.build/versions/main/visibility.html). See complete list @@ -386,6 +390,7 @@ def kernel_images( modules_options = modules_options, ramdisk_compression = ramdisk_compression, ramdisk_compression_args = ramdisk_compression_args, + create_modules_order = create_modules_order, **kwargs ) all_rules.append(":{}_initramfs".format(name)) @@ -406,6 +411,7 @@ def kernel_images( system_dlkm_modules_list = system_dlkm_modules_list, system_dlkm_modules_blocklist = system_dlkm_modules_blocklist, system_dlkm_props = system_dlkm_props, + create_modules_order = False, **kwargs ) all_rules.append(":{}_system_dlkm_image".format(name)) @@ -428,6 +434,7 @@ def kernel_images( dedup_dlkm_modules = dedup_dlkm_modules, system_dlkm_image = "{}_system_dlkm_image".format(name) if build_system_dlkm else None, base_kernel_images = base_kernel_images, + create_modules_order = create_modules_order, **kwargs ) all_rules.append(":{}_vendor_dlkm_image".format(name)) diff --git a/kleaf/impl/kernel_module.bzl b/kleaf/impl/kernel_module.bzl index cbd84df..d24210b 100644 --- a/kleaf/impl/kernel_module.bzl +++ b/kleaf/impl/kernel_module.bzl @@ -417,6 +417,18 @@ def _kernel_module_impl(ctx): command += modpost_warn.cmd command_outputs += modpost_warn.outputs + # Keep a record of the modules.order generated by `make`. + modules_order = ctx.actions.declare_file("{}/modules.order".format(ctx.attr.name)) + command_outputs.append(modules_order) + grab_modules_order_cmd = """ + # Backup modules.order files before optionally dropping them. + cp -L -p {modules_staging_dir}/lib/modules/*/extra/{ext_mod}/modules.order.* {modules_order} + """.format( + ext_mod = ext_mod, + modules_staging_dir = modules_staging_dws.directory.path, + modules_order = modules_order.path, + ) + make_filter = "" if not ctx.attr.generate_btf: # Filter out warnings if there is no need for BTF generation @@ -459,7 +471,8 @@ def _kernel_module_impl(ctx): {grab_cmd_cmd} # Move Module.symvers rsync -aL ${{OUT_DIR}}/${{ext_mod_rel}}/Module.symvers {module_symvers} - + # Grab and then drop modules.order + {grab_modules_order_cmd} {drop_modules_order_cmd} """.format( label = ctx.label, @@ -476,6 +489,7 @@ def _kernel_module_impl(ctx): all_module_names_file = all_module_names_file.path, grab_unstripped_cmd = grab_unstripped_cmd, check_no_remaining = check_no_remaining.path, + grab_modules_order_cmd = grab_modules_order_cmd, drop_modules_order_cmd = drop_modules_order_cmd, grab_cmd_cmd = grab_cmd_step.cmd, ) @@ -608,6 +622,7 @@ def _kernel_module_impl(ctx): files = depset(output_files), packages = depset([ext_mod]), label = ctx.label, + modules_order = depset([modules_order]), ), KernelUnstrippedModulesInfo( directories = depset([unstripped_dir], order = "postorder"), diff --git a/kleaf/impl/kernel_module_group.bzl b/kleaf/impl/kernel_module_group.bzl index 28409f7..831ad36 100644 --- a/kleaf/impl/kernel_module_group.bzl +++ b/kleaf/impl/kernel_module_group.bzl @@ -65,6 +65,10 @@ def _kernel_module_group_impl(ctx): ]), packages = depset(transitive = [target[KernelModuleInfo].packages for target in targets]), label = ctx.label, + modules_order = depset( + transitive = [target[KernelModuleInfo].modules_order for target in targets], + order = "postorder", + ), ) unstripped_modules_info = KernelUnstrippedModulesInfo( diff --git a/kleaf/impl/kernel_modules_install.bzl b/kleaf/impl/kernel_modules_install.bzl index cb38106..c8ab534 100644 --- a/kleaf/impl/kernel_modules_install.bzl +++ b/kleaf/impl/kernel_modules_install.bzl @@ -194,6 +194,10 @@ def _kernel_modules_install_impl(ctx): for target in ctx.attr.kernel_modules ]), label = ctx.label, + modules_order = depset(transitive = [ + target[KernelModuleInfo].modules_order + for target in ctx.attr.kernel_modules + ], order = "postorder"), ), cmds_info, ] |