xref: /aosp_15_r20/build/bazel/rules/apex/apex_test_helpers.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1*7594170eSAndroid Build Coastguard Worker# Copyright (C) 2022 The Android Open Source Project
2*7594170eSAndroid Build Coastguard Worker#
3*7594170eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*7594170eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*7594170eSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*7594170eSAndroid Build Coastguard Worker#
7*7594170eSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
8*7594170eSAndroid Build Coastguard Worker#
9*7594170eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*7594170eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*7594170eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*7594170eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*7594170eSAndroid Build Coastguard Worker# limitations under the License.
14*7594170eSAndroid Build Coastguard Worker
15*7594170eSAndroid Build Coastguard Workerload("//build/bazel/rules/android:android_app_certificate.bzl", "android_app_certificate")
16*7594170eSAndroid Build Coastguard Workerload(":apex.bzl", "apex")
17*7594170eSAndroid Build Coastguard Workerload(":apex_key.bzl", "apex_key")
18*7594170eSAndroid Build Coastguard Worker
19*7594170eSAndroid Build Coastguard Worker# Set up test-local dependencies required for every apex.
20*7594170eSAndroid Build Coastguard Workerdef _setup_apex_required_deps(
21*7594170eSAndroid Build Coastguard Worker        file_contexts,
22*7594170eSAndroid Build Coastguard Worker        key,
23*7594170eSAndroid Build Coastguard Worker        manifest,
24*7594170eSAndroid Build Coastguard Worker        certificate):
25*7594170eSAndroid Build Coastguard Worker    # Use the same shared common deps for all test apexes.
26*7594170eSAndroid Build Coastguard Worker    if file_contexts and not native.existing_rule(file_contexts):
27*7594170eSAndroid Build Coastguard Worker        native.genrule(
28*7594170eSAndroid Build Coastguard Worker            name = file_contexts,
29*7594170eSAndroid Build Coastguard Worker            outs = [file_contexts + ".out"],
30*7594170eSAndroid Build Coastguard Worker            cmd = "echo unused && exit 1",
31*7594170eSAndroid Build Coastguard Worker            tags = ["manual"],
32*7594170eSAndroid Build Coastguard Worker        )
33*7594170eSAndroid Build Coastguard Worker
34*7594170eSAndroid Build Coastguard Worker    if manifest and not native.existing_rule(manifest):
35*7594170eSAndroid Build Coastguard Worker        native.genrule(
36*7594170eSAndroid Build Coastguard Worker            name = manifest,
37*7594170eSAndroid Build Coastguard Worker            outs = [manifest + ".json"],
38*7594170eSAndroid Build Coastguard Worker            cmd = "echo unused && exit 1",
39*7594170eSAndroid Build Coastguard Worker            tags = ["manual"],
40*7594170eSAndroid Build Coastguard Worker        )
41*7594170eSAndroid Build Coastguard Worker
42*7594170eSAndroid Build Coastguard Worker    # Required for ApexKeyInfo provider
43*7594170eSAndroid Build Coastguard Worker    if key and not native.existing_rule(key):
44*7594170eSAndroid Build Coastguard Worker        apex_key(
45*7594170eSAndroid Build Coastguard Worker            name = key,
46*7594170eSAndroid Build Coastguard Worker            private_key = key + ".pem",
47*7594170eSAndroid Build Coastguard Worker            public_key = key + ".avbpubkey",
48*7594170eSAndroid Build Coastguard Worker            tags = ["manual"],
49*7594170eSAndroid Build Coastguard Worker        )
50*7594170eSAndroid Build Coastguard Worker
51*7594170eSAndroid Build Coastguard Worker    # Required for AndroidAppCertificate provider
52*7594170eSAndroid Build Coastguard Worker    if certificate and not native.existing_rule(certificate):
53*7594170eSAndroid Build Coastguard Worker        android_app_certificate(
54*7594170eSAndroid Build Coastguard Worker            name = certificate,
55*7594170eSAndroid Build Coastguard Worker            certificate = certificate + ".cert",
56*7594170eSAndroid Build Coastguard Worker            tags = ["manual"],
57*7594170eSAndroid Build Coastguard Worker        )
58*7594170eSAndroid Build Coastguard Worker
59*7594170eSAndroid Build Coastguard Workerdef test_apex(
60*7594170eSAndroid Build Coastguard Worker        name,
61*7594170eSAndroid Build Coastguard Worker        file_contexts = "test_file_contexts",
62*7594170eSAndroid Build Coastguard Worker        key = "test_key",
63*7594170eSAndroid Build Coastguard Worker        manifest = "test_manifest",
64*7594170eSAndroid Build Coastguard Worker        certificate = "test_certificate",
65*7594170eSAndroid Build Coastguard Worker        **kwargs):
66*7594170eSAndroid Build Coastguard Worker    _setup_apex_required_deps(
67*7594170eSAndroid Build Coastguard Worker        file_contexts = file_contexts,
68*7594170eSAndroid Build Coastguard Worker        key = key,
69*7594170eSAndroid Build Coastguard Worker        manifest = manifest,
70*7594170eSAndroid Build Coastguard Worker        certificate = certificate,
71*7594170eSAndroid Build Coastguard Worker    )
72*7594170eSAndroid Build Coastguard Worker
73*7594170eSAndroid Build Coastguard Worker    apex(
74*7594170eSAndroid Build Coastguard Worker        name = name,
75*7594170eSAndroid Build Coastguard Worker        file_contexts = file_contexts,
76*7594170eSAndroid Build Coastguard Worker        key = key,
77*7594170eSAndroid Build Coastguard Worker        manifest = manifest,
78*7594170eSAndroid Build Coastguard Worker        certificate = certificate,
79*7594170eSAndroid Build Coastguard Worker        tags = ["manual"],
80*7594170eSAndroid Build Coastguard Worker        **kwargs
81*7594170eSAndroid Build Coastguard Worker    )
82