xref: /aosp_15_r20/external/bazelbuild-rules_android/mobile_install/adapters/apk_import.bzl (revision 9e965d6fece27a77de5377433c2f7e6999b8cc0b)
1# Copyright 2018 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Rule adapter for android_binary."""
15
16load(":adapters/base.bzl", "make_adapter")
17load(":providers.bzl", "MIAppInfo")
18load(":utils.bzl", "utils")
19
20def _aspect_attrs():
21    """Attrs of the rule requiring traversal by the aspect."""
22    return ["unsigned_apk"]
23
24def adapt(target, ctx):
25    # adapt is made visibile for testing
26    """Adapts the android rule
27
28    Args:
29        target: The target.
30        ctx: The context.
31    Returns:
32         A list of providers
33    """
34    apk = ctx.rule.file.unsigned_apk
35
36    package_name_output_file = utils.isolated_declare_file(ctx, ctx.label.name + "/manifest_package_name.txt")
37
38    utils.extract_package_name(ctx, apk, package_name_output_file)
39
40    return [
41        MIAppInfo(
42            apk = apk,
43            manifest_package_name = package_name_output_file,
44        ),
45    ]
46
47apk_import = make_adapter(_aspect_attrs, adapt)
48