Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 1 | // 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/apex" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 20 | "android/soong/cc" |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 21 | "android/soong/etc" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 22 | "android/soong/java" |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 23 | "android/soong/sh" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 24 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 25 | "fmt" |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 26 | "testing" |
| 27 | ) |
| 28 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 29 | func runApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 30 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 31 | RunBp2BuildTestCase(t, registerApexModuleTypes, tc) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 35 | // CC module types needed as they can be APEX dependencies |
| 36 | cc.RegisterCCBuildComponents(ctx) |
| 37 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 38 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 39 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 40 | 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 Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 44 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 45 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 48 | func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 49 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 50 | RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func 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 Kammer | 1a1c9df | 2023-03-28 11:39:50 -0400 | [diff] [blame] | 61 | ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 62 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 63 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 64 | ctx.RegisterModuleType("apex", apex.BundleFactory) |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 65 | ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory) |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 66 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 67 | ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory) |
| 68 | ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 71 | func TestApexBundleSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 72 | 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 Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 78 | apex_key { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 79 | name: "com.android.apogee.key", |
| 80 | public_key: "com.android.apogee.avbpubkey", |
| 81 | private_key: "com.android.apogee.pem", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 82 | bazel_module: { bp2build_available: false }, |
| 83 | } |
| 84 | |
| 85 | android_app_certificate { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 86 | name: "com.android.apogee.certificate", |
| 87 | certificate: "com.android.apogee", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 88 | bazel_module: { bp2build_available: false }, |
| 89 | } |
| 90 | |
| 91 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 92 | name: "native_shared_lib_1", |
| 93 | bazel_module: { bp2build_available: false }, |
| 94 | } |
| 95 | |
| 96 | cc_library { |
| 97 | name: "native_shared_lib_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 98 | bazel_module: { bp2build_available: false }, |
| 99 | } |
| 100 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 101 | prebuilt_etc { |
| 102 | name: "prebuilt_1", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 103 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 106 | prebuilt_etc { |
| 107 | name: "prebuilt_2", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 108 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 111 | filegroup { |
| 112 | name: "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 113 | srcs: [ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 114 | "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 115 | ], |
| 116 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 119 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 120 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 121 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 122 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 123 | name: "com.android.apogee", |
| 124 | manifest: "apogee_manifest.json", |
| 125 | androidManifest: "ApogeeAndroidManifest.xml", |
Sam Delmerico | e860d14 | 2023-06-06 15:47:30 -0400 | [diff] [blame] | 126 | apex_available_name: "apogee_apex_name", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 127 | file_contexts: ":com.android.apogee-file_contexts", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 128 | min_sdk_version: "29", |
| 129 | key: "com.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 130 | certificate: ":com.android.apogee.certificate", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 131 | updatable: false, |
| 132 | installable: false, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 133 | compressible: false, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 134 | native_shared_libs: [ |
| 135 | "native_shared_lib_1", |
| 136 | "native_shared_lib_2", |
| 137 | ], |
| 138 | binaries: [ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 139 | "cc_binary_1", |
| 140 | "sh_binary_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 141 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 142 | prebuilts: [ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 143 | "prebuilt_1", |
| 144 | "prebuilt_2", |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 145 | ], |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 146 | package_name: "com.android.apogee.test.package", |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 147 | logging_parent: "logging.parent", |
Sam Delmerico | e860d14 | 2023-06-06 15:47:30 -0400 | [diff] [blame] | 148 | variant_version: "3", |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 149 | } |
| 150 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 151 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 152 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Sam Delmerico | e860d14 | 2023-06-06 15:47:30 -0400 | [diff] [blame] | 153 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 154 | "apex_available_name": `"apogee_apex_name"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 155 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 156 | ":cc_binary_1", |
| 157 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 158 | ]`, |
| 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 Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 165 | "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 Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 176 | "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 Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 187 | "prebuilts": `[ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 188 | ":prebuilt_1", |
| 189 | ":prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 190 | ]`, |
Sam Delmerico | e860d14 | 2023-06-06 15:47:30 -0400 | [diff] [blame] | 191 | "updatable": "False", |
| 192 | "compressible": "False", |
| 193 | "package_name": `"com.android.apogee.test.package"`, |
| 194 | "logging_parent": `"logging.parent"`, |
| 195 | "variant_version": `"3"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 196 | }), |
| 197 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 200 | func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 201 | 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 Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 206 | "a/b/Android.bp": ` |
| 207 | filegroup { |
| 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 Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 216 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 217 | apex { |
| 218 | name: "com.android.apogee", |
| 219 | file_contexts: ":com.android.apogee-file_contexts", |
| 220 | } |
| 221 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 222 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 223 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 224 | "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 225 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 226 | }), |
| 227 | }}) |
| 228 | } |
| 229 | |
| 230 | func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 231 | 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 Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 237 | apex { |
| 238 | name: "com.android.apogee", |
| 239 | file_contexts: "file_contexts_file", |
| 240 | } |
| 241 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 242 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 243 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 244 | "file_contexts": `"file_contexts_file"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 245 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 246 | }), |
| 247 | }}) |
| 248 | } |
| 249 | |
| 250 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 251 | runApexTestCase(t, Bp2buildTestCase{ |
| 252 | Description: "apex - file contexts is not specified", |
| 253 | ModuleTypeUnderTest: "apex", |
| 254 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 255 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 256 | "system/sepolicy/apex/Android.bp": ` |
| 257 | filegroup { |
| 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 Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 266 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 267 | apex { |
| 268 | name: "com.android.apogee", |
| 269 | } |
| 270 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 271 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 272 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 273 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 274 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 275 | }), |
| 276 | }}) |
| 277 | } |
| 278 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 279 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 280 | runApexTestCase(t, Bp2buildTestCase{ |
| 281 | Description: "apex - example with compile_multilib=both", |
| 282 | ModuleTypeUnderTest: "apex", |
| 283 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 284 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 285 | "system/sepolicy/apex/Android.bp": ` |
| 286 | filegroup { |
| 287 | name: "com.android.apogee-file_contexts", |
| 288 | srcs: [ "apogee-file_contexts", ], |
| 289 | bazel_module: { bp2build_available: false }, |
| 290 | } |
| 291 | `, |
| 292 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 293 | Blueprint: createMultilibBlueprint(`compile_multilib: "both",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 294 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 295 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 296 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 297 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 298 | ":native_shared_lib_for_both", |
| 299 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 300 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 301 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 302 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 303 | "//conditions:default": [], |
| 304 | })`, |
| 305 | "native_shared_libs_64": `select({ |
| 306 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 307 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 308 | ":native_shared_lib_for_both", |
| 309 | ":native_shared_lib_for_lib64", |
| 310 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 311 | ], |
| 312 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 313 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 314 | ":native_shared_lib_for_both", |
| 315 | ":native_shared_lib_for_lib64", |
| 316 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 317 | ], |
| 318 | "//conditions:default": [], |
| 319 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 320 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 321 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 322 | }), |
| 323 | }}) |
| 324 | } |
| 325 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 326 | func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) { |
| 327 | expectedBazelTargets := []string{ |
| 328 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 329 | "native_shared_libs_32": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 330 | "//build/bazel/platforms/arch:arm": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 331 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 332 | ":native_shared_lib_for_both", |
| 333 | ":native_shared_lib_for_lib32", |
| 334 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 335 | ], |
| 336 | "//build/bazel/platforms/arch:x86": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 337 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 338 | ":native_shared_lib_for_both", |
| 339 | ":native_shared_lib_for_lib32", |
| 340 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 341 | ], |
| 342 | "//conditions:default": [], |
| 343 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 344 | "native_shared_libs_64": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 345 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 346 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 347 | ":native_shared_lib_for_both", |
| 348 | ":native_shared_lib_for_lib64", |
| 349 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 350 | ], |
| 351 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 352 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 353 | ":native_shared_lib_for_both", |
| 354 | ":native_shared_lib_for_lib64", |
| 355 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 356 | ], |
| 357 | "//conditions:default": [], |
| 358 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 359 | "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 Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | func TestApexBundleCompileMultilib32(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 392 | runApexTestCase(t, Bp2buildTestCase{ |
| 393 | Description: "apex - example with compile_multilib=32", |
| 394 | ModuleTypeUnderTest: "apex", |
| 395 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 396 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 397 | "system/sepolicy/apex/Android.bp": ` |
| 398 | filegroup { |
| 399 | name: "com.android.apogee-file_contexts", |
| 400 | srcs: [ "apogee-file_contexts", ], |
| 401 | bazel_module: { bp2build_available: false }, |
| 402 | } |
| 403 | `, |
| 404 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 405 | Blueprint: createMultilibBlueprint(`compile_multilib: "32",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 406 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 407 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 408 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 409 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 410 | ":native_shared_lib_for_both", |
| 411 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 412 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 413 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 414 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 415 | "//conditions:default": [], |
| 416 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 417 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 418 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 419 | }), |
| 420 | }}) |
| 421 | } |
| 422 | |
| 423 | func TestApexBundleCompileMultilib64(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 424 | runApexTestCase(t, Bp2buildTestCase{ |
| 425 | Description: "apex - example with compile_multilib=64", |
| 426 | ModuleTypeUnderTest: "apex", |
| 427 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 428 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 429 | "system/sepolicy/apex/Android.bp": ` |
| 430 | filegroup { |
| 431 | name: "com.android.apogee-file_contexts", |
| 432 | srcs: [ "apogee-file_contexts", ], |
| 433 | bazel_module: { bp2build_available: false }, |
| 434 | } |
| 435 | `, |
| 436 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 437 | Blueprint: createMultilibBlueprint(`compile_multilib: "64",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 438 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 439 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 440 | "native_shared_libs_64": `select({ |
| 441 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 442 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 443 | ":native_shared_lib_for_both", |
| 444 | ":native_shared_lib_for_lib64", |
| 445 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 446 | ], |
| 447 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 448 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 449 | ":native_shared_lib_for_both", |
| 450 | ":native_shared_lib_for_lib64", |
| 451 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 452 | ], |
| 453 | "//conditions:default": [], |
| 454 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 455 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 456 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 457 | }), |
| 458 | }}) |
| 459 | } |
| 460 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 461 | func createMultilibBlueprint(compile_multilib string) string { |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 462 | return fmt.Sprintf(` |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 463 | cc_library { |
| 464 | name: "native_shared_lib_for_both", |
| 465 | bazel_module: { bp2build_available: false }, |
| 466 | } |
| 467 | |
| 468 | cc_library { |
| 469 | name: "native_shared_lib_for_first", |
| 470 | bazel_module: { bp2build_available: false }, |
| 471 | } |
| 472 | |
| 473 | cc_library { |
| 474 | name: "native_shared_lib_for_lib32", |
| 475 | bazel_module: { bp2build_available: false }, |
| 476 | } |
| 477 | |
| 478 | cc_library { |
| 479 | name: "native_shared_lib_for_lib64", |
| 480 | bazel_module: { bp2build_available: false }, |
| 481 | } |
| 482 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 483 | cc_library { |
| 484 | name: "unnested_native_shared_lib", |
| 485 | bazel_module: { bp2build_available: false }, |
| 486 | } |
| 487 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 488 | apex { |
| 489 | name: "com.android.apogee", |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 490 | %s |
| 491 | native_shared_libs: ["unnested_native_shared_lib"], |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 492 | 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 Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 514 | }`, compile_multilib) |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 517 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 518 | runApexTestCase(t, Bp2buildTestCase{ |
| 519 | Description: "apex - default property values", |
| 520 | ModuleTypeUnderTest: "apex", |
| 521 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 522 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 523 | "system/sepolicy/apex/Android.bp": ` |
| 524 | filegroup { |
| 525 | name: "com.android.apogee-file_contexts", |
| 526 | srcs: [ "apogee-file_contexts", ], |
| 527 | bazel_module: { bp2build_available: false }, |
| 528 | } |
| 529 | `, |
| 530 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 531 | Blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 532 | apex { |
| 533 | name: "com.android.apogee", |
| 534 | manifest: "apogee_manifest.json", |
| 535 | } |
| 536 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 537 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 538 | "manifest": `"apogee_manifest.json"`, |
| 539 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 540 | }), |
| 541 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 542 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 543 | |
| 544 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 545 | runApexTestCase(t, Bp2buildTestCase{ |
| 546 | Description: "apex - has bazel module props", |
| 547 | ModuleTypeUnderTest: "apex", |
| 548 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 549 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 550 | "system/sepolicy/apex/Android.bp": ` |
| 551 | filegroup { |
| 552 | name: "apogee-file_contexts", |
| 553 | srcs: [ "apogee-file_contexts", ], |
| 554 | bazel_module: { bp2build_available: false }, |
| 555 | } |
| 556 | `, |
| 557 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 558 | Blueprint: ` |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 559 | apex { |
| 560 | name: "apogee", |
| 561 | manifest: "manifest.json", |
| 562 | bazel_module: { bp2build_available: true }, |
| 563 | } |
| 564 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 565 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 566 | "manifest": `"manifest.json"`, |
| 567 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 568 | }), |
| 569 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 570 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 571 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 572 | func TestBp2BuildOverrideApex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 573 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 574 | Description: "override_apex", |
| 575 | ModuleTypeUnderTest: "override_apex", |
| 576 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 577 | Filesystem: map[string]string{}, |
| 578 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 579 | apex_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 | |
| 586 | android_app_certificate { |
| 587 | name: "com.android.apogee.certificate", |
| 588 | certificate: "com.android.apogee", |
| 589 | bazel_module: { bp2build_available: false }, |
| 590 | } |
| 591 | |
| 592 | cc_library { |
| 593 | name: "native_shared_lib_1", |
| 594 | bazel_module: { bp2build_available: false }, |
| 595 | } |
| 596 | |
| 597 | cc_library { |
| 598 | name: "native_shared_lib_2", |
| 599 | bazel_module: { bp2build_available: false }, |
| 600 | } |
| 601 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 602 | prebuilt_etc { |
| 603 | name: "prebuilt_1", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 604 | bazel_module: { bp2build_available: false }, |
| 605 | } |
| 606 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 607 | prebuilt_etc { |
| 608 | name: "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 609 | bazel_module: { bp2build_available: false }, |
| 610 | } |
| 611 | |
| 612 | filegroup { |
| 613 | name: "com.android.apogee-file_contexts", |
| 614 | srcs: [ |
| 615 | "com.android.apogee-file_contexts", |
| 616 | ], |
| 617 | bazel_module: { bp2build_available: false }, |
| 618 | } |
| 619 | |
| 620 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 621 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 622 | |
| 623 | apex { |
| 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 Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 630 | certificate: ":com.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 631 | 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 Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 643 | "prebuilt_1", |
| 644 | "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 645 | ], |
| 646 | bazel_module: { bp2build_available: false }, |
| 647 | } |
| 648 | |
| 649 | apex_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 | |
| 656 | android_app_certificate { |
| 657 | name: "com.google.android.apogee.certificate", |
| 658 | certificate: "com.google.android.apogee", |
| 659 | bazel_module: { bp2build_available: false }, |
| 660 | } |
| 661 | |
| 662 | override_apex { |
| 663 | name: "com.google.android.apogee", |
| 664 | base: ":com.android.apogee", |
| 665 | key: "com.google.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 666 | certificate: ":com.google.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 667 | prebuilts: [], |
| 668 | compressible: true, |
| 669 | } |
| 670 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 671 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 672 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 673 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 674 | "base_apex_name": `"com.android.apogee"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 675 | "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 Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 685 | "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 Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 696 | "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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 713 | |
Liz Kammer | 1a1c9df | 2023-03-28 11:39:50 -0400 | [diff] [blame] | 714 | func 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: ` |
| 721 | apex_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 | |
| 728 | android_app_certificate { |
| 729 | name: "com.android.apogee.certificate", |
| 730 | certificate: "com.android.apogee", |
| 731 | bazel_module: { bp2build_available: false }, |
| 732 | } |
| 733 | |
| 734 | cc_library { |
| 735 | name: "native_shared_lib_1", |
| 736 | bazel_module: { bp2build_available: false }, |
| 737 | } |
| 738 | |
| 739 | prebuilt_etc { |
| 740 | name: "prebuilt_1", |
| 741 | bazel_module: { bp2build_available: false }, |
| 742 | } |
| 743 | |
| 744 | filegroup { |
| 745 | name: "com.android.apogee-file_contexts", |
| 746 | srcs: [ |
| 747 | "com.android.apogee-file_contexts", |
| 748 | ], |
| 749 | bazel_module: { bp2build_available: false }, |
| 750 | } |
| 751 | |
| 752 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 753 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 754 | |
| 755 | apex_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 | |
| 779 | apex_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 | |
| 786 | android_app_certificate { |
| 787 | name: "com.google.android.apogee.certificate", |
| 788 | certificate: "com.google.android.apogee", |
| 789 | bazel_module: { bp2build_available: false }, |
| 790 | } |
| 791 | |
| 792 | override_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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 833 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 834 | 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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 839 | "system/sepolicy/apex/Android.bp": ` |
| 840 | filegroup { |
| 841 | name: "com.android.apogee-file_contexts", |
| 842 | srcs: [ "apogee-file_contexts", ], |
| 843 | bazel_module: { bp2build_available: false }, |
| 844 | }`, |
| 845 | "a/b/Android.bp": ` |
| 846 | apex { |
| 847 | name: "com.android.apogee", |
| 848 | bazel_module: { bp2build_available: false }, |
| 849 | } |
| 850 | `, |
| 851 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 852 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 853 | override_apex { |
| 854 | name: "com.google.android.apogee", |
| 855 | base: ":com.android.apogee", |
| 856 | } |
| 857 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 858 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 859 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 860 | "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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 863 | }), |
| 864 | }}) |
| 865 | } |
| 866 | |
| 867 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 868 | 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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 873 | "system/sepolicy/apex/Android.bp": ` |
| 874 | filegroup { |
| 875 | name: "com.android.apogee-file_contexts", |
| 876 | srcs: [ "apogee-file_contexts", ], |
| 877 | bazel_module: { bp2build_available: false }, |
| 878 | }`, |
| 879 | "a/b/Android.bp": ` |
| 880 | apex { |
| 881 | name: "com.android.apogee", |
| 882 | manifest: "apogee_manifest.json", |
| 883 | bazel_module: { bp2build_available: false }, |
| 884 | } |
| 885 | `, |
| 886 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 887 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 888 | override_apex { |
| 889 | name: "com.google.android.apogee", |
| 890 | base: ":com.android.apogee", |
| 891 | } |
| 892 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 893 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 894 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 895 | "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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 898 | }), |
| 899 | }}) |
| 900 | } |
| 901 | |
| 902 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 903 | 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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 908 | "system/sepolicy/apex/Android.bp": ` |
| 909 | filegroup { |
| 910 | name: "com.android.apogee-file_contexts", |
| 911 | srcs: [ "apogee-file_contexts", ], |
| 912 | bazel_module: { bp2build_available: false }, |
| 913 | }`, |
| 914 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 915 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 916 | apex { |
| 917 | name: "com.android.apogee", |
| 918 | bazel_module: { bp2build_available: false }, |
| 919 | } |
| 920 | |
| 921 | override_apex { |
| 922 | name: "com.google.android.apogee", |
| 923 | base: ":com.android.apogee", |
| 924 | } |
| 925 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 926 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 927 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 928 | "base_apex_name": `"com.android.apogee"`, |
| 929 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 930 | "manifest": `"apex_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 931 | }), |
| 932 | }}) |
| 933 | } |
| 934 | |
| 935 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 936 | 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 Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 941 | "system/sepolicy/apex/Android.bp": ` |
| 942 | filegroup { |
| 943 | name: "com.android.apogee-file_contexts", |
| 944 | srcs: [ "apogee-file_contexts", ], |
| 945 | bazel_module: { bp2build_available: false }, |
| 946 | }`, |
| 947 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 948 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 949 | apex { |
| 950 | name: "com.android.apogee", |
| 951 | manifest: "apogee_manifest.json", |
| 952 | bazel_module: { bp2build_available: false }, |
| 953 | } |
| 954 | |
| 955 | override_apex { |
| 956 | name: "com.google.android.apogee", |
| 957 | base: ":com.android.apogee", |
| 958 | } |
| 959 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 960 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 961 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 962 | "base_apex_name": `"com.android.apogee"`, |
| 963 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 964 | "manifest": `"apogee_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 965 | }), |
| 966 | }}) |
| 967 | } |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 968 | |
| 969 | func TestApexBundleSimple_packageNameOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 970 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 971 | Description: "override_apex - override package name", |
| 972 | ModuleTypeUnderTest: "override_apex", |
| 973 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 974 | Filesystem: map[string]string{ |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 975 | "system/sepolicy/apex/Android.bp": ` |
| 976 | filegroup { |
| 977 | name: "com.android.apogee-file_contexts", |
| 978 | srcs: [ "apogee-file_contexts", ], |
| 979 | bazel_module: { bp2build_available: false }, |
| 980 | }`, |
| 981 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 982 | Blueprint: ` |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 983 | apex { |
| 984 | name: "com.android.apogee", |
| 985 | bazel_module: { bp2build_available: false }, |
| 986 | } |
| 987 | |
| 988 | override_apex { |
| 989 | name: "com.google.android.apogee", |
| 990 | base: ":com.android.apogee", |
| 991 | package_name: "com.google.android.apogee", |
| 992 | } |
| 993 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 994 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 995 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 996 | "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 Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 1000 | }), |
| 1001 | }}) |
| 1002 | } |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1003 | |
| 1004 | func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1005 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1006 | Description: "override_apex - no override", |
| 1007 | ModuleTypeUnderTest: "override_apex", |
| 1008 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1009 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1010 | "system/sepolicy/apex/Android.bp": ` |
| 1011 | filegroup { |
| 1012 | name: "com.android.apogee-file_contexts", |
| 1013 | srcs: [ "apogee-file_contexts", ], |
| 1014 | bazel_module: { bp2build_available: false }, |
| 1015 | }`, |
| 1016 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1017 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1018 | prebuilt_etc { |
| 1019 | name: "prebuilt_file", |
| 1020 | bazel_module: { bp2build_available: false }, |
| 1021 | } |
| 1022 | |
| 1023 | apex { |
| 1024 | name: "com.android.apogee", |
| 1025 | bazel_module: { bp2build_available: false }, |
| 1026 | prebuilts: ["prebuilt_file"] |
| 1027 | } |
| 1028 | |
| 1029 | override_apex { |
| 1030 | name: "com.google.android.apogee", |
| 1031 | base: ":com.android.apogee", |
| 1032 | } |
| 1033 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1034 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1035 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1036 | "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 Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1040 | }), |
| 1041 | }}) |
| 1042 | } |
| 1043 | |
| 1044 | func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1045 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1046 | Description: "override_apex - ooverride", |
| 1047 | ModuleTypeUnderTest: "override_apex", |
| 1048 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1049 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1050 | "system/sepolicy/apex/Android.bp": ` |
| 1051 | filegroup { |
| 1052 | name: "com.android.apogee-file_contexts", |
| 1053 | srcs: [ "apogee-file_contexts", ], |
| 1054 | bazel_module: { bp2build_available: false }, |
| 1055 | }`, |
| 1056 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1057 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1058 | prebuilt_etc { |
| 1059 | name: "prebuilt_file", |
| 1060 | bazel_module: { bp2build_available: false }, |
| 1061 | } |
| 1062 | |
| 1063 | prebuilt_etc { |
| 1064 | name: "prebuilt_file2", |
| 1065 | bazel_module: { bp2build_available: false }, |
| 1066 | } |
| 1067 | |
| 1068 | apex { |
| 1069 | name: "com.android.apogee", |
| 1070 | bazel_module: { bp2build_available: false }, |
| 1071 | prebuilts: ["prebuilt_file"] |
| 1072 | } |
| 1073 | |
| 1074 | override_apex { |
| 1075 | name: "com.google.android.apogee", |
| 1076 | base: ":com.android.apogee", |
| 1077 | prebuilts: ["prebuilt_file2"] |
| 1078 | } |
| 1079 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1080 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1081 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1082 | "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 Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1086 | }), |
| 1087 | }}) |
| 1088 | } |
| 1089 | |
| 1090 | func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1091 | 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 Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1096 | "system/sepolicy/apex/Android.bp": ` |
| 1097 | filegroup { |
| 1098 | name: "com.android.apogee-file_contexts", |
| 1099 | srcs: [ "apogee-file_contexts", ], |
| 1100 | bazel_module: { bp2build_available: false }, |
| 1101 | }`, |
| 1102 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1103 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1104 | prebuilt_etc { |
| 1105 | name: "prebuilt_file", |
| 1106 | bazel_module: { bp2build_available: false }, |
| 1107 | } |
| 1108 | |
| 1109 | apex { |
| 1110 | name: "com.android.apogee", |
| 1111 | bazel_module: { bp2build_available: false }, |
| 1112 | prebuilts: ["prebuilt_file"] |
| 1113 | } |
| 1114 | |
| 1115 | override_apex { |
| 1116 | name: "com.google.android.apogee", |
| 1117 | base: ":com.android.apogee", |
| 1118 | prebuilts: [], |
| 1119 | } |
| 1120 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1121 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1122 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1123 | "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 Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1127 | }), |
| 1128 | }}) |
| 1129 | } |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1130 | |
| 1131 | func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1132 | 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 Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1137 | "system/sepolicy/apex/Android.bp": ` |
| 1138 | filegroup { |
| 1139 | name: "com.android.apogee-file_contexts", |
| 1140 | srcs: [ "apogee-file_contexts", ], |
| 1141 | bazel_module: { bp2build_available: false }, |
| 1142 | }`, |
| 1143 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1144 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1145 | apex { |
| 1146 | name: "com.android.apogee", |
| 1147 | bazel_module: { bp2build_available: false }, |
| 1148 | logging_parent: "foo.bar.baz", |
| 1149 | } |
| 1150 | |
| 1151 | override_apex { |
| 1152 | name: "com.google.android.apogee", |
| 1153 | base: ":com.android.apogee", |
| 1154 | } |
| 1155 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1156 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1157 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1158 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1159 | "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 | |
| 1166 | func TestApexBundleSimple_LoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1167 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1168 | Description: "override_apex - logging_parent - override", |
| 1169 | ModuleTypeUnderTest: "override_apex", |
| 1170 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1171 | Filesystem: map[string]string{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1172 | "system/sepolicy/apex/Android.bp": ` |
| 1173 | filegroup { |
| 1174 | name: "com.android.apogee-file_contexts", |
| 1175 | srcs: [ "apogee-file_contexts", ], |
| 1176 | bazel_module: { bp2build_available: false }, |
| 1177 | }`, |
| 1178 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1179 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1180 | apex { |
| 1181 | name: "com.android.apogee", |
| 1182 | bazel_module: { bp2build_available: false }, |
| 1183 | logging_parent: "foo.bar.baz", |
| 1184 | } |
| 1185 | |
| 1186 | override_apex { |
| 1187 | name: "com.google.android.apogee", |
| 1188 | base: ":com.android.apogee", |
| 1189 | logging_parent: "foo.bar.baz.override", |
| 1190 | } |
| 1191 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1192 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1193 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1194 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1195 | "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 Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1201 | |
| 1202 | func 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: ` |
| 1209 | android_app_certificate { |
| 1210 | name: "com.android.apogee.certificate", |
| 1211 | certificate: "com.android.apogee", |
| 1212 | bazel_module: { bp2build_available: false }, |
| 1213 | } |
| 1214 | |
| 1215 | filegroup { |
| 1216 | name: "com.android.apogee-file_contexts", |
| 1217 | srcs: [ |
| 1218 | "com.android.apogee-file_contexts", |
| 1219 | ], |
| 1220 | bazel_module: { bp2build_available: false }, |
| 1221 | } |
| 1222 | |
| 1223 | apex { |
| 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 | |
| 1231 | override_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 Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1240 | "base_apex_name": `"com.android.apogee"`, |
| 1241 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1242 | "manifest": `"apogee_manifest.json"`, |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1243 | }), |
| 1244 | }}) |
| 1245 | } |
| 1246 | |
| 1247 | func 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: ` |
| 1254 | android_app_certificate { |
| 1255 | name: "com.android.apogee.certificate", |
| 1256 | certificate: "com.android.apogee", |
| 1257 | bazel_module: { bp2build_available: false }, |
| 1258 | } |
| 1259 | |
| 1260 | apex { |
| 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 Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 1266 | ` + SimpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1267 | 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 Tran | 55225e3 | 2022-12-20 10:38:48 -0500 | [diff] [blame] | 1276 | func 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: ` |
| 1283 | cc_library{ |
| 1284 | name: "foo", |
| 1285 | stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] }, |
| 1286 | apex_available: ["myapex"], |
| 1287 | } |
| 1288 | |
| 1289 | cc_binary{ |
| 1290 | name: "bar", |
| 1291 | static_libs: ["foo"], |
| 1292 | apex_available: ["myapex"], |
| 1293 | } |
| 1294 | |
| 1295 | apex { |
| 1296 | name: "myapex", |
| 1297 | manifest: "myapex_manifest.json", |
| 1298 | file_contexts: ":myapex-file_contexts", |
| 1299 | binaries: ["bar"], |
| 1300 | native_shared_libs: ["foo"], |
| 1301 | } |
Sam Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 1302 | ` + SimpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"), |
Vinh Tran | 55225e3 | 2022-12-20 10:38:48 -0500 | [diff] [blame] | 1303 | 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 Das | 04f9f4c | 2023-09-13 23:59:05 +0000 | [diff] [blame^] | 1318 | "api_surface": `"module-libapi"`, |
Sam Delmerico | 5f90649 | 2023-03-15 18:06:18 -0400 | [diff] [blame] | 1319 | "soname": `"foo.so"`, |
| 1320 | "source_library_label": `"//:foo"`, |
| 1321 | "symbol_file": `"foo.map.txt"`, |
Vinh Tran | 55225e3 | 2022-12-20 10:38:48 -0500 | [diff] [blame] | 1322 | "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 Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1347 | func 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: ` |
| 1354 | apex { |
| 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 Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 1360 | ` + SimpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1361 | 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 | |
| 1370 | func 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: ` |
| 1377 | android_app_certificate { |
| 1378 | name: "com.android.apogee.certificate", |
| 1379 | certificate: "com.android.apogee", |
| 1380 | bazel_module: { bp2build_available: false }, |
| 1381 | } |
| 1382 | |
| 1383 | filegroup { |
| 1384 | name: "com.android.apogee-file_contexts", |
| 1385 | srcs: [ |
| 1386 | "com.android.apogee-file_contexts", |
| 1387 | ], |
| 1388 | bazel_module: { bp2build_available: false }, |
| 1389 | } |
| 1390 | |
| 1391 | apex { |
| 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 | |
| 1399 | android_app_certificate { |
| 1400 | name: "com.google.android.apogee.certificate", |
| 1401 | certificate: "com.google.android.apogee", |
| 1402 | bazel_module: { bp2build_available: false }, |
| 1403 | } |
| 1404 | |
| 1405 | override_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 Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1413 | "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 Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1417 | }), |
| 1418 | }}) |
| 1419 | } |
| 1420 | |
| 1421 | func 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: ` |
| 1428 | android_app_certificate { |
| 1429 | name: "com.android.apogee.certificate", |
| 1430 | certificate: "com.android.apogee", |
| 1431 | bazel_module: { bp2build_available: false }, |
| 1432 | } |
| 1433 | |
| 1434 | filegroup { |
| 1435 | name: "com.android.apogee-file_contexts", |
| 1436 | srcs: [ |
| 1437 | "com.android.apogee-file_contexts", |
| 1438 | ], |
| 1439 | bazel_module: { bp2build_available: false }, |
| 1440 | } |
| 1441 | |
| 1442 | apex { |
| 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 | |
| 1450 | override_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 Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1458 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1459 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1460 | "certificate_name": `"com.google.android.apogee.certificate"`, |
| 1461 | "manifest": `"apogee_manifest.json"`, |
| 1462 | }), |
| 1463 | }}) |
| 1464 | } |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 1465 | |
| 1466 | func 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: ` |
| 1473 | cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } } |
| 1474 | |
| 1475 | apex_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 Das | a43ae13 | 2023-05-08 18:33:16 +0000 | [diff] [blame] | 1483 | "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 Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 1488 | }), |
| 1489 | }}) |
| 1490 | } |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 1491 | |
| 1492 | func 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: ` |
| 1501 | soong_config_string_variable { |
| 1502 | name: "library_linking_strategy", |
| 1503 | values: [ |
| 1504 | "prefer_static", |
| 1505 | ], |
| 1506 | } |
| 1507 | |
| 1508 | soong_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 | |
| 1519 | library_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 | |
| 1533 | filegroup { |
| 1534 | name: "foo-file_contexts", |
| 1535 | srcs: [ |
| 1536 | "com.android.apogee-file_contexts", |
| 1537 | ], |
| 1538 | bazel_module: { bp2build_available: false }, |
| 1539 | } |
| 1540 | |
| 1541 | apex { |
| 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 | } |
| 1548 | override_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 Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 1559 | "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30", |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 1560 | "//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 Faust | 87c0c33 | 2023-07-31 12:10:12 -0700 | [diff] [blame] | 1568 | "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30", |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 1569 | "//conditions:default": "31", |
| 1570 | })`, |
| 1571 | "package_name": `"override_pkg_name"`, |
| 1572 | }), |
| 1573 | }}) |
| 1574 | } |
Jingwen Chen | a8623da | 2023-03-28 13:05:02 +0000 | [diff] [blame] | 1575 | |
| 1576 | func 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: ` |
| 1583 | apex { |
| 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 | } |