blob: 456f18aa8d88f3fad3040f85dadb93f7ccea65c1 [file] [log] [blame]
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04001// Copyright 2021 Google Inc. 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
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/apex"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040020 "android/soong/cc"
21 "android/soong/java"
22
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040023 "testing"
24)
25
26func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
27 t.Helper()
28 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
29}
30
31func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040032 // CC module types needed as they can be APEX dependencies
33 cc.RegisterCCBuildComponents(ctx)
34
35 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
36 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
37 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
38 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040039}
40
41func TestApexBundleSimple(t *testing.T) {
42 runApexTestCase(t, bp2buildTestCase{
43 description: "apex - simple example",
44 moduleTypeUnderTest: "apex",
45 moduleTypeUnderTestFactory: apex.BundleFactory,
46 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
47 filesystem: map[string]string{},
48 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040049apex_key {
50 name: "com.android.apogee.key",
51 public_key: "com.android.apogee.avbpubkey",
52 private_key: "com.android.apogee.pem",
53 bazel_module: { bp2build_available: false },
54}
55
56android_app_certificate {
57 name: "com.android.apogee.certificate",
58 certificate: "com.android.apogee",
59 bazel_module: { bp2build_available: false },
60}
61
62cc_library {
63 name: "native_shared_lib_1",
64 bazel_module: { bp2build_available: false },
65}
66
67cc_library {
68 name: "native_shared_lib_2",
69 bazel_module: { bp2build_available: false },
70}
71
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040072// TODO(b/194878861): Add bp2build support for prebuilt_etc
73cc_library {
74 name: "pretend_prebuilt_1",
75 bazel_module: { bp2build_available: false },
76}
77
78// TODO(b/194878861): Add bp2build support for prebuilt_etc
79cc_library {
80 name: "pretend_prebuilt_2",
81 bazel_module: { bp2build_available: false },
82}
83
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040084filegroup {
85 name: "com.android.apogee-file_contexts",
86 srcs: [
87 "com.android.apogee-file_contexts",
88 ],
89 bazel_module: { bp2build_available: false },
90}
91
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040092apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040093 name: "com.android.apogee",
94 manifest: "apogee_manifest.json",
95 androidManifest: "ApogeeAndroidManifest.xml",
96 file_contexts: "com.android.apogee-file_contexts",
97 min_sdk_version: "29",
98 key: "com.android.apogee.key",
99 certificate: "com.android.apogee.certificate",
100 updatable: false,
101 installable: false,
102 native_shared_libs: [
103 "native_shared_lib_1",
104 "native_shared_lib_2",
105 ],
106 binaries: [
107 "binary_1",
108 "binary_2",
109 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400110 prebuilts: [
111 "pretend_prebuilt_1",
112 "pretend_prebuilt_2",
113 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400114}
115`,
116 expectedBazelTargets: []string{`apex(
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400117 name = "com.android.apogee",
118 android_manifest = "ApogeeAndroidManifest.xml",
119 binaries = [
120 "binary_1",
121 "binary_2",
122 ],
123 certificate = ":com.android.apogee.certificate",
124 file_contexts = ":com.android.apogee-file_contexts",
125 installable = False,
126 key = ":com.android.apogee.key",
127 manifest = "apogee_manifest.json",
128 min_sdk_version = "29",
129 native_shared_libs = [
130 ":native_shared_lib_1",
131 ":native_shared_lib_2",
132 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400133 prebuilts = [
134 ":pretend_prebuilt_1",
135 ":pretend_prebuilt_2",
136 ],
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400137 updatable = False,
138)`}})
139}
140
141func TestApexBundleDefaultPropertyValues(t *testing.T) {
142 runApexTestCase(t, bp2buildTestCase{
143 description: "apex - default property values",
144 moduleTypeUnderTest: "apex",
145 moduleTypeUnderTestFactory: apex.BundleFactory,
146 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
147 filesystem: map[string]string{},
148 blueprint: `
149apex {
150 name: "com.android.apogee",
151 manifest: "apogee_manifest.json",
152}
153`,
154 expectedBazelTargets: []string{`apex(
155 name = "com.android.apogee",
156 manifest = "apogee_manifest.json",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400157)`}})
158}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000159
160func TestApexBundleHasBazelModuleProps(t *testing.T) {
161 runApexTestCase(t, bp2buildTestCase{
162 description: "apex - has bazel module props",
163 moduleTypeUnderTest: "apex",
164 moduleTypeUnderTestFactory: apex.BundleFactory,
165 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
166 filesystem: map[string]string{},
167 blueprint: `
168apex {
169 name: "apogee",
170 manifest: "manifest.json",
171 bazel_module: { bp2build_available: true },
172}
173`,
174 expectedBazelTargets: []string{`apex(
175 name = "apogee",
176 manifest = "manifest.json",
177)`}})
178}