diff options
author | Jingwen Chen <jingwen@google.com> | 2022-07-12 15:09:06 +0000 |
---|---|---|
committer | Jingwen Chen <jingwen@google.com> | 2022-07-18 12:26:36 +0000 |
commit | 745cf75c24c399934d0fd3ef7e4578d6cbddfb99 (patch) | |
tree | a2529c250c76a2635ae9db192c633aec6e3a4a8f /rules/apex/apex_aab.bzl | |
parent | 5480ab72d3d63b34ed00a2be2f7fcab4a0887780 (diff) | |
download | bazel-745cf75c24c399934d0fd3ef7e4578d6cbddfb99.tar.gz |
Add apex_files output group to apex_aab to forward all base APEX files
for each architecture.
The Mainline CI build target produces both .aab files and .apex files
for each module, in the following layout:
x.aab
y.aab
mainline_modules_arm/x.apex
mainline_modules_arm/y.apex
mainline_modules_arm64/x.apex
mainline_modules_arm64/y.apex
..
Currently, we're only producing the .aab files by building the apex_aab
targets. To dist the .apex files, we either build the apex targets
separately within a --config={android_arm, android_arm64, ..} loop, or
we could just forward the 1:4 split transition'd multi-arch apex files
from the apex_aab target, which are already built.
This is a output group because it can be controlled from a filegroup or
the command line --output_groups flag, which makes it easy to extend the
mainline build script.
For example:
```
apex_aab(
name = "module",
mainline_module = "//path/to:apex",
)
filegroup(
name = "apex_files",
srcs = [":module"],
output_group = "apex_files",
)
```
Or: b build //path/to/module --output_groups=apex_files
produces the following:
bazel-bin/path/to/mainline_modules_arm/module.apex
bazel-bin/path/to/mainline_modules_arm64/module.apex
bazel-bin/path/to/mainline_modules_x86/module.apex
bazel-bin/path/to/mainline_modules_x86_64/module.apex
Test: new analysis test
Bug: 238723069
Change-Id: I3f4efa4eff1adeba8c315d9f97729a3a529b32c0
Diffstat (limited to 'rules/apex/apex_aab.bzl')
-rw-r--r-- | rules/apex/apex_aab.bzl | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/rules/apex/apex_aab.bzl b/rules/apex/apex_aab.bzl index a814b705..6fee25b1 100644 --- a/rules/apex/apex_aab.bzl +++ b/rules/apex/apex_aab.bzl @@ -198,12 +198,29 @@ def _apex_bundle(ctx, module_name, merged_base_file, bundle_config_file): def _apex_aab_impl(ctx): """Implementation of apex_aab rule, which drives the process of creating aab file from apex files created for each arch.""" + prefixed_signed_apex_files = [] apex_base_files = [] bundle_config_file = None module_name = ctx.attr.mainline_module[0].label.name for arch in ctx.split_attr.mainline_module: - apex_file = ctx.split_attr.mainline_module[arch].files.to_list()[0] - proto_convert_file = _apex_proto_convert(ctx, arch, module_name, apex_file) + signed_apex = ctx.split_attr.mainline_module[arch][ApexInfo].signed_output + + # Forward the individual files for all variants in an additional output group, + # so dependents can easily access the multi-arch base APEX files by building + # this target with --output_groups=apex_files. + # + # Copy them into an arch-specific directory, since they have the same basename. + prefixed_signed_apex_file = ctx.actions.declare_file( + "mainline_modules_" + arch + "/" + signed_apex.basename, + ) + ctx.actions.run_shell( + inputs = [signed_apex], + outputs = [prefixed_signed_apex_file], + command = " ".join(["cp", signed_apex.path, prefixed_signed_apex_file.path]), + ) + prefixed_signed_apex_files.append(prefixed_signed_apex_file) + + proto_convert_file = _apex_proto_convert(ctx, arch, module_name, signed_apex) base_file = _apex_base_file(ctx, arch, module_name, proto_convert_file) apex_base_files.append(base_file) @@ -214,11 +231,15 @@ def _apex_aab_impl(ctx): merged_base_file = _merge_base_files(ctx, module_name, apex_base_files) bundle_file = _apex_bundle(ctx, module_name, merged_base_file, bundle_config_file) - return [DefaultInfo(files = depset([bundle_file]))] + return [ + DefaultInfo(files = depset([bundle_file])), + OutputGroupInfo(apex_files = depset(prefixed_signed_apex_files)), + ] -# apex_aab rule creates Android Apk Bundle (.aab) file of the APEX specified in mainline_module. -# There is no equivalent Soong module, and it is currently done in shell script by -# invoking Soong multiple times. +# apex_aab rule creates multi-arch outputs of a Mainline module, such as the +# Android Apk Bundle (.aab) file of the APEX specified in mainline_module. +# There is no equivalent Soong module, and it is currently done in shell script +# by invoking Soong multiple times. apex_aab = rule( implementation = _apex_aab_impl, attrs = { |