xref: /aosp_15_r20/build/bazel/rules/apex/apex_test_helpers.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# Copyright (C) 2022 The Android Open Source Project
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
15load("//build/bazel/rules/android:android_app_certificate.bzl", "android_app_certificate")
16load(":apex.bzl", "apex")
17load(":apex_key.bzl", "apex_key")
18
19# Set up test-local dependencies required for every apex.
20def _setup_apex_required_deps(
21        file_contexts,
22        key,
23        manifest,
24        certificate):
25    # Use the same shared common deps for all test apexes.
26    if file_contexts and not native.existing_rule(file_contexts):
27        native.genrule(
28            name = file_contexts,
29            outs = [file_contexts + ".out"],
30            cmd = "echo unused && exit 1",
31            tags = ["manual"],
32        )
33
34    if manifest and not native.existing_rule(manifest):
35        native.genrule(
36            name = manifest,
37            outs = [manifest + ".json"],
38            cmd = "echo unused && exit 1",
39            tags = ["manual"],
40        )
41
42    # Required for ApexKeyInfo provider
43    if key and not native.existing_rule(key):
44        apex_key(
45            name = key,
46            private_key = key + ".pem",
47            public_key = key + ".avbpubkey",
48            tags = ["manual"],
49        )
50
51    # Required for AndroidAppCertificate provider
52    if certificate and not native.existing_rule(certificate):
53        android_app_certificate(
54            name = certificate,
55            certificate = certificate + ".cert",
56            tags = ["manual"],
57        )
58
59def test_apex(
60        name,
61        file_contexts = "test_file_contexts",
62        key = "test_key",
63        manifest = "test_manifest",
64        certificate = "test_certificate",
65        **kwargs):
66    _setup_apex_required_deps(
67        file_contexts = file_contexts,
68        key = key,
69        manifest = manifest,
70        certificate = certificate,
71    )
72
73    apex(
74        name = name,
75        file_contexts = file_contexts,
76        key = key,
77        manifest = manifest,
78        certificate = certificate,
79        tags = ["manual"],
80        **kwargs
81    )
82