blob: d6db6778acde8df0c889ccf33927aceb45c91289 [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"
Jingwen Chendf165c92022-06-08 16:00:39 +000021 "android/soong/etc"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040022 "android/soong/java"
Jingwen Chenb07c9012021-12-08 10:05:45 +000023 "android/soong/sh"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040024
Vinh Tran8f5310f2022-10-07 18:16:47 -040025 "fmt"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040026 "testing"
27)
28
Sam Delmerico3177a6e2022-06-21 19:28:33 +000029func runApexTestCase(t *testing.T, tc Bp2buildTestCase) {
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000031 RunBp2BuildTestCase(t, registerApexModuleTypes, tc)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040032}
33
34func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040035 // CC module types needed as they can be APEX dependencies
36 cc.RegisterCCBuildComponents(ctx)
37
Jingwen Chenb07c9012021-12-08 10:05:45 +000038 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
39 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040040 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
41 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
42 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
43 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Jingwen Chen81c67d32022-06-08 16:08:25 +000044 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Yu Liu4c212ce2022-10-14 12:20:20 -070045 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040046}
47
Sam Delmerico3177a6e2022-06-21 19:28:33 +000048func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) {
Wei Li1c66fc72022-05-09 23:59:14 -070049 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000050 RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
Wei Li1c66fc72022-05-09 23:59:14 -070051}
52
53func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
54 // CC module types needed as they can be APEX dependencies
55 cc.RegisterCCBuildComponents(ctx)
56
57 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
58 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
59 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
60 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
Liz Kammer1a1c9df2023-03-28 11:39:50 -040061 ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070062 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
63 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
64 ctx.RegisterModuleType("apex", apex.BundleFactory)
Cole Faust912bc882023-03-08 12:29:50 -080065 ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory)
Jingwen Chendf165c92022-06-08 16:00:39 +000066 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Cole Faust912bc882023-03-08 12:29:50 -080067 ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory)
68 ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070069}
70
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040071func TestApexBundleSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000072 runApexTestCase(t, Bp2buildTestCase{
73 Description: "apex - example with all props, file_context is a module in same Android.bp",
74 ModuleTypeUnderTest: "apex",
75 ModuleTypeUnderTestFactory: apex.BundleFactory,
76 Filesystem: map[string]string{},
77 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040078apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000079 name: "com.android.apogee.key",
80 public_key: "com.android.apogee.avbpubkey",
81 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040082 bazel_module: { bp2build_available: false },
83}
84
85android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000086 name: "com.android.apogee.certificate",
87 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040088 bazel_module: { bp2build_available: false },
89}
90
91cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000092 name: "native_shared_lib_1",
93 bazel_module: { bp2build_available: false },
94}
95
96cc_library {
97 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040098 bazel_module: { bp2build_available: false },
99}
100
Jingwen Chen81c67d32022-06-08 16:08:25 +0000101prebuilt_etc {
102 name: "prebuilt_1",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000103 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400104}
105
Jingwen Chen81c67d32022-06-08 16:08:25 +0000106prebuilt_etc {
107 name: "prebuilt_2",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000108 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400109}
110
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400111filegroup {
112 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000113 srcs: [
Wei Li1c66fc72022-05-09 23:59:14 -0700114 "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000115 ],
116 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400117}
118
Jingwen Chenb07c9012021-12-08 10:05:45 +0000119cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
120sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
121
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400122apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400123 name: "com.android.apogee",
124 manifest: "apogee_manifest.json",
125 androidManifest: "ApogeeAndroidManifest.xml",
Sam Delmericoe860d142023-06-06 15:47:30 -0400126 apex_available_name: "apogee_apex_name",
Wei Li1c66fc72022-05-09 23:59:14 -0700127 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400128 min_sdk_version: "29",
129 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000130 certificate: ":com.android.apogee.certificate",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400131 updatable: false,
132 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800133 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400134 native_shared_libs: [
135 "native_shared_lib_1",
136 "native_shared_lib_2",
137 ],
138 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000139 "cc_binary_1",
140 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400141 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400142 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000143 "prebuilt_1",
144 "prebuilt_2",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400145 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000146 package_name: "com.android.apogee.test.package",
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000147 logging_parent: "logging.parent",
Sam Delmericoe860d142023-06-06 15:47:30 -0400148 variant_version: "3",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400149}
150`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000151 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000152 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Sam Delmericoe860d142023-06-06 15:47:30 -0400153 "android_manifest": `"ApogeeAndroidManifest.xml"`,
154 "apex_available_name": `"apogee_apex_name"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000156 ":cc_binary_1",
157 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500158 ]`,
159 "certificate": `":com.android.apogee.certificate"`,
160 "file_contexts": `":com.android.apogee-file_contexts"`,
161 "installable": "False",
162 "key": `":com.android.apogee.key"`,
163 "manifest": `"apogee_manifest.json"`,
164 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400165 "native_shared_libs_32": `select({
166 "//build/bazel/platforms/arch:arm": [
167 ":native_shared_lib_1",
168 ":native_shared_lib_2",
169 ],
170 "//build/bazel/platforms/arch:x86": [
171 ":native_shared_lib_1",
172 ":native_shared_lib_2",
173 ],
174 "//conditions:default": [],
175 })`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800176 "native_shared_libs_64": `select({
177 "//build/bazel/platforms/arch:arm64": [
178 ":native_shared_lib_1",
179 ":native_shared_lib_2",
180 ],
181 "//build/bazel/platforms/arch:x86_64": [
182 ":native_shared_lib_1",
183 ":native_shared_lib_2",
184 ],
185 "//conditions:default": [],
186 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500187 "prebuilts": `[
Jingwen Chen81c67d32022-06-08 16:08:25 +0000188 ":prebuilt_1",
189 ":prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500190 ]`,
Sam Delmericoe860d142023-06-06 15:47:30 -0400191 "updatable": "False",
192 "compressible": "False",
193 "package_name": `"com.android.apogee.test.package"`,
194 "logging_parent": `"logging.parent"`,
195 "variant_version": `"3"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500196 }),
197 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400198}
199
Wei Li1c66fc72022-05-09 23:59:14 -0700200func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000201 runApexTestCase(t, Bp2buildTestCase{
202 Description: "apex - file contexts is a module in another Android.bp",
203 ModuleTypeUnderTest: "apex",
204 ModuleTypeUnderTestFactory: apex.BundleFactory,
205 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700206 "a/b/Android.bp": `
207filegroup {
208 name: "com.android.apogee-file_contexts",
209 srcs: [
210 "com.android.apogee-file_contexts",
211 ],
212 bazel_module: { bp2build_available: false },
213}
214`,
215 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000216 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700217apex {
218 name: "com.android.apogee",
219 file_contexts: ":com.android.apogee-file_contexts",
220}
221`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000222 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000223 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700224 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700225 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700226 }),
227 }})
228}
229
230func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000231 runApexTestCase(t, Bp2buildTestCase{
232 Description: "apex - file contexts is a file",
233 ModuleTypeUnderTest: "apex",
234 ModuleTypeUnderTestFactory: apex.BundleFactory,
235 Filesystem: map[string]string{},
236 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700237apex {
238 name: "com.android.apogee",
239 file_contexts: "file_contexts_file",
240}
241`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000242 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000243 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700244 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700245 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700246 }),
247 }})
248}
249
250func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000251 runApexTestCase(t, Bp2buildTestCase{
252 Description: "apex - file contexts is not specified",
253 ModuleTypeUnderTest: "apex",
254 ModuleTypeUnderTestFactory: apex.BundleFactory,
255 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700256 "system/sepolicy/apex/Android.bp": `
257filegroup {
258 name: "com.android.apogee-file_contexts",
259 srcs: [
260 "com.android.apogee-file_contexts",
261 ],
262 bazel_module: { bp2build_available: false },
263}
264`,
265 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000266 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700267apex {
268 name: "com.android.apogee",
269}
270`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000271 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000272 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700273 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700274 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700275 }),
276 }})
277}
278
Yu Liu4ae55d12022-01-05 17:17:23 -0800279func TestApexBundleCompileMultilibBoth(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000280 runApexTestCase(t, Bp2buildTestCase{
281 Description: "apex - example with compile_multilib=both",
282 ModuleTypeUnderTest: "apex",
283 ModuleTypeUnderTestFactory: apex.BundleFactory,
284 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700285 "system/sepolicy/apex/Android.bp": `
286filegroup {
287 name: "com.android.apogee-file_contexts",
288 srcs: [ "apogee-file_contexts", ],
289 bazel_module: { bp2build_available: false },
290}
291`,
292 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400293 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000294 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000295 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800296 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400297 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000298 ":native_shared_lib_for_both",
299 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800300 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000301 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
302 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800303 "//conditions:default": [],
304 })`,
305 "native_shared_libs_64": `select({
306 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400307 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000308 ":native_shared_lib_for_both",
309 ":native_shared_lib_for_lib64",
310 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800311 ],
312 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400313 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000314 ":native_shared_lib_for_both",
315 ":native_shared_lib_for_lib64",
316 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800317 ],
318 "//conditions:default": [],
319 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700320 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700321 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800322 }),
323 }})
324}
325
Vinh Tran8f5310f2022-10-07 18:16:47 -0400326func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
327 expectedBazelTargets := []string{
328 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
329 "native_shared_libs_32": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800330 "//build/bazel/platforms/arch:arm": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400331 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000332 ":native_shared_lib_for_both",
333 ":native_shared_lib_for_lib32",
334 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800335 ],
336 "//build/bazel/platforms/arch:x86": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400337 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000338 ":native_shared_lib_for_both",
339 ":native_shared_lib_for_lib32",
340 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800341 ],
342 "//conditions:default": [],
343 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400344 "native_shared_libs_64": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800345 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400346 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000347 ":native_shared_lib_for_both",
348 ":native_shared_lib_for_lib64",
349 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800350 ],
351 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400352 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000353 ":native_shared_lib_for_both",
354 ":native_shared_lib_for_lib64",
355 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800356 ],
357 "//conditions:default": [],
358 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400359 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
360 "manifest": `"apex_manifest.json"`,
361 }),
362 }
363
364 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
365 // should result to the same bp2build output
366 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
367 for _, compileMultiLibProp := range compileMultiLibPropValues {
368 descriptionSuffix := compileMultiLibProp
369 if descriptionSuffix == "" {
370 descriptionSuffix = "compile_multilib unset"
371 }
372 runApexTestCase(t, Bp2buildTestCase{
373 Description: "apex - example with " + compileMultiLibProp,
374 ModuleTypeUnderTest: "apex",
375 ModuleTypeUnderTestFactory: apex.BundleFactory,
376 Filesystem: map[string]string{
377 "system/sepolicy/apex/Android.bp": `
378 filegroup {
379 name: "com.android.apogee-file_contexts",
380 srcs: [ "apogee-file_contexts", ],
381 bazel_module: { bp2build_available: false },
382 }
383 `,
384 },
385 Blueprint: createMultilibBlueprint(compileMultiLibProp),
386 ExpectedBazelTargets: expectedBazelTargets,
387 })
388 }
Yu Liu4ae55d12022-01-05 17:17:23 -0800389}
390
391func TestApexBundleCompileMultilib32(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000392 runApexTestCase(t, Bp2buildTestCase{
393 Description: "apex - example with compile_multilib=32",
394 ModuleTypeUnderTest: "apex",
395 ModuleTypeUnderTestFactory: apex.BundleFactory,
396 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700397 "system/sepolicy/apex/Android.bp": `
398filegroup {
399 name: "com.android.apogee-file_contexts",
400 srcs: [ "apogee-file_contexts", ],
401 bazel_module: { bp2build_available: false },
402}
403`,
404 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400405 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000406 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000407 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800408 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400409 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000410 ":native_shared_lib_for_both",
411 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800412 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000413 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
414 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800415 "//conditions:default": [],
416 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700417 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700418 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800419 }),
420 }})
421}
422
423func TestApexBundleCompileMultilib64(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000424 runApexTestCase(t, Bp2buildTestCase{
425 Description: "apex - example with compile_multilib=64",
426 ModuleTypeUnderTest: "apex",
427 ModuleTypeUnderTestFactory: apex.BundleFactory,
428 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700429 "system/sepolicy/apex/Android.bp": `
430filegroup {
431 name: "com.android.apogee-file_contexts",
432 srcs: [ "apogee-file_contexts", ],
433 bazel_module: { bp2build_available: false },
434}
435`,
436 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400437 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000438 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000439 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800440 "native_shared_libs_64": `select({
441 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400442 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000443 ":native_shared_lib_for_both",
444 ":native_shared_lib_for_lib64",
445 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800446 ],
447 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400448 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000449 ":native_shared_lib_for_both",
450 ":native_shared_lib_for_lib64",
451 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800452 ],
453 "//conditions:default": [],
454 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700455 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700456 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800457 }),
458 }})
459}
460
Jingwen Chen34feb142022-10-06 13:02:30 +0000461func createMultilibBlueprint(compile_multilib string) string {
Vinh Tran8f5310f2022-10-07 18:16:47 -0400462 return fmt.Sprintf(`
Jingwen Chen34feb142022-10-06 13:02:30 +0000463cc_library {
464 name: "native_shared_lib_for_both",
465 bazel_module: { bp2build_available: false },
466}
467
468cc_library {
469 name: "native_shared_lib_for_first",
470 bazel_module: { bp2build_available: false },
471}
472
473cc_library {
474 name: "native_shared_lib_for_lib32",
475 bazel_module: { bp2build_available: false },
476}
477
478cc_library {
479 name: "native_shared_lib_for_lib64",
480 bazel_module: { bp2build_available: false },
481}
482
Vinh Tran8f5310f2022-10-07 18:16:47 -0400483cc_library {
484 name: "unnested_native_shared_lib",
485 bazel_module: { bp2build_available: false },
486}
487
Jingwen Chen34feb142022-10-06 13:02:30 +0000488apex {
489 name: "com.android.apogee",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400490 %s
491 native_shared_libs: ["unnested_native_shared_lib"],
Jingwen Chen34feb142022-10-06 13:02:30 +0000492 multilib: {
493 both: {
494 native_shared_libs: [
495 "native_shared_lib_for_both",
496 ],
497 },
498 first: {
499 native_shared_libs: [
500 "native_shared_lib_for_first",
501 ],
502 },
503 lib32: {
504 native_shared_libs: [
505 "native_shared_lib_for_lib32",
506 ],
507 },
508 lib64: {
509 native_shared_libs: [
510 "native_shared_lib_for_lib64",
511 ],
512 },
513 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400514}`, compile_multilib)
Jingwen Chen34feb142022-10-06 13:02:30 +0000515}
516
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400517func TestApexBundleDefaultPropertyValues(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000518 runApexTestCase(t, Bp2buildTestCase{
519 Description: "apex - default property values",
520 ModuleTypeUnderTest: "apex",
521 ModuleTypeUnderTestFactory: apex.BundleFactory,
522 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700523 "system/sepolicy/apex/Android.bp": `
524filegroup {
525 name: "com.android.apogee-file_contexts",
526 srcs: [ "apogee-file_contexts", ],
527 bazel_module: { bp2build_available: false },
528}
529`,
530 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000531 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400532apex {
533 name: "com.android.apogee",
534 manifest: "apogee_manifest.json",
535}
536`,
Alixe06d75b2022-08-31 18:28:19 +0000537 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700538 "manifest": `"apogee_manifest.json"`,
539 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500540 }),
541 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400542}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000543
544func TestApexBundleHasBazelModuleProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000545 runApexTestCase(t, Bp2buildTestCase{
546 Description: "apex - has bazel module props",
547 ModuleTypeUnderTest: "apex",
548 ModuleTypeUnderTestFactory: apex.BundleFactory,
549 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700550 "system/sepolicy/apex/Android.bp": `
551filegroup {
552 name: "apogee-file_contexts",
553 srcs: [ "apogee-file_contexts", ],
554 bazel_module: { bp2build_available: false },
555}
556`,
557 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000558 Blueprint: `
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000559apex {
560 name: "apogee",
561 manifest: "manifest.json",
562 bazel_module: { bp2build_available: true },
563}
564`,
Alixe06d75b2022-08-31 18:28:19 +0000565 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700566 "manifest": `"manifest.json"`,
567 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500568 }),
569 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000570}
Yu Liu4ae55d12022-01-05 17:17:23 -0800571
Wei Li1c66fc72022-05-09 23:59:14 -0700572func TestBp2BuildOverrideApex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000573 runOverrideApexTestCase(t, Bp2buildTestCase{
574 Description: "override_apex",
575 ModuleTypeUnderTest: "override_apex",
576 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
577 Filesystem: map[string]string{},
578 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700579apex_key {
580 name: "com.android.apogee.key",
581 public_key: "com.android.apogee.avbpubkey",
582 private_key: "com.android.apogee.pem",
583 bazel_module: { bp2build_available: false },
584}
585
586android_app_certificate {
587 name: "com.android.apogee.certificate",
588 certificate: "com.android.apogee",
589 bazel_module: { bp2build_available: false },
590}
591
592cc_library {
593 name: "native_shared_lib_1",
594 bazel_module: { bp2build_available: false },
595}
596
597cc_library {
598 name: "native_shared_lib_2",
599 bazel_module: { bp2build_available: false },
600}
601
Jingwen Chen81c67d32022-06-08 16:08:25 +0000602prebuilt_etc {
603 name: "prebuilt_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700604 bazel_module: { bp2build_available: false },
605}
606
Jingwen Chen81c67d32022-06-08 16:08:25 +0000607prebuilt_etc {
608 name: "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700609 bazel_module: { bp2build_available: false },
610}
611
612filegroup {
613 name: "com.android.apogee-file_contexts",
614 srcs: [
615 "com.android.apogee-file_contexts",
616 ],
617 bazel_module: { bp2build_available: false },
618}
619
620cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
621sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
622
623apex {
624 name: "com.android.apogee",
625 manifest: "apogee_manifest.json",
626 androidManifest: "ApogeeAndroidManifest.xml",
627 file_contexts: ":com.android.apogee-file_contexts",
628 min_sdk_version: "29",
629 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000630 certificate: ":com.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700631 updatable: false,
632 installable: false,
633 compressible: false,
634 native_shared_libs: [
635 "native_shared_lib_1",
636 "native_shared_lib_2",
637 ],
638 binaries: [
639 "cc_binary_1",
640 "sh_binary_2",
641 ],
642 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000643 "prebuilt_1",
644 "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700645 ],
646 bazel_module: { bp2build_available: false },
647}
648
649apex_key {
650 name: "com.google.android.apogee.key",
651 public_key: "com.google.android.apogee.avbpubkey",
652 private_key: "com.google.android.apogee.pem",
653 bazel_module: { bp2build_available: false },
654}
655
656android_app_certificate {
657 name: "com.google.android.apogee.certificate",
658 certificate: "com.google.android.apogee",
659 bazel_module: { bp2build_available: false },
660}
661
662override_apex {
663 name: "com.google.android.apogee",
664 base: ":com.android.apogee",
665 key: "com.google.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000666 certificate: ":com.google.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700667 prebuilts: [],
668 compressible: true,
669}
670`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000671 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000672 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700673 "android_manifest": `"ApogeeAndroidManifest.xml"`,
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000674 "base_apex_name": `"com.android.apogee"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700675 "binaries": `[
676 ":cc_binary_1",
677 ":sh_binary_2",
678 ]`,
679 "certificate": `":com.google.android.apogee.certificate"`,
680 "file_contexts": `":com.android.apogee-file_contexts"`,
681 "installable": "False",
682 "key": `":com.google.android.apogee.key"`,
683 "manifest": `"apogee_manifest.json"`,
684 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400685 "native_shared_libs_32": `select({
686 "//build/bazel/platforms/arch:arm": [
687 ":native_shared_lib_1",
688 ":native_shared_lib_2",
689 ],
690 "//build/bazel/platforms/arch:x86": [
691 ":native_shared_lib_1",
692 ":native_shared_lib_2",
693 ],
694 "//conditions:default": [],
695 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700696 "native_shared_libs_64": `select({
697 "//build/bazel/platforms/arch:arm64": [
698 ":native_shared_lib_1",
699 ":native_shared_lib_2",
700 ],
701 "//build/bazel/platforms/arch:x86_64": [
702 ":native_shared_lib_1",
703 ":native_shared_lib_2",
704 ],
705 "//conditions:default": [],
706 })`,
707 "prebuilts": `[]`,
708 "updatable": "False",
709 "compressible": "True",
710 }),
711 }})
712}
Wei Li40f98732022-05-20 22:08:11 -0700713
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400714func TestOverrideApexTest(t *testing.T) {
715 runOverrideApexTestCase(t, Bp2buildTestCase{
716 Description: "override_apex",
717 ModuleTypeUnderTest: "override_apex",
718 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
719 Filesystem: map[string]string{},
720 Blueprint: `
721apex_key {
722 name: "com.android.apogee.key",
723 public_key: "com.android.apogee.avbpubkey",
724 private_key: "com.android.apogee.pem",
725 bazel_module: { bp2build_available: false },
726}
727
728android_app_certificate {
729 name: "com.android.apogee.certificate",
730 certificate: "com.android.apogee",
731 bazel_module: { bp2build_available: false },
732}
733
734cc_library {
735 name: "native_shared_lib_1",
736 bazel_module: { bp2build_available: false },
737}
738
739prebuilt_etc {
740 name: "prebuilt_1",
741 bazel_module: { bp2build_available: false },
742}
743
744filegroup {
745 name: "com.android.apogee-file_contexts",
746 srcs: [
747 "com.android.apogee-file_contexts",
748 ],
749 bazel_module: { bp2build_available: false },
750}
751
752cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
753sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
754
755apex_test {
756 name: "com.android.apogee",
757 manifest: "apogee_manifest.json",
758 androidManifest: "ApogeeAndroidManifest.xml",
759 file_contexts: ":com.android.apogee-file_contexts",
760 min_sdk_version: "29",
761 key: "com.android.apogee.key",
762 certificate: ":com.android.apogee.certificate",
763 updatable: false,
764 installable: false,
765 compressible: false,
766 native_shared_libs: [
767 "native_shared_lib_1",
768 ],
769 binaries: [
770 "cc_binary_1",
771 "sh_binary_2",
772 ],
773 prebuilts: [
774 "prebuilt_1",
775 ],
776 bazel_module: { bp2build_available: false },
777}
778
779apex_key {
780 name: "com.google.android.apogee.key",
781 public_key: "com.google.android.apogee.avbpubkey",
782 private_key: "com.google.android.apogee.pem",
783 bazel_module: { bp2build_available: false },
784}
785
786android_app_certificate {
787 name: "com.google.android.apogee.certificate",
788 certificate: "com.google.android.apogee",
789 bazel_module: { bp2build_available: false },
790}
791
792override_apex {
793 name: "com.google.android.apogee",
794 base: ":com.android.apogee",
795 key: "com.google.android.apogee.key",
796 certificate: ":com.google.android.apogee.certificate",
797 prebuilts: [],
798 compressible: true,
799}
800`,
801 ExpectedBazelTargets: []string{
802 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
803 "android_manifest": `"ApogeeAndroidManifest.xml"`,
804 "base_apex_name": `"com.android.apogee"`,
805 "binaries": `[
806 ":cc_binary_1",
807 ":sh_binary_2",
808 ]`,
809 "certificate": `":com.google.android.apogee.certificate"`,
810 "file_contexts": `":com.android.apogee-file_contexts"`,
811 "installable": "False",
812 "key": `":com.google.android.apogee.key"`,
813 "manifest": `"apogee_manifest.json"`,
814 "min_sdk_version": `"29"`,
815 "native_shared_libs_32": `select({
816 "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"],
817 "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"],
818 "//conditions:default": [],
819 })`,
820 "native_shared_libs_64": `select({
821 "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"],
822 "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"],
823 "//conditions:default": [],
824 })`,
825 "testonly": "True",
826 "prebuilts": `[]`,
827 "updatable": "False",
828 "compressible": "True",
829 }),
830 }})
831}
832
Wei Li40f98732022-05-20 22:08:11 -0700833func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000834 runOverrideApexTestCase(t, Bp2buildTestCase{
835 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
836 ModuleTypeUnderTest: "override_apex",
837 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
838 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700839 "system/sepolicy/apex/Android.bp": `
840filegroup {
841 name: "com.android.apogee-file_contexts",
842 srcs: [ "apogee-file_contexts", ],
843 bazel_module: { bp2build_available: false },
844}`,
845 "a/b/Android.bp": `
846apex {
847 name: "com.android.apogee",
848 bazel_module: { bp2build_available: false },
849}
850`,
851 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000852 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700853override_apex {
854 name: "com.google.android.apogee",
855 base: ":com.android.apogee",
856}
857`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000858 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000859 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000860 "base_apex_name": `"com.android.apogee"`,
861 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
862 "manifest": `"//a/b:apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700863 }),
864 }})
865}
866
867func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000868 runOverrideApexTestCase(t, Bp2buildTestCase{
869 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
870 ModuleTypeUnderTest: "override_apex",
871 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
872 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700873 "system/sepolicy/apex/Android.bp": `
874filegroup {
875 name: "com.android.apogee-file_contexts",
876 srcs: [ "apogee-file_contexts", ],
877 bazel_module: { bp2build_available: false },
878}`,
879 "a/b/Android.bp": `
880apex {
881 name: "com.android.apogee",
882 manifest: "apogee_manifest.json",
883 bazel_module: { bp2build_available: false },
884}
885`,
886 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000887 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700888override_apex {
889 name: "com.google.android.apogee",
890 base: ":com.android.apogee",
891}
892`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000893 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000894 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000895 "base_apex_name": `"com.android.apogee"`,
896 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
897 "manifest": `"//a/b:apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700898 }),
899 }})
900}
901
902func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000903 runOverrideApexTestCase(t, Bp2buildTestCase{
904 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
905 ModuleTypeUnderTest: "override_apex",
906 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
907 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700908 "system/sepolicy/apex/Android.bp": `
909filegroup {
910 name: "com.android.apogee-file_contexts",
911 srcs: [ "apogee-file_contexts", ],
912 bazel_module: { bp2build_available: false },
913}`,
914 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000915 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700916apex {
917 name: "com.android.apogee",
918 bazel_module: { bp2build_available: false },
919}
920
921override_apex {
922 name: "com.google.android.apogee",
923 base: ":com.android.apogee",
924}
925`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000926 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000927 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000928 "base_apex_name": `"com.android.apogee"`,
929 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
930 "manifest": `"apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700931 }),
932 }})
933}
934
935func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000936 runOverrideApexTestCase(t, Bp2buildTestCase{
937 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
938 ModuleTypeUnderTest: "override_apex",
939 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
940 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700941 "system/sepolicy/apex/Android.bp": `
942filegroup {
943 name: "com.android.apogee-file_contexts",
944 srcs: [ "apogee-file_contexts", ],
945 bazel_module: { bp2build_available: false },
946}`,
947 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000948 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700949apex {
950 name: "com.android.apogee",
951 manifest: "apogee_manifest.json",
952 bazel_module: { bp2build_available: false },
953}
954
955override_apex {
956 name: "com.google.android.apogee",
957 base: ":com.android.apogee",
958}
959`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000960 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000961 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000962 "base_apex_name": `"com.android.apogee"`,
963 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
964 "manifest": `"apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700965 }),
966 }})
967}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000968
969func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000970 runOverrideApexTestCase(t, Bp2buildTestCase{
971 Description: "override_apex - override package name",
972 ModuleTypeUnderTest: "override_apex",
973 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
974 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000975 "system/sepolicy/apex/Android.bp": `
976filegroup {
977 name: "com.android.apogee-file_contexts",
978 srcs: [ "apogee-file_contexts", ],
979 bazel_module: { bp2build_available: false },
980}`,
981 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000982 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000983apex {
984 name: "com.android.apogee",
985 bazel_module: { bp2build_available: false },
986}
987
988override_apex {
989 name: "com.google.android.apogee",
990 base: ":com.android.apogee",
991 package_name: "com.google.android.apogee",
992}
993`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000994 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000995 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000996 "base_apex_name": `"com.android.apogee"`,
997 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
998 "manifest": `"apex_manifest.json"`,
999 "package_name": `"com.google.android.apogee"`,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +00001000 }),
1001 }})
1002}
Jingwen Chendf165c92022-06-08 16:00:39 +00001003
1004func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001005 runOverrideApexTestCase(t, Bp2buildTestCase{
1006 Description: "override_apex - no override",
1007 ModuleTypeUnderTest: "override_apex",
1008 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1009 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001010 "system/sepolicy/apex/Android.bp": `
1011filegroup {
1012 name: "com.android.apogee-file_contexts",
1013 srcs: [ "apogee-file_contexts", ],
1014 bazel_module: { bp2build_available: false },
1015}`,
1016 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001017 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001018prebuilt_etc {
1019 name: "prebuilt_file",
1020 bazel_module: { bp2build_available: false },
1021}
1022
1023apex {
1024 name: "com.android.apogee",
1025 bazel_module: { bp2build_available: false },
1026 prebuilts: ["prebuilt_file"]
1027}
1028
1029override_apex {
1030 name: "com.google.android.apogee",
1031 base: ":com.android.apogee",
1032}
1033`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001034 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001035 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001036 "base_apex_name": `"com.android.apogee"`,
1037 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1038 "manifest": `"apex_manifest.json"`,
1039 "prebuilts": `[":prebuilt_file"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001040 }),
1041 }})
1042}
1043
1044func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001045 runOverrideApexTestCase(t, Bp2buildTestCase{
1046 Description: "override_apex - ooverride",
1047 ModuleTypeUnderTest: "override_apex",
1048 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1049 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001050 "system/sepolicy/apex/Android.bp": `
1051filegroup {
1052 name: "com.android.apogee-file_contexts",
1053 srcs: [ "apogee-file_contexts", ],
1054 bazel_module: { bp2build_available: false },
1055}`,
1056 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001057 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001058prebuilt_etc {
1059 name: "prebuilt_file",
1060 bazel_module: { bp2build_available: false },
1061}
1062
1063prebuilt_etc {
1064 name: "prebuilt_file2",
1065 bazel_module: { bp2build_available: false },
1066}
1067
1068apex {
1069 name: "com.android.apogee",
1070 bazel_module: { bp2build_available: false },
1071 prebuilts: ["prebuilt_file"]
1072}
1073
1074override_apex {
1075 name: "com.google.android.apogee",
1076 base: ":com.android.apogee",
1077 prebuilts: ["prebuilt_file2"]
1078}
1079`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001080 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001081 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001082 "base_apex_name": `"com.android.apogee"`,
1083 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1084 "manifest": `"apex_manifest.json"`,
1085 "prebuilts": `[":prebuilt_file2"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001086 }),
1087 }})
1088}
1089
1090func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001091 runOverrideApexTestCase(t, Bp2buildTestCase{
1092 Description: "override_apex - override with empty list",
1093 ModuleTypeUnderTest: "override_apex",
1094 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1095 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001096 "system/sepolicy/apex/Android.bp": `
1097filegroup {
1098 name: "com.android.apogee-file_contexts",
1099 srcs: [ "apogee-file_contexts", ],
1100 bazel_module: { bp2build_available: false },
1101}`,
1102 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001103 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001104prebuilt_etc {
1105 name: "prebuilt_file",
1106 bazel_module: { bp2build_available: false },
1107}
1108
1109apex {
1110 name: "com.android.apogee",
1111 bazel_module: { bp2build_available: false },
1112 prebuilts: ["prebuilt_file"]
1113}
1114
1115override_apex {
1116 name: "com.google.android.apogee",
1117 base: ":com.android.apogee",
1118 prebuilts: [],
1119}
1120`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001121 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001122 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001123 "base_apex_name": `"com.android.apogee"`,
1124 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1125 "manifest": `"apex_manifest.json"`,
1126 "prebuilts": `[]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001127 }),
1128 }})
1129}
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001130
1131func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001132 runOverrideApexTestCase(t, Bp2buildTestCase{
1133 Description: "override_apex - logging_parent - no override",
1134 ModuleTypeUnderTest: "override_apex",
1135 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1136 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001137 "system/sepolicy/apex/Android.bp": `
1138filegroup {
1139 name: "com.android.apogee-file_contexts",
1140 srcs: [ "apogee-file_contexts", ],
1141 bazel_module: { bp2build_available: false },
1142}`,
1143 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001144 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001145apex {
1146 name: "com.android.apogee",
1147 bazel_module: { bp2build_available: false },
1148 logging_parent: "foo.bar.baz",
1149}
1150
1151override_apex {
1152 name: "com.google.android.apogee",
1153 base: ":com.android.apogee",
1154}
1155`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001156 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001157 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001158 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001159 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1160 "manifest": `"apex_manifest.json"`,
1161 "logging_parent": `"foo.bar.baz"`,
1162 }),
1163 }})
1164}
1165
1166func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001167 runOverrideApexTestCase(t, Bp2buildTestCase{
1168 Description: "override_apex - logging_parent - override",
1169 ModuleTypeUnderTest: "override_apex",
1170 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1171 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001172 "system/sepolicy/apex/Android.bp": `
1173filegroup {
1174 name: "com.android.apogee-file_contexts",
1175 srcs: [ "apogee-file_contexts", ],
1176 bazel_module: { bp2build_available: false },
1177}`,
1178 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001179 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001180apex {
1181 name: "com.android.apogee",
1182 bazel_module: { bp2build_available: false },
1183 logging_parent: "foo.bar.baz",
1184}
1185
1186override_apex {
1187 name: "com.google.android.apogee",
1188 base: ":com.android.apogee",
1189 logging_parent: "foo.bar.baz.override",
1190}
1191`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001192 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001193 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001194 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001195 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1196 "manifest": `"apex_manifest.json"`,
1197 "logging_parent": `"foo.bar.baz.override"`,
1198 }),
1199 }})
1200}
Jingwen Chenbea58092022-09-29 16:56:02 +00001201
1202func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1203 runOverrideApexTestCase(t, Bp2buildTestCase{
1204 Description: "override_apex - don't set default certificate",
1205 ModuleTypeUnderTest: "override_apex",
1206 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1207 Filesystem: map[string]string{},
1208 Blueprint: `
1209android_app_certificate {
1210 name: "com.android.apogee.certificate",
1211 certificate: "com.android.apogee",
1212 bazel_module: { bp2build_available: false },
1213}
1214
1215filegroup {
1216 name: "com.android.apogee-file_contexts",
1217 srcs: [
1218 "com.android.apogee-file_contexts",
1219 ],
1220 bazel_module: { bp2build_available: false },
1221}
1222
1223apex {
1224 name: "com.android.apogee",
1225 manifest: "apogee_manifest.json",
1226 file_contexts: ":com.android.apogee-file_contexts",
1227 certificate: ":com.android.apogee.certificate",
1228 bazel_module: { bp2build_available: false },
1229}
1230
1231override_apex {
1232 name: "com.google.android.apogee",
1233 base: ":com.android.apogee",
1234 // certificate is deliberately omitted, and not converted to bazel,
1235 // because the overridden apex shouldn't be using the base apex's cert.
1236}
1237`,
1238 ExpectedBazelTargets: []string{
1239 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001240 "base_apex_name": `"com.android.apogee"`,
1241 "file_contexts": `":com.android.apogee-file_contexts"`,
1242 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001243 }),
1244 }})
1245}
1246
1247func TestApexCertificateIsModule(t *testing.T) {
1248 runApexTestCase(t, Bp2buildTestCase{
1249 Description: "apex - certificate is module",
1250 ModuleTypeUnderTest: "apex",
1251 ModuleTypeUnderTestFactory: apex.BundleFactory,
1252 Filesystem: map[string]string{},
1253 Blueprint: `
1254android_app_certificate {
1255 name: "com.android.apogee.certificate",
1256 certificate: "com.android.apogee",
1257 bazel_module: { bp2build_available: false },
1258}
1259
1260apex {
1261 name: "com.android.apogee",
1262 manifest: "apogee_manifest.json",
1263 file_contexts: ":com.android.apogee-file_contexts",
1264 certificate: ":com.android.apogee.certificate",
1265}
Sam Delmerico130d75b2023-08-31 00:51:44 +00001266` + SimpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001267 ExpectedBazelTargets: []string{
1268 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1269 "certificate": `":com.android.apogee.certificate"`,
1270 "file_contexts": `":com.android.apogee-file_contexts"`,
1271 "manifest": `"apogee_manifest.json"`,
1272 }),
1273 }})
1274}
1275
Vinh Tran55225e32022-12-20 10:38:48 -05001276func TestApexWithStubLib(t *testing.T) {
1277 runApexTestCase(t, Bp2buildTestCase{
1278 Description: "apex - static variant of stub lib should not have apex_available tag",
1279 ModuleTypeUnderTest: "apex",
1280 ModuleTypeUnderTestFactory: apex.BundleFactory,
1281 Filesystem: map[string]string{},
1282 Blueprint: `
1283cc_library{
1284 name: "foo",
1285 stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
1286 apex_available: ["myapex"],
1287}
1288
1289cc_binary{
1290 name: "bar",
1291 static_libs: ["foo"],
1292 apex_available: ["myapex"],
1293}
1294
1295apex {
1296 name: "myapex",
1297 manifest: "myapex_manifest.json",
1298 file_contexts: ":myapex-file_contexts",
1299 binaries: ["bar"],
1300 native_shared_libs: ["foo"],
1301}
Sam Delmerico130d75b2023-08-31 00:51:44 +00001302` + SimpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"),
Vinh Tran55225e32022-12-20 10:38:48 -05001303 ExpectedBazelTargets: []string{
1304 MakeBazelTarget("cc_binary", "bar", AttrNameToString{
1305 "local_includes": `["."]`,
1306 "deps": `[":foo_bp2build_cc_library_static"]`,
1307 "tags": `["apex_available=myapex"]`,
1308 }),
1309 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
1310 "local_includes": `["."]`,
1311 }),
1312 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1313 "local_includes": `["."]`,
1314 "stubs_symbol_file": `"foo.map.txt"`,
1315 "tags": `["apex_available=myapex"]`,
1316 }),
1317 MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001318 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -04001319 "soname": `"foo.so"`,
1320 "source_library_label": `"//:foo"`,
1321 "symbol_file": `"foo.map.txt"`,
Vinh Tran55225e32022-12-20 10:38:48 -05001322 "versions": `[
1323 "28",
1324 "29",
1325 "current",
1326 ]`,
1327 }),
1328 MakeBazelTarget("apex", "myapex", AttrNameToString{
1329 "file_contexts": `":myapex-file_contexts"`,
1330 "manifest": `"myapex_manifest.json"`,
1331 "binaries": `[":bar"]`,
1332 "native_shared_libs_32": `select({
1333 "//build/bazel/platforms/arch:arm": [":foo"],
1334 "//build/bazel/platforms/arch:x86": [":foo"],
1335 "//conditions:default": [],
1336 })`,
1337 "native_shared_libs_64": `select({
1338 "//build/bazel/platforms/arch:arm64": [":foo"],
1339 "//build/bazel/platforms/arch:x86_64": [":foo"],
1340 "//conditions:default": [],
1341 })`,
1342 }),
1343 },
1344 })
1345}
1346
Jingwen Chenbea58092022-09-29 16:56:02 +00001347func TestApexCertificateIsSrc(t *testing.T) {
1348 runApexTestCase(t, Bp2buildTestCase{
1349 Description: "apex - certificate is src",
1350 ModuleTypeUnderTest: "apex",
1351 ModuleTypeUnderTestFactory: apex.BundleFactory,
1352 Filesystem: map[string]string{},
1353 Blueprint: `
1354apex {
1355 name: "com.android.apogee",
1356 manifest: "apogee_manifest.json",
1357 file_contexts: ":com.android.apogee-file_contexts",
1358 certificate: "com.android.apogee.certificate",
1359}
Sam Delmerico130d75b2023-08-31 00:51:44 +00001360` + SimpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001361 ExpectedBazelTargets: []string{
1362 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1363 "certificate_name": `"com.android.apogee.certificate"`,
1364 "file_contexts": `":com.android.apogee-file_contexts"`,
1365 "manifest": `"apogee_manifest.json"`,
1366 }),
1367 }})
1368}
1369
1370func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1371 runOverrideApexTestCase(t, Bp2buildTestCase{
1372 Description: "override_apex - certificate is module",
1373 ModuleTypeUnderTest: "override_apex",
1374 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1375 Filesystem: map[string]string{},
1376 Blueprint: `
1377android_app_certificate {
1378 name: "com.android.apogee.certificate",
1379 certificate: "com.android.apogee",
1380 bazel_module: { bp2build_available: false },
1381}
1382
1383filegroup {
1384 name: "com.android.apogee-file_contexts",
1385 srcs: [
1386 "com.android.apogee-file_contexts",
1387 ],
1388 bazel_module: { bp2build_available: false },
1389}
1390
1391apex {
1392 name: "com.android.apogee",
1393 manifest: "apogee_manifest.json",
1394 file_contexts: ":com.android.apogee-file_contexts",
1395 certificate: ":com.android.apogee.certificate",
1396 bazel_module: { bp2build_available: false },
1397}
1398
1399android_app_certificate {
1400 name: "com.google.android.apogee.certificate",
1401 certificate: "com.google.android.apogee",
1402 bazel_module: { bp2build_available: false },
1403}
1404
1405override_apex {
1406 name: "com.google.android.apogee",
1407 base: ":com.android.apogee",
1408 certificate: ":com.google.android.apogee.certificate",
1409}
1410`,
1411 ExpectedBazelTargets: []string{
1412 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001413 "base_apex_name": `"com.android.apogee"`,
1414 "file_contexts": `":com.android.apogee-file_contexts"`,
1415 "certificate": `":com.google.android.apogee.certificate"`,
1416 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001417 }),
1418 }})
1419}
1420
1421func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1422 runOverrideApexTestCase(t, Bp2buildTestCase{
1423 Description: "override_apex - certificate is src",
1424 ModuleTypeUnderTest: "override_apex",
1425 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1426 Filesystem: map[string]string{},
1427 Blueprint: `
1428android_app_certificate {
1429 name: "com.android.apogee.certificate",
1430 certificate: "com.android.apogee",
1431 bazel_module: { bp2build_available: false },
1432}
1433
1434filegroup {
1435 name: "com.android.apogee-file_contexts",
1436 srcs: [
1437 "com.android.apogee-file_contexts",
1438 ],
1439 bazel_module: { bp2build_available: false },
1440}
1441
1442apex {
1443 name: "com.android.apogee",
1444 manifest: "apogee_manifest.json",
1445 file_contexts: ":com.android.apogee-file_contexts",
1446 certificate: ":com.android.apogee.certificate",
1447 bazel_module: { bp2build_available: false },
1448}
1449
1450override_apex {
1451 name: "com.google.android.apogee",
1452 base: ":com.android.apogee",
1453 certificate: "com.google.android.apogee.certificate",
1454}
1455`,
1456 ExpectedBazelTargets: []string{
1457 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001458 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001459 "file_contexts": `":com.android.apogee-file_contexts"`,
1460 "certificate_name": `"com.google.android.apogee.certificate"`,
1461 "manifest": `"apogee_manifest.json"`,
1462 }),
1463 }})
1464}
Yu Liu4c212ce2022-10-14 12:20:20 -07001465
1466func TestApexTestBundleSimple(t *testing.T) {
1467 runApexTestCase(t, Bp2buildTestCase{
1468 Description: "apex_test - simple",
1469 ModuleTypeUnderTest: "apex_test",
1470 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1471 Filesystem: map[string]string{},
1472 Blueprint: `
1473cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
1474
1475apex_test {
1476 name: "test_com.android.apogee",
1477 file_contexts: "file_contexts_file",
1478 tests: ["cc_test_1"],
1479}
1480`,
1481 ExpectedBazelTargets: []string{
1482 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
Spandan Dasa43ae132023-05-08 18:33:16 +00001483 "file_contexts": `"file_contexts_file"`,
1484 "base_apex_name": `"com.android.apogee"`,
1485 "manifest": `"apex_manifest.json"`,
1486 "testonly": `True`,
1487 "tests": `[":cc_test_1"]`,
Yu Liu4c212ce2022-10-14 12:20:20 -07001488 }),
1489 }})
1490}
Cole Faust912bc882023-03-08 12:29:50 -08001491
1492func TestApexBundle_overridePlusProductVars(t *testing.T) {
1493 // Reproduction of b/271424349
1494 // Tests that overriding an apex that uses product variables correctly copies the product var
1495 // selects over to the override.
1496 runOverrideApexTestCase(t, Bp2buildTestCase{
1497 Description: "apex - overriding a module that uses product vars",
1498 ModuleTypeUnderTest: "override_apex",
1499 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1500 Blueprint: `
1501soong_config_string_variable {
1502 name: "library_linking_strategy",
1503 values: [
1504 "prefer_static",
1505 ],
1506}
1507
1508soong_config_module_type {
1509 name: "library_linking_strategy_apex_defaults",
1510 module_type: "apex_defaults",
1511 config_namespace: "ANDROID",
1512 variables: ["library_linking_strategy"],
1513 properties: [
1514 "manifest",
1515 "min_sdk_version",
1516 ],
1517}
1518
1519library_linking_strategy_apex_defaults {
1520 name: "higher_min_sdk_when_prefer_static",
1521 soong_config_variables: {
1522 library_linking_strategy: {
1523 // Use the R min_sdk_version
1524 prefer_static: {},
1525 // Override the R min_sdk_version to min_sdk_version that supports dcla
1526 conditions_default: {
1527 min_sdk_version: "31",
1528 },
1529 },
1530 },
1531}
1532
1533filegroup {
1534 name: "foo-file_contexts",
1535 srcs: [
1536 "com.android.apogee-file_contexts",
1537 ],
1538 bazel_module: { bp2build_available: false },
1539}
1540
1541apex {
1542 name: "foo",
1543 defaults: ["higher_min_sdk_when_prefer_static"],
1544 min_sdk_version: "30",
1545 package_name: "pkg_name",
1546 file_contexts: ":foo-file_contexts",
1547}
1548override_apex {
1549 name: "override_foo",
1550 base: ":foo",
1551 package_name: "override_pkg_name",
1552}
1553`,
1554 ExpectedBazelTargets: []string{
1555 MakeBazelTarget("apex", "foo", AttrNameToString{
1556 "file_contexts": `":foo-file_contexts"`,
1557 "manifest": `"apex_manifest.json"`,
1558 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001559 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001560 "//conditions:default": "31",
1561 })`,
1562 "package_name": `"pkg_name"`,
1563 }), MakeBazelTarget("apex", "override_foo", AttrNameToString{
1564 "base_apex_name": `"foo"`,
1565 "file_contexts": `":foo-file_contexts"`,
1566 "manifest": `"apex_manifest.json"`,
1567 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001568 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001569 "//conditions:default": "31",
1570 })`,
1571 "package_name": `"override_pkg_name"`,
1572 }),
1573 }})
1574}
Jingwen Chena8623da2023-03-28 13:05:02 +00001575
1576func TestApexBundleSimple_customCannedFsConfig(t *testing.T) {
1577 runApexTestCase(t, Bp2buildTestCase{
1578 Description: "apex - custom canned_fs_config",
1579 ModuleTypeUnderTest: "apex",
1580 ModuleTypeUnderTestFactory: apex.BundleFactory,
1581 Filesystem: map[string]string{},
1582 Blueprint: `
1583apex {
1584 name: "com.android.apogee",
1585 canned_fs_config: "custom.canned_fs_config",
1586 file_contexts: "file_contexts_file",
1587}
1588`,
1589 ExpectedBazelTargets: []string{
1590 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1591 "canned_fs_config": `"custom.canned_fs_config"`,
1592 "file_contexts": `"file_contexts_file"`,
1593 "manifest": `"apex_manifest.json"`,
1594 }),
1595 }})
1596}