blob: 1cc3f22ed381d856d29bb4e4ce16ae602f910e5b [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",
Wei Li1c66fc72022-05-09 23:59:14 -0700126 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400127 min_sdk_version: "29",
128 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000129 certificate: ":com.android.apogee.certificate",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400130 updatable: false,
131 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800132 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400133 native_shared_libs: [
134 "native_shared_lib_1",
135 "native_shared_lib_2",
136 ],
137 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000138 "cc_binary_1",
139 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400140 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400141 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000142 "prebuilt_1",
143 "prebuilt_2",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400144 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000145 package_name: "com.android.apogee.test.package",
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000146 logging_parent: "logging.parent",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400147}
148`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000149 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000150 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500151 "android_manifest": `"ApogeeAndroidManifest.xml"`,
152 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000153 ":cc_binary_1",
154 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 ]`,
156 "certificate": `":com.android.apogee.certificate"`,
157 "file_contexts": `":com.android.apogee-file_contexts"`,
158 "installable": "False",
159 "key": `":com.android.apogee.key"`,
160 "manifest": `"apogee_manifest.json"`,
161 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400162 "native_shared_libs_32": `select({
163 "//build/bazel/platforms/arch:arm": [
164 ":native_shared_lib_1",
165 ":native_shared_lib_2",
166 ],
167 "//build/bazel/platforms/arch:x86": [
168 ":native_shared_lib_1",
169 ":native_shared_lib_2",
170 ],
171 "//conditions:default": [],
172 })`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800173 "native_shared_libs_64": `select({
174 "//build/bazel/platforms/arch:arm64": [
175 ":native_shared_lib_1",
176 ":native_shared_lib_2",
177 ],
178 "//build/bazel/platforms/arch:x86_64": [
179 ":native_shared_lib_1",
180 ":native_shared_lib_2",
181 ],
182 "//conditions:default": [],
183 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500184 "prebuilts": `[
Jingwen Chen81c67d32022-06-08 16:08:25 +0000185 ":prebuilt_1",
186 ":prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500187 ]`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000188 "updatable": "False",
189 "compressible": "False",
190 "package_name": `"com.android.apogee.test.package"`,
191 "logging_parent": `"logging.parent"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500192 }),
193 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400194}
195
Wei Li1c66fc72022-05-09 23:59:14 -0700196func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000197 runApexTestCase(t, Bp2buildTestCase{
198 Description: "apex - file contexts is a module in another Android.bp",
199 ModuleTypeUnderTest: "apex",
200 ModuleTypeUnderTestFactory: apex.BundleFactory,
201 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700202 "a/b/Android.bp": `
203filegroup {
204 name: "com.android.apogee-file_contexts",
205 srcs: [
206 "com.android.apogee-file_contexts",
207 ],
208 bazel_module: { bp2build_available: false },
209}
210`,
211 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000212 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700213apex {
214 name: "com.android.apogee",
215 file_contexts: ":com.android.apogee-file_contexts",
216}
217`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000218 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000219 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700220 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700221 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700222 }),
223 }})
224}
225
226func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000227 runApexTestCase(t, Bp2buildTestCase{
228 Description: "apex - file contexts is a file",
229 ModuleTypeUnderTest: "apex",
230 ModuleTypeUnderTestFactory: apex.BundleFactory,
231 Filesystem: map[string]string{},
232 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700233apex {
234 name: "com.android.apogee",
235 file_contexts: "file_contexts_file",
236}
237`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000238 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000239 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700240 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700241 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700242 }),
243 }})
244}
245
246func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000247 runApexTestCase(t, Bp2buildTestCase{
248 Description: "apex - file contexts is not specified",
249 ModuleTypeUnderTest: "apex",
250 ModuleTypeUnderTestFactory: apex.BundleFactory,
251 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700252 "system/sepolicy/apex/Android.bp": `
253filegroup {
254 name: "com.android.apogee-file_contexts",
255 srcs: [
256 "com.android.apogee-file_contexts",
257 ],
258 bazel_module: { bp2build_available: false },
259}
260`,
261 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000262 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700263apex {
264 name: "com.android.apogee",
265}
266`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000267 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000268 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700269 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700270 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700271 }),
272 }})
273}
274
Yu Liu4ae55d12022-01-05 17:17:23 -0800275func TestApexBundleCompileMultilibBoth(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000276 runApexTestCase(t, Bp2buildTestCase{
277 Description: "apex - example with compile_multilib=both",
278 ModuleTypeUnderTest: "apex",
279 ModuleTypeUnderTestFactory: apex.BundleFactory,
280 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700281 "system/sepolicy/apex/Android.bp": `
282filegroup {
283 name: "com.android.apogee-file_contexts",
284 srcs: [ "apogee-file_contexts", ],
285 bazel_module: { bp2build_available: false },
286}
287`,
288 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400289 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000290 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000291 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800292 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400293 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000294 ":native_shared_lib_for_both",
295 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800296 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000297 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
298 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800299 "//conditions:default": [],
300 })`,
301 "native_shared_libs_64": `select({
302 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400303 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000304 ":native_shared_lib_for_both",
305 ":native_shared_lib_for_lib64",
306 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800307 ],
308 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400309 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000310 ":native_shared_lib_for_both",
311 ":native_shared_lib_for_lib64",
312 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800313 ],
314 "//conditions:default": [],
315 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700316 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700317 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800318 }),
319 }})
320}
321
Vinh Tran8f5310f2022-10-07 18:16:47 -0400322func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
323 expectedBazelTargets := []string{
324 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
325 "native_shared_libs_32": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800326 "//build/bazel/platforms/arch:arm": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400327 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000328 ":native_shared_lib_for_both",
329 ":native_shared_lib_for_lib32",
330 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800331 ],
332 "//build/bazel/platforms/arch:x86": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400333 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000334 ":native_shared_lib_for_both",
335 ":native_shared_lib_for_lib32",
336 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800337 ],
338 "//conditions:default": [],
339 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400340 "native_shared_libs_64": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800341 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400342 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000343 ":native_shared_lib_for_both",
344 ":native_shared_lib_for_lib64",
345 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800346 ],
347 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400348 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000349 ":native_shared_lib_for_both",
350 ":native_shared_lib_for_lib64",
351 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800352 ],
353 "//conditions:default": [],
354 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400355 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
356 "manifest": `"apex_manifest.json"`,
357 }),
358 }
359
360 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
361 // should result to the same bp2build output
362 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
363 for _, compileMultiLibProp := range compileMultiLibPropValues {
364 descriptionSuffix := compileMultiLibProp
365 if descriptionSuffix == "" {
366 descriptionSuffix = "compile_multilib unset"
367 }
368 runApexTestCase(t, Bp2buildTestCase{
369 Description: "apex - example with " + compileMultiLibProp,
370 ModuleTypeUnderTest: "apex",
371 ModuleTypeUnderTestFactory: apex.BundleFactory,
372 Filesystem: map[string]string{
373 "system/sepolicy/apex/Android.bp": `
374 filegroup {
375 name: "com.android.apogee-file_contexts",
376 srcs: [ "apogee-file_contexts", ],
377 bazel_module: { bp2build_available: false },
378 }
379 `,
380 },
381 Blueprint: createMultilibBlueprint(compileMultiLibProp),
382 ExpectedBazelTargets: expectedBazelTargets,
383 })
384 }
Yu Liu4ae55d12022-01-05 17:17:23 -0800385}
386
387func TestApexBundleCompileMultilib32(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000388 runApexTestCase(t, Bp2buildTestCase{
389 Description: "apex - example with compile_multilib=32",
390 ModuleTypeUnderTest: "apex",
391 ModuleTypeUnderTestFactory: apex.BundleFactory,
392 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700393 "system/sepolicy/apex/Android.bp": `
394filegroup {
395 name: "com.android.apogee-file_contexts",
396 srcs: [ "apogee-file_contexts", ],
397 bazel_module: { bp2build_available: false },
398}
399`,
400 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400401 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000402 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000403 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800404 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400405 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000406 ":native_shared_lib_for_both",
407 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800408 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000409 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
410 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800411 "//conditions:default": [],
412 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700413 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700414 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800415 }),
416 }})
417}
418
419func TestApexBundleCompileMultilib64(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000420 runApexTestCase(t, Bp2buildTestCase{
421 Description: "apex - example with compile_multilib=64",
422 ModuleTypeUnderTest: "apex",
423 ModuleTypeUnderTestFactory: apex.BundleFactory,
424 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700425 "system/sepolicy/apex/Android.bp": `
426filegroup {
427 name: "com.android.apogee-file_contexts",
428 srcs: [ "apogee-file_contexts", ],
429 bazel_module: { bp2build_available: false },
430}
431`,
432 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400433 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000434 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000435 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800436 "native_shared_libs_64": `select({
437 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400438 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000439 ":native_shared_lib_for_both",
440 ":native_shared_lib_for_lib64",
441 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800442 ],
443 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400444 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000445 ":native_shared_lib_for_both",
446 ":native_shared_lib_for_lib64",
447 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800448 ],
449 "//conditions:default": [],
450 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700451 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700452 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800453 }),
454 }})
455}
456
Jingwen Chen34feb142022-10-06 13:02:30 +0000457func createMultilibBlueprint(compile_multilib string) string {
Vinh Tran8f5310f2022-10-07 18:16:47 -0400458 return fmt.Sprintf(`
Jingwen Chen34feb142022-10-06 13:02:30 +0000459cc_library {
460 name: "native_shared_lib_for_both",
461 bazel_module: { bp2build_available: false },
462}
463
464cc_library {
465 name: "native_shared_lib_for_first",
466 bazel_module: { bp2build_available: false },
467}
468
469cc_library {
470 name: "native_shared_lib_for_lib32",
471 bazel_module: { bp2build_available: false },
472}
473
474cc_library {
475 name: "native_shared_lib_for_lib64",
476 bazel_module: { bp2build_available: false },
477}
478
Vinh Tran8f5310f2022-10-07 18:16:47 -0400479cc_library {
480 name: "unnested_native_shared_lib",
481 bazel_module: { bp2build_available: false },
482}
483
Jingwen Chen34feb142022-10-06 13:02:30 +0000484apex {
485 name: "com.android.apogee",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400486 %s
487 native_shared_libs: ["unnested_native_shared_lib"],
Jingwen Chen34feb142022-10-06 13:02:30 +0000488 multilib: {
489 both: {
490 native_shared_libs: [
491 "native_shared_lib_for_both",
492 ],
493 },
494 first: {
495 native_shared_libs: [
496 "native_shared_lib_for_first",
497 ],
498 },
499 lib32: {
500 native_shared_libs: [
501 "native_shared_lib_for_lib32",
502 ],
503 },
504 lib64: {
505 native_shared_libs: [
506 "native_shared_lib_for_lib64",
507 ],
508 },
509 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400510}`, compile_multilib)
Jingwen Chen34feb142022-10-06 13:02:30 +0000511}
512
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400513func TestApexBundleDefaultPropertyValues(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000514 runApexTestCase(t, Bp2buildTestCase{
515 Description: "apex - default property values",
516 ModuleTypeUnderTest: "apex",
517 ModuleTypeUnderTestFactory: apex.BundleFactory,
518 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700519 "system/sepolicy/apex/Android.bp": `
520filegroup {
521 name: "com.android.apogee-file_contexts",
522 srcs: [ "apogee-file_contexts", ],
523 bazel_module: { bp2build_available: false },
524}
525`,
526 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000527 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400528apex {
529 name: "com.android.apogee",
530 manifest: "apogee_manifest.json",
531}
532`,
Alixe06d75b2022-08-31 18:28:19 +0000533 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700534 "manifest": `"apogee_manifest.json"`,
535 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500536 }),
537 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400538}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000539
540func TestApexBundleHasBazelModuleProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000541 runApexTestCase(t, Bp2buildTestCase{
542 Description: "apex - has bazel module props",
543 ModuleTypeUnderTest: "apex",
544 ModuleTypeUnderTestFactory: apex.BundleFactory,
545 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700546 "system/sepolicy/apex/Android.bp": `
547filegroup {
548 name: "apogee-file_contexts",
549 srcs: [ "apogee-file_contexts", ],
550 bazel_module: { bp2build_available: false },
551}
552`,
553 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000554 Blueprint: `
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000555apex {
556 name: "apogee",
557 manifest: "manifest.json",
558 bazel_module: { bp2build_available: true },
559}
560`,
Alixe06d75b2022-08-31 18:28:19 +0000561 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700562 "manifest": `"manifest.json"`,
563 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500564 }),
565 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000566}
Yu Liu4ae55d12022-01-05 17:17:23 -0800567
Wei Li1c66fc72022-05-09 23:59:14 -0700568func TestBp2BuildOverrideApex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000569 runOverrideApexTestCase(t, Bp2buildTestCase{
570 Description: "override_apex",
571 ModuleTypeUnderTest: "override_apex",
572 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
573 Filesystem: map[string]string{},
574 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700575apex_key {
576 name: "com.android.apogee.key",
577 public_key: "com.android.apogee.avbpubkey",
578 private_key: "com.android.apogee.pem",
579 bazel_module: { bp2build_available: false },
580}
581
582android_app_certificate {
583 name: "com.android.apogee.certificate",
584 certificate: "com.android.apogee",
585 bazel_module: { bp2build_available: false },
586}
587
588cc_library {
589 name: "native_shared_lib_1",
590 bazel_module: { bp2build_available: false },
591}
592
593cc_library {
594 name: "native_shared_lib_2",
595 bazel_module: { bp2build_available: false },
596}
597
Jingwen Chen81c67d32022-06-08 16:08:25 +0000598prebuilt_etc {
599 name: "prebuilt_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700600 bazel_module: { bp2build_available: false },
601}
602
Jingwen Chen81c67d32022-06-08 16:08:25 +0000603prebuilt_etc {
604 name: "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700605 bazel_module: { bp2build_available: false },
606}
607
608filegroup {
609 name: "com.android.apogee-file_contexts",
610 srcs: [
611 "com.android.apogee-file_contexts",
612 ],
613 bazel_module: { bp2build_available: false },
614}
615
616cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
617sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
618
619apex {
620 name: "com.android.apogee",
621 manifest: "apogee_manifest.json",
622 androidManifest: "ApogeeAndroidManifest.xml",
623 file_contexts: ":com.android.apogee-file_contexts",
624 min_sdk_version: "29",
625 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000626 certificate: ":com.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700627 updatable: false,
628 installable: false,
629 compressible: false,
630 native_shared_libs: [
631 "native_shared_lib_1",
632 "native_shared_lib_2",
633 ],
634 binaries: [
635 "cc_binary_1",
636 "sh_binary_2",
637 ],
638 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000639 "prebuilt_1",
640 "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700641 ],
642 bazel_module: { bp2build_available: false },
643}
644
645apex_key {
646 name: "com.google.android.apogee.key",
647 public_key: "com.google.android.apogee.avbpubkey",
648 private_key: "com.google.android.apogee.pem",
649 bazel_module: { bp2build_available: false },
650}
651
652android_app_certificate {
653 name: "com.google.android.apogee.certificate",
654 certificate: "com.google.android.apogee",
655 bazel_module: { bp2build_available: false },
656}
657
658override_apex {
659 name: "com.google.android.apogee",
660 base: ":com.android.apogee",
661 key: "com.google.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000662 certificate: ":com.google.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700663 prebuilts: [],
664 compressible: true,
665}
666`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000667 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000668 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700669 "android_manifest": `"ApogeeAndroidManifest.xml"`,
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000670 "base_apex_name": `"com.android.apogee"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700671 "binaries": `[
672 ":cc_binary_1",
673 ":sh_binary_2",
674 ]`,
675 "certificate": `":com.google.android.apogee.certificate"`,
676 "file_contexts": `":com.android.apogee-file_contexts"`,
677 "installable": "False",
678 "key": `":com.google.android.apogee.key"`,
679 "manifest": `"apogee_manifest.json"`,
680 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400681 "native_shared_libs_32": `select({
682 "//build/bazel/platforms/arch:arm": [
683 ":native_shared_lib_1",
684 ":native_shared_lib_2",
685 ],
686 "//build/bazel/platforms/arch:x86": [
687 ":native_shared_lib_1",
688 ":native_shared_lib_2",
689 ],
690 "//conditions:default": [],
691 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700692 "native_shared_libs_64": `select({
693 "//build/bazel/platforms/arch:arm64": [
694 ":native_shared_lib_1",
695 ":native_shared_lib_2",
696 ],
697 "//build/bazel/platforms/arch:x86_64": [
698 ":native_shared_lib_1",
699 ":native_shared_lib_2",
700 ],
701 "//conditions:default": [],
702 })`,
703 "prebuilts": `[]`,
704 "updatable": "False",
705 "compressible": "True",
706 }),
707 }})
708}
Wei Li40f98732022-05-20 22:08:11 -0700709
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400710func TestOverrideApexTest(t *testing.T) {
711 runOverrideApexTestCase(t, Bp2buildTestCase{
712 Description: "override_apex",
713 ModuleTypeUnderTest: "override_apex",
714 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
715 Filesystem: map[string]string{},
716 Blueprint: `
717apex_key {
718 name: "com.android.apogee.key",
719 public_key: "com.android.apogee.avbpubkey",
720 private_key: "com.android.apogee.pem",
721 bazel_module: { bp2build_available: false },
722}
723
724android_app_certificate {
725 name: "com.android.apogee.certificate",
726 certificate: "com.android.apogee",
727 bazel_module: { bp2build_available: false },
728}
729
730cc_library {
731 name: "native_shared_lib_1",
732 bazel_module: { bp2build_available: false },
733}
734
735prebuilt_etc {
736 name: "prebuilt_1",
737 bazel_module: { bp2build_available: false },
738}
739
740filegroup {
741 name: "com.android.apogee-file_contexts",
742 srcs: [
743 "com.android.apogee-file_contexts",
744 ],
745 bazel_module: { bp2build_available: false },
746}
747
748cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
749sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
750
751apex_test {
752 name: "com.android.apogee",
753 manifest: "apogee_manifest.json",
754 androidManifest: "ApogeeAndroidManifest.xml",
755 file_contexts: ":com.android.apogee-file_contexts",
756 min_sdk_version: "29",
757 key: "com.android.apogee.key",
758 certificate: ":com.android.apogee.certificate",
759 updatable: false,
760 installable: false,
761 compressible: false,
762 native_shared_libs: [
763 "native_shared_lib_1",
764 ],
765 binaries: [
766 "cc_binary_1",
767 "sh_binary_2",
768 ],
769 prebuilts: [
770 "prebuilt_1",
771 ],
772 bazel_module: { bp2build_available: false },
773}
774
775apex_key {
776 name: "com.google.android.apogee.key",
777 public_key: "com.google.android.apogee.avbpubkey",
778 private_key: "com.google.android.apogee.pem",
779 bazel_module: { bp2build_available: false },
780}
781
782android_app_certificate {
783 name: "com.google.android.apogee.certificate",
784 certificate: "com.google.android.apogee",
785 bazel_module: { bp2build_available: false },
786}
787
788override_apex {
789 name: "com.google.android.apogee",
790 base: ":com.android.apogee",
791 key: "com.google.android.apogee.key",
792 certificate: ":com.google.android.apogee.certificate",
793 prebuilts: [],
794 compressible: true,
795}
796`,
797 ExpectedBazelTargets: []string{
798 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
799 "android_manifest": `"ApogeeAndroidManifest.xml"`,
800 "base_apex_name": `"com.android.apogee"`,
801 "binaries": `[
802 ":cc_binary_1",
803 ":sh_binary_2",
804 ]`,
805 "certificate": `":com.google.android.apogee.certificate"`,
806 "file_contexts": `":com.android.apogee-file_contexts"`,
807 "installable": "False",
808 "key": `":com.google.android.apogee.key"`,
809 "manifest": `"apogee_manifest.json"`,
810 "min_sdk_version": `"29"`,
811 "native_shared_libs_32": `select({
812 "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"],
813 "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"],
814 "//conditions:default": [],
815 })`,
816 "native_shared_libs_64": `select({
817 "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"],
818 "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"],
819 "//conditions:default": [],
820 })`,
821 "testonly": "True",
822 "prebuilts": `[]`,
823 "updatable": "False",
824 "compressible": "True",
825 }),
826 }})
827}
828
Wei Li40f98732022-05-20 22:08:11 -0700829func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000830 runOverrideApexTestCase(t, Bp2buildTestCase{
831 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
832 ModuleTypeUnderTest: "override_apex",
833 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
834 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700835 "system/sepolicy/apex/Android.bp": `
836filegroup {
837 name: "com.android.apogee-file_contexts",
838 srcs: [ "apogee-file_contexts", ],
839 bazel_module: { bp2build_available: false },
840}`,
841 "a/b/Android.bp": `
842apex {
843 name: "com.android.apogee",
844 bazel_module: { bp2build_available: false },
845}
846`,
847 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000848 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700849override_apex {
850 name: "com.google.android.apogee",
851 base: ":com.android.apogee",
852}
853`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000854 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000855 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000856 "base_apex_name": `"com.android.apogee"`,
857 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
858 "manifest": `"//a/b:apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700859 }),
860 }})
861}
862
863func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000864 runOverrideApexTestCase(t, Bp2buildTestCase{
865 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
866 ModuleTypeUnderTest: "override_apex",
867 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
868 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700869 "system/sepolicy/apex/Android.bp": `
870filegroup {
871 name: "com.android.apogee-file_contexts",
872 srcs: [ "apogee-file_contexts", ],
873 bazel_module: { bp2build_available: false },
874}`,
875 "a/b/Android.bp": `
876apex {
877 name: "com.android.apogee",
878 manifest: "apogee_manifest.json",
879 bazel_module: { bp2build_available: false },
880}
881`,
882 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000883 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700884override_apex {
885 name: "com.google.android.apogee",
886 base: ":com.android.apogee",
887}
888`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000889 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000890 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000891 "base_apex_name": `"com.android.apogee"`,
892 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
893 "manifest": `"//a/b:apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700894 }),
895 }})
896}
897
898func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000899 runOverrideApexTestCase(t, Bp2buildTestCase{
900 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
901 ModuleTypeUnderTest: "override_apex",
902 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
903 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700904 "system/sepolicy/apex/Android.bp": `
905filegroup {
906 name: "com.android.apogee-file_contexts",
907 srcs: [ "apogee-file_contexts", ],
908 bazel_module: { bp2build_available: false },
909}`,
910 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000911 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700912apex {
913 name: "com.android.apogee",
914 bazel_module: { bp2build_available: false },
915}
916
917override_apex {
918 name: "com.google.android.apogee",
919 base: ":com.android.apogee",
920}
921`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000922 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000923 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000924 "base_apex_name": `"com.android.apogee"`,
925 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
926 "manifest": `"apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700927 }),
928 }})
929}
930
931func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000932 runOverrideApexTestCase(t, Bp2buildTestCase{
933 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
934 ModuleTypeUnderTest: "override_apex",
935 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
936 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700937 "system/sepolicy/apex/Android.bp": `
938filegroup {
939 name: "com.android.apogee-file_contexts",
940 srcs: [ "apogee-file_contexts", ],
941 bazel_module: { bp2build_available: false },
942}`,
943 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000944 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700945apex {
946 name: "com.android.apogee",
947 manifest: "apogee_manifest.json",
948 bazel_module: { bp2build_available: false },
949}
950
951override_apex {
952 name: "com.google.android.apogee",
953 base: ":com.android.apogee",
954}
955`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000956 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000957 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000958 "base_apex_name": `"com.android.apogee"`,
959 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
960 "manifest": `"apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700961 }),
962 }})
963}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000964
965func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000966 runOverrideApexTestCase(t, Bp2buildTestCase{
967 Description: "override_apex - override package name",
968 ModuleTypeUnderTest: "override_apex",
969 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
970 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000971 "system/sepolicy/apex/Android.bp": `
972filegroup {
973 name: "com.android.apogee-file_contexts",
974 srcs: [ "apogee-file_contexts", ],
975 bazel_module: { bp2build_available: false },
976}`,
977 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000978 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000979apex {
980 name: "com.android.apogee",
981 bazel_module: { bp2build_available: false },
982}
983
984override_apex {
985 name: "com.google.android.apogee",
986 base: ":com.android.apogee",
987 package_name: "com.google.android.apogee",
988}
989`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000990 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000991 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000992 "base_apex_name": `"com.android.apogee"`,
993 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
994 "manifest": `"apex_manifest.json"`,
995 "package_name": `"com.google.android.apogee"`,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000996 }),
997 }})
998}
Jingwen Chendf165c92022-06-08 16:00:39 +0000999
1000func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001001 runOverrideApexTestCase(t, Bp2buildTestCase{
1002 Description: "override_apex - no override",
1003 ModuleTypeUnderTest: "override_apex",
1004 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1005 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001006 "system/sepolicy/apex/Android.bp": `
1007filegroup {
1008 name: "com.android.apogee-file_contexts",
1009 srcs: [ "apogee-file_contexts", ],
1010 bazel_module: { bp2build_available: false },
1011}`,
1012 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001013 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001014prebuilt_etc {
1015 name: "prebuilt_file",
1016 bazel_module: { bp2build_available: false },
1017}
1018
1019apex {
1020 name: "com.android.apogee",
1021 bazel_module: { bp2build_available: false },
1022 prebuilts: ["prebuilt_file"]
1023}
1024
1025override_apex {
1026 name: "com.google.android.apogee",
1027 base: ":com.android.apogee",
1028}
1029`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001030 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001031 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001032 "base_apex_name": `"com.android.apogee"`,
1033 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1034 "manifest": `"apex_manifest.json"`,
1035 "prebuilts": `[":prebuilt_file"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001036 }),
1037 }})
1038}
1039
1040func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001041 runOverrideApexTestCase(t, Bp2buildTestCase{
1042 Description: "override_apex - ooverride",
1043 ModuleTypeUnderTest: "override_apex",
1044 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1045 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001046 "system/sepolicy/apex/Android.bp": `
1047filegroup {
1048 name: "com.android.apogee-file_contexts",
1049 srcs: [ "apogee-file_contexts", ],
1050 bazel_module: { bp2build_available: false },
1051}`,
1052 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001053 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001054prebuilt_etc {
1055 name: "prebuilt_file",
1056 bazel_module: { bp2build_available: false },
1057}
1058
1059prebuilt_etc {
1060 name: "prebuilt_file2",
1061 bazel_module: { bp2build_available: false },
1062}
1063
1064apex {
1065 name: "com.android.apogee",
1066 bazel_module: { bp2build_available: false },
1067 prebuilts: ["prebuilt_file"]
1068}
1069
1070override_apex {
1071 name: "com.google.android.apogee",
1072 base: ":com.android.apogee",
1073 prebuilts: ["prebuilt_file2"]
1074}
1075`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001076 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001077 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001078 "base_apex_name": `"com.android.apogee"`,
1079 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1080 "manifest": `"apex_manifest.json"`,
1081 "prebuilts": `[":prebuilt_file2"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001082 }),
1083 }})
1084}
1085
1086func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001087 runOverrideApexTestCase(t, Bp2buildTestCase{
1088 Description: "override_apex - override with empty list",
1089 ModuleTypeUnderTest: "override_apex",
1090 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1091 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001092 "system/sepolicy/apex/Android.bp": `
1093filegroup {
1094 name: "com.android.apogee-file_contexts",
1095 srcs: [ "apogee-file_contexts", ],
1096 bazel_module: { bp2build_available: false },
1097}`,
1098 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001099 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001100prebuilt_etc {
1101 name: "prebuilt_file",
1102 bazel_module: { bp2build_available: false },
1103}
1104
1105apex {
1106 name: "com.android.apogee",
1107 bazel_module: { bp2build_available: false },
1108 prebuilts: ["prebuilt_file"]
1109}
1110
1111override_apex {
1112 name: "com.google.android.apogee",
1113 base: ":com.android.apogee",
1114 prebuilts: [],
1115}
1116`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001117 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001118 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001119 "base_apex_name": `"com.android.apogee"`,
1120 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1121 "manifest": `"apex_manifest.json"`,
1122 "prebuilts": `[]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001123 }),
1124 }})
1125}
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001126
1127func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001128 runOverrideApexTestCase(t, Bp2buildTestCase{
1129 Description: "override_apex - logging_parent - no override",
1130 ModuleTypeUnderTest: "override_apex",
1131 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1132 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001133 "system/sepolicy/apex/Android.bp": `
1134filegroup {
1135 name: "com.android.apogee-file_contexts",
1136 srcs: [ "apogee-file_contexts", ],
1137 bazel_module: { bp2build_available: false },
1138}`,
1139 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001140 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001141apex {
1142 name: "com.android.apogee",
1143 bazel_module: { bp2build_available: false },
1144 logging_parent: "foo.bar.baz",
1145}
1146
1147override_apex {
1148 name: "com.google.android.apogee",
1149 base: ":com.android.apogee",
1150}
1151`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001152 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001153 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001154 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001155 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1156 "manifest": `"apex_manifest.json"`,
1157 "logging_parent": `"foo.bar.baz"`,
1158 }),
1159 }})
1160}
1161
1162func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001163 runOverrideApexTestCase(t, Bp2buildTestCase{
1164 Description: "override_apex - logging_parent - override",
1165 ModuleTypeUnderTest: "override_apex",
1166 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1167 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001168 "system/sepolicy/apex/Android.bp": `
1169filegroup {
1170 name: "com.android.apogee-file_contexts",
1171 srcs: [ "apogee-file_contexts", ],
1172 bazel_module: { bp2build_available: false },
1173}`,
1174 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001175 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001176apex {
1177 name: "com.android.apogee",
1178 bazel_module: { bp2build_available: false },
1179 logging_parent: "foo.bar.baz",
1180}
1181
1182override_apex {
1183 name: "com.google.android.apogee",
1184 base: ":com.android.apogee",
1185 logging_parent: "foo.bar.baz.override",
1186}
1187`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001188 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001189 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001190 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001191 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1192 "manifest": `"apex_manifest.json"`,
1193 "logging_parent": `"foo.bar.baz.override"`,
1194 }),
1195 }})
1196}
Jingwen Chenbea58092022-09-29 16:56:02 +00001197
1198func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1199 runOverrideApexTestCase(t, Bp2buildTestCase{
1200 Description: "override_apex - don't set default certificate",
1201 ModuleTypeUnderTest: "override_apex",
1202 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1203 Filesystem: map[string]string{},
1204 Blueprint: `
1205android_app_certificate {
1206 name: "com.android.apogee.certificate",
1207 certificate: "com.android.apogee",
1208 bazel_module: { bp2build_available: false },
1209}
1210
1211filegroup {
1212 name: "com.android.apogee-file_contexts",
1213 srcs: [
1214 "com.android.apogee-file_contexts",
1215 ],
1216 bazel_module: { bp2build_available: false },
1217}
1218
1219apex {
1220 name: "com.android.apogee",
1221 manifest: "apogee_manifest.json",
1222 file_contexts: ":com.android.apogee-file_contexts",
1223 certificate: ":com.android.apogee.certificate",
1224 bazel_module: { bp2build_available: false },
1225}
1226
1227override_apex {
1228 name: "com.google.android.apogee",
1229 base: ":com.android.apogee",
1230 // certificate is deliberately omitted, and not converted to bazel,
1231 // because the overridden apex shouldn't be using the base apex's cert.
1232}
1233`,
1234 ExpectedBazelTargets: []string{
1235 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001236 "base_apex_name": `"com.android.apogee"`,
1237 "file_contexts": `":com.android.apogee-file_contexts"`,
1238 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001239 }),
1240 }})
1241}
1242
1243func TestApexCertificateIsModule(t *testing.T) {
1244 runApexTestCase(t, Bp2buildTestCase{
1245 Description: "apex - certificate is module",
1246 ModuleTypeUnderTest: "apex",
1247 ModuleTypeUnderTestFactory: apex.BundleFactory,
1248 Filesystem: map[string]string{},
1249 Blueprint: `
1250android_app_certificate {
1251 name: "com.android.apogee.certificate",
1252 certificate: "com.android.apogee",
1253 bazel_module: { bp2build_available: false },
1254}
1255
1256apex {
1257 name: "com.android.apogee",
1258 manifest: "apogee_manifest.json",
1259 file_contexts: ":com.android.apogee-file_contexts",
1260 certificate: ":com.android.apogee.certificate",
1261}
1262` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1263 ExpectedBazelTargets: []string{
1264 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1265 "certificate": `":com.android.apogee.certificate"`,
1266 "file_contexts": `":com.android.apogee-file_contexts"`,
1267 "manifest": `"apogee_manifest.json"`,
1268 }),
1269 }})
1270}
1271
Vinh Tran55225e32022-12-20 10:38:48 -05001272func TestApexWithStubLib(t *testing.T) {
1273 runApexTestCase(t, Bp2buildTestCase{
1274 Description: "apex - static variant of stub lib should not have apex_available tag",
1275 ModuleTypeUnderTest: "apex",
1276 ModuleTypeUnderTestFactory: apex.BundleFactory,
1277 Filesystem: map[string]string{},
1278 Blueprint: `
1279cc_library{
1280 name: "foo",
1281 stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
1282 apex_available: ["myapex"],
1283}
1284
1285cc_binary{
1286 name: "bar",
1287 static_libs: ["foo"],
1288 apex_available: ["myapex"],
1289}
1290
1291apex {
1292 name: "myapex",
1293 manifest: "myapex_manifest.json",
1294 file_contexts: ":myapex-file_contexts",
1295 binaries: ["bar"],
1296 native_shared_libs: ["foo"],
1297}
1298` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"),
1299 ExpectedBazelTargets: []string{
1300 MakeBazelTarget("cc_binary", "bar", AttrNameToString{
1301 "local_includes": `["."]`,
1302 "deps": `[":foo_bp2build_cc_library_static"]`,
1303 "tags": `["apex_available=myapex"]`,
1304 }),
1305 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
1306 "local_includes": `["."]`,
1307 }),
1308 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1309 "local_includes": `["."]`,
1310 "stubs_symbol_file": `"foo.map.txt"`,
1311 "tags": `["apex_available=myapex"]`,
1312 }),
1313 MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
Sam Delmerico5f906492023-03-15 18:06:18 -04001314 "soname": `"foo.so"`,
1315 "source_library_label": `"//:foo"`,
1316 "symbol_file": `"foo.map.txt"`,
Vinh Tran55225e32022-12-20 10:38:48 -05001317 "versions": `[
1318 "28",
1319 "29",
1320 "current",
1321 ]`,
1322 }),
1323 MakeBazelTarget("apex", "myapex", AttrNameToString{
1324 "file_contexts": `":myapex-file_contexts"`,
1325 "manifest": `"myapex_manifest.json"`,
1326 "binaries": `[":bar"]`,
1327 "native_shared_libs_32": `select({
1328 "//build/bazel/platforms/arch:arm": [":foo"],
1329 "//build/bazel/platforms/arch:x86": [":foo"],
1330 "//conditions:default": [],
1331 })`,
1332 "native_shared_libs_64": `select({
1333 "//build/bazel/platforms/arch:arm64": [":foo"],
1334 "//build/bazel/platforms/arch:x86_64": [":foo"],
1335 "//conditions:default": [],
1336 })`,
1337 }),
1338 },
1339 })
1340}
1341
Jingwen Chenbea58092022-09-29 16:56:02 +00001342func TestApexCertificateIsSrc(t *testing.T) {
1343 runApexTestCase(t, Bp2buildTestCase{
1344 Description: "apex - certificate is src",
1345 ModuleTypeUnderTest: "apex",
1346 ModuleTypeUnderTestFactory: apex.BundleFactory,
1347 Filesystem: map[string]string{},
1348 Blueprint: `
1349apex {
1350 name: "com.android.apogee",
1351 manifest: "apogee_manifest.json",
1352 file_contexts: ":com.android.apogee-file_contexts",
1353 certificate: "com.android.apogee.certificate",
1354}
1355` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1356 ExpectedBazelTargets: []string{
1357 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1358 "certificate_name": `"com.android.apogee.certificate"`,
1359 "file_contexts": `":com.android.apogee-file_contexts"`,
1360 "manifest": `"apogee_manifest.json"`,
1361 }),
1362 }})
1363}
1364
1365func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1366 runOverrideApexTestCase(t, Bp2buildTestCase{
1367 Description: "override_apex - certificate is module",
1368 ModuleTypeUnderTest: "override_apex",
1369 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1370 Filesystem: map[string]string{},
1371 Blueprint: `
1372android_app_certificate {
1373 name: "com.android.apogee.certificate",
1374 certificate: "com.android.apogee",
1375 bazel_module: { bp2build_available: false },
1376}
1377
1378filegroup {
1379 name: "com.android.apogee-file_contexts",
1380 srcs: [
1381 "com.android.apogee-file_contexts",
1382 ],
1383 bazel_module: { bp2build_available: false },
1384}
1385
1386apex {
1387 name: "com.android.apogee",
1388 manifest: "apogee_manifest.json",
1389 file_contexts: ":com.android.apogee-file_contexts",
1390 certificate: ":com.android.apogee.certificate",
1391 bazel_module: { bp2build_available: false },
1392}
1393
1394android_app_certificate {
1395 name: "com.google.android.apogee.certificate",
1396 certificate: "com.google.android.apogee",
1397 bazel_module: { bp2build_available: false },
1398}
1399
1400override_apex {
1401 name: "com.google.android.apogee",
1402 base: ":com.android.apogee",
1403 certificate: ":com.google.android.apogee.certificate",
1404}
1405`,
1406 ExpectedBazelTargets: []string{
1407 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001408 "base_apex_name": `"com.android.apogee"`,
1409 "file_contexts": `":com.android.apogee-file_contexts"`,
1410 "certificate": `":com.google.android.apogee.certificate"`,
1411 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001412 }),
1413 }})
1414}
1415
1416func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1417 runOverrideApexTestCase(t, Bp2buildTestCase{
1418 Description: "override_apex - certificate is src",
1419 ModuleTypeUnderTest: "override_apex",
1420 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1421 Filesystem: map[string]string{},
1422 Blueprint: `
1423android_app_certificate {
1424 name: "com.android.apogee.certificate",
1425 certificate: "com.android.apogee",
1426 bazel_module: { bp2build_available: false },
1427}
1428
1429filegroup {
1430 name: "com.android.apogee-file_contexts",
1431 srcs: [
1432 "com.android.apogee-file_contexts",
1433 ],
1434 bazel_module: { bp2build_available: false },
1435}
1436
1437apex {
1438 name: "com.android.apogee",
1439 manifest: "apogee_manifest.json",
1440 file_contexts: ":com.android.apogee-file_contexts",
1441 certificate: ":com.android.apogee.certificate",
1442 bazel_module: { bp2build_available: false },
1443}
1444
1445override_apex {
1446 name: "com.google.android.apogee",
1447 base: ":com.android.apogee",
1448 certificate: "com.google.android.apogee.certificate",
1449}
1450`,
1451 ExpectedBazelTargets: []string{
1452 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001453 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001454 "file_contexts": `":com.android.apogee-file_contexts"`,
1455 "certificate_name": `"com.google.android.apogee.certificate"`,
1456 "manifest": `"apogee_manifest.json"`,
1457 }),
1458 }})
1459}
Yu Liu4c212ce2022-10-14 12:20:20 -07001460
1461func TestApexTestBundleSimple(t *testing.T) {
1462 runApexTestCase(t, Bp2buildTestCase{
1463 Description: "apex_test - simple",
1464 ModuleTypeUnderTest: "apex_test",
1465 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1466 Filesystem: map[string]string{},
1467 Blueprint: `
1468cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
1469
1470apex_test {
1471 name: "test_com.android.apogee",
1472 file_contexts: "file_contexts_file",
1473 tests: ["cc_test_1"],
1474}
1475`,
1476 ExpectedBazelTargets: []string{
1477 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
1478 "file_contexts": `"file_contexts_file"`,
1479 "manifest": `"apex_manifest.json"`,
1480 "testonly": `True`,
1481 "tests": `[":cc_test_1"]`,
1482 }),
1483 }})
1484}
Cole Faust912bc882023-03-08 12:29:50 -08001485
1486func TestApexBundle_overridePlusProductVars(t *testing.T) {
1487 // Reproduction of b/271424349
1488 // Tests that overriding an apex that uses product variables correctly copies the product var
1489 // selects over to the override.
1490 runOverrideApexTestCase(t, Bp2buildTestCase{
1491 Description: "apex - overriding a module that uses product vars",
1492 ModuleTypeUnderTest: "override_apex",
1493 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1494 Blueprint: `
1495soong_config_string_variable {
1496 name: "library_linking_strategy",
1497 values: [
1498 "prefer_static",
1499 ],
1500}
1501
1502soong_config_module_type {
1503 name: "library_linking_strategy_apex_defaults",
1504 module_type: "apex_defaults",
1505 config_namespace: "ANDROID",
1506 variables: ["library_linking_strategy"],
1507 properties: [
1508 "manifest",
1509 "min_sdk_version",
1510 ],
1511}
1512
1513library_linking_strategy_apex_defaults {
1514 name: "higher_min_sdk_when_prefer_static",
1515 soong_config_variables: {
1516 library_linking_strategy: {
1517 // Use the R min_sdk_version
1518 prefer_static: {},
1519 // Override the R min_sdk_version to min_sdk_version that supports dcla
1520 conditions_default: {
1521 min_sdk_version: "31",
1522 },
1523 },
1524 },
1525}
1526
1527filegroup {
1528 name: "foo-file_contexts",
1529 srcs: [
1530 "com.android.apogee-file_contexts",
1531 ],
1532 bazel_module: { bp2build_available: false },
1533}
1534
1535apex {
1536 name: "foo",
1537 defaults: ["higher_min_sdk_when_prefer_static"],
1538 min_sdk_version: "30",
1539 package_name: "pkg_name",
1540 file_contexts: ":foo-file_contexts",
1541}
1542override_apex {
1543 name: "override_foo",
1544 base: ":foo",
1545 package_name: "override_pkg_name",
1546}
1547`,
1548 ExpectedBazelTargets: []string{
1549 MakeBazelTarget("apex", "foo", AttrNameToString{
1550 "file_contexts": `":foo-file_contexts"`,
1551 "manifest": `"apex_manifest.json"`,
1552 "min_sdk_version": `select({
1553 "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30",
1554 "//conditions:default": "31",
1555 })`,
1556 "package_name": `"pkg_name"`,
1557 }), MakeBazelTarget("apex", "override_foo", AttrNameToString{
1558 "base_apex_name": `"foo"`,
1559 "file_contexts": `":foo-file_contexts"`,
1560 "manifest": `"apex_manifest.json"`,
1561 "min_sdk_version": `select({
1562 "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30",
1563 "//conditions:default": "31",
1564 })`,
1565 "package_name": `"override_pkg_name"`,
1566 }),
1567 }})
1568}
Jingwen Chena8623da2023-03-28 13:05:02 +00001569
1570func TestApexBundleSimple_customCannedFsConfig(t *testing.T) {
1571 runApexTestCase(t, Bp2buildTestCase{
1572 Description: "apex - custom canned_fs_config",
1573 ModuleTypeUnderTest: "apex",
1574 ModuleTypeUnderTestFactory: apex.BundleFactory,
1575 Filesystem: map[string]string{},
1576 Blueprint: `
1577apex {
1578 name: "com.android.apogee",
1579 canned_fs_config: "custom.canned_fs_config",
1580 file_contexts: "file_contexts_file",
1581}
1582`,
1583 ExpectedBazelTargets: []string{
1584 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1585 "canned_fs_config": `"custom.canned_fs_config"`,
1586 "file_contexts": `"file_contexts_file"`,
1587 "manifest": `"apex_manifest.json"`,
1588 }),
1589 }})
1590}