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" |
| 21 | "android/soong/java" |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 22 | "android/soong/sh" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 23 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 24 | "testing" |
| 25 | ) |
| 26 | |
| 27 | func runApexTestCase(t *testing.T, tc bp2buildTestCase) { |
| 28 | t.Helper() |
| 29 | runBp2BuildTestCase(t, registerApexModuleTypes, tc) |
| 30 | } |
| 31 | |
| 32 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 33 | // CC module types needed as they can be APEX dependencies |
| 34 | cc.RegisterCCBuildComponents(ctx) |
| 35 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 36 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 37 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 38 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 39 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 40 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 41 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 44 | func runOverrideApexTestCase(t *testing.T, tc bp2buildTestCase) { |
| 45 | t.Helper() |
| 46 | runBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) |
| 47 | } |
| 48 | |
| 49 | func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { |
| 50 | // CC module types needed as they can be APEX dependencies |
| 51 | cc.RegisterCCBuildComponents(ctx) |
| 52 | |
| 53 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 54 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
| 55 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 56 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 57 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 58 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 59 | ctx.RegisterModuleType("apex", apex.BundleFactory) |
| 60 | } |
| 61 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 62 | func TestApexBundleSimple(t *testing.T) { |
| 63 | runApexTestCase(t, bp2buildTestCase{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 64 | description: "apex - example with all props, file_context is a module in same Android.bp", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 65 | moduleTypeUnderTest: "apex", |
| 66 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 67 | filesystem: map[string]string{}, |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 68 | blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 69 | apex_key { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 70 | name: "com.android.apogee.key", |
| 71 | public_key: "com.android.apogee.avbpubkey", |
| 72 | private_key: "com.android.apogee.pem", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 73 | bazel_module: { bp2build_available: false }, |
| 74 | } |
| 75 | |
| 76 | android_app_certificate { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 77 | name: "com.android.apogee.certificate", |
| 78 | certificate: "com.android.apogee", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 79 | bazel_module: { bp2build_available: false }, |
| 80 | } |
| 81 | |
| 82 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 83 | name: "native_shared_lib_1", |
| 84 | bazel_module: { bp2build_available: false }, |
| 85 | } |
| 86 | |
| 87 | cc_library { |
| 88 | name: "native_shared_lib_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 89 | bazel_module: { bp2build_available: false }, |
| 90 | } |
| 91 | |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 92 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 93 | name: "pretend_prebuilt_1", |
| 94 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 97 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 98 | name: "pretend_prebuilt_2", |
| 99 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 102 | filegroup { |
| 103 | name: "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 104 | srcs: [ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 105 | "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 106 | ], |
| 107 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 110 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 111 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 112 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 113 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 114 | name: "com.android.apogee", |
| 115 | manifest: "apogee_manifest.json", |
| 116 | androidManifest: "ApogeeAndroidManifest.xml", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 117 | file_contexts: ":com.android.apogee-file_contexts", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 118 | min_sdk_version: "29", |
| 119 | key: "com.android.apogee.key", |
| 120 | certificate: "com.android.apogee.certificate", |
| 121 | updatable: false, |
| 122 | installable: false, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 123 | compressible: false, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 124 | native_shared_libs: [ |
| 125 | "native_shared_lib_1", |
| 126 | "native_shared_lib_2", |
| 127 | ], |
| 128 | binaries: [ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 129 | "cc_binary_1", |
| 130 | "sh_binary_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 131 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 132 | prebuilts: [ |
| 133 | "pretend_prebuilt_1", |
| 134 | "pretend_prebuilt_2", |
| 135 | ], |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 136 | package_name: "com.android.apogee.test.package", |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 137 | } |
| 138 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 139 | expectedBazelTargets: []string{ |
| 140 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 141 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 142 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 143 | ":cc_binary_1", |
| 144 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 145 | ]`, |
| 146 | "certificate": `":com.android.apogee.certificate"`, |
| 147 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 148 | "installable": "False", |
| 149 | "key": `":com.android.apogee.key"`, |
| 150 | "manifest": `"apogee_manifest.json"`, |
| 151 | "min_sdk_version": `"29"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 152 | "native_shared_libs_32": `[ |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 153 | ":native_shared_lib_1", |
| 154 | ":native_shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 155 | ]`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 156 | "native_shared_libs_64": `select({ |
| 157 | "//build/bazel/platforms/arch:arm64": [ |
| 158 | ":native_shared_lib_1", |
| 159 | ":native_shared_lib_2", |
| 160 | ], |
| 161 | "//build/bazel/platforms/arch:x86_64": [ |
| 162 | ":native_shared_lib_1", |
| 163 | ":native_shared_lib_2", |
| 164 | ], |
| 165 | "//conditions:default": [], |
| 166 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 167 | "prebuilts": `[ |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 168 | ":pretend_prebuilt_1", |
| 169 | ":pretend_prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 170 | ]`, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 171 | "updatable": "False", |
| 172 | "compressible": "False", |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 173 | "package_name": `"com.android.apogee.test.package"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 174 | }), |
| 175 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 178 | func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { |
| 179 | runApexTestCase(t, bp2buildTestCase{ |
| 180 | description: "apex - file contexts is a module in another Android.bp", |
| 181 | moduleTypeUnderTest: "apex", |
| 182 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 183 | filesystem: map[string]string{ |
| 184 | "a/b/Android.bp": ` |
| 185 | filegroup { |
| 186 | name: "com.android.apogee-file_contexts", |
| 187 | srcs: [ |
| 188 | "com.android.apogee-file_contexts", |
| 189 | ], |
| 190 | bazel_module: { bp2build_available: false }, |
| 191 | } |
| 192 | `, |
| 193 | }, |
| 194 | blueprint: ` |
| 195 | apex { |
| 196 | name: "com.android.apogee", |
| 197 | file_contexts: ":com.android.apogee-file_contexts", |
| 198 | } |
| 199 | `, |
| 200 | expectedBazelTargets: []string{ |
| 201 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 202 | "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 203 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 204 | }), |
| 205 | }}) |
| 206 | } |
| 207 | |
| 208 | func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { |
| 209 | runApexTestCase(t, bp2buildTestCase{ |
| 210 | description: "apex - file contexts is a file", |
| 211 | moduleTypeUnderTest: "apex", |
| 212 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 213 | filesystem: map[string]string{}, |
| 214 | blueprint: ` |
| 215 | apex { |
| 216 | name: "com.android.apogee", |
| 217 | file_contexts: "file_contexts_file", |
| 218 | } |
| 219 | `, |
| 220 | expectedBazelTargets: []string{ |
| 221 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 222 | "file_contexts": `"file_contexts_file"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 223 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 224 | }), |
| 225 | }}) |
| 226 | } |
| 227 | |
| 228 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
| 229 | runApexTestCase(t, bp2buildTestCase{ |
| 230 | description: "apex - file contexts is not specified", |
| 231 | moduleTypeUnderTest: "apex", |
| 232 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 233 | filesystem: map[string]string{ |
| 234 | "system/sepolicy/apex/Android.bp": ` |
| 235 | filegroup { |
| 236 | name: "com.android.apogee-file_contexts", |
| 237 | srcs: [ |
| 238 | "com.android.apogee-file_contexts", |
| 239 | ], |
| 240 | bazel_module: { bp2build_available: false }, |
| 241 | } |
| 242 | `, |
| 243 | }, |
| 244 | blueprint: ` |
| 245 | apex { |
| 246 | name: "com.android.apogee", |
| 247 | } |
| 248 | `, |
| 249 | expectedBazelTargets: []string{ |
| 250 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 251 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 252 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 253 | }), |
| 254 | }}) |
| 255 | } |
| 256 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 257 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
| 258 | runApexTestCase(t, bp2buildTestCase{ |
| 259 | description: "apex - example with compile_multilib=both", |
| 260 | moduleTypeUnderTest: "apex", |
| 261 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 262 | filesystem: map[string]string{ |
| 263 | "system/sepolicy/apex/Android.bp": ` |
| 264 | filegroup { |
| 265 | name: "com.android.apogee-file_contexts", |
| 266 | srcs: [ "apogee-file_contexts", ], |
| 267 | bazel_module: { bp2build_available: false }, |
| 268 | } |
| 269 | `, |
| 270 | }, |
| 271 | blueprint: createMultilibBlueprint("both"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 272 | expectedBazelTargets: []string{ |
| 273 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 274 | "native_shared_libs_32": `[ |
| 275 | ":native_shared_lib_1", |
| 276 | ":native_shared_lib_3", |
| 277 | ] + select({ |
| 278 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 279 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 280 | "//conditions:default": [], |
| 281 | })`, |
| 282 | "native_shared_libs_64": `select({ |
| 283 | "//build/bazel/platforms/arch:arm64": [ |
| 284 | ":native_shared_lib_1", |
| 285 | ":native_shared_lib_4", |
| 286 | ":native_shared_lib_2", |
| 287 | ], |
| 288 | "//build/bazel/platforms/arch:x86_64": [ |
| 289 | ":native_shared_lib_1", |
| 290 | ":native_shared_lib_4", |
| 291 | ":native_shared_lib_2", |
| 292 | ], |
| 293 | "//conditions:default": [], |
| 294 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 295 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 296 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 297 | }), |
| 298 | }}) |
| 299 | } |
| 300 | |
| 301 | func TestApexBundleCompileMultilibFirst(t *testing.T) { |
| 302 | runApexTestCase(t, bp2buildTestCase{ |
| 303 | description: "apex - example with compile_multilib=first", |
| 304 | moduleTypeUnderTest: "apex", |
| 305 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 306 | filesystem: map[string]string{ |
| 307 | "system/sepolicy/apex/Android.bp": ` |
| 308 | filegroup { |
| 309 | name: "com.android.apogee-file_contexts", |
| 310 | srcs: [ "apogee-file_contexts", ], |
| 311 | bazel_module: { bp2build_available: false }, |
| 312 | } |
| 313 | `, |
| 314 | }, |
| 315 | blueprint: createMultilibBlueprint("first"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 316 | expectedBazelTargets: []string{ |
| 317 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 318 | "native_shared_libs_32": `select({ |
| 319 | "//build/bazel/platforms/arch:arm": [ |
| 320 | ":native_shared_lib_1", |
| 321 | ":native_shared_lib_3", |
| 322 | ":native_shared_lib_2", |
| 323 | ], |
| 324 | "//build/bazel/platforms/arch:x86": [ |
| 325 | ":native_shared_lib_1", |
| 326 | ":native_shared_lib_3", |
| 327 | ":native_shared_lib_2", |
| 328 | ], |
| 329 | "//conditions:default": [], |
| 330 | })`, |
| 331 | "native_shared_libs_64": `select({ |
| 332 | "//build/bazel/platforms/arch:arm64": [ |
| 333 | ":native_shared_lib_1", |
| 334 | ":native_shared_lib_4", |
| 335 | ":native_shared_lib_2", |
| 336 | ], |
| 337 | "//build/bazel/platforms/arch:x86_64": [ |
| 338 | ":native_shared_lib_1", |
| 339 | ":native_shared_lib_4", |
| 340 | ":native_shared_lib_2", |
| 341 | ], |
| 342 | "//conditions:default": [], |
| 343 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 344 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 345 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 346 | }), |
| 347 | }}) |
| 348 | } |
| 349 | |
| 350 | func TestApexBundleCompileMultilib32(t *testing.T) { |
| 351 | runApexTestCase(t, bp2buildTestCase{ |
| 352 | description: "apex - example with compile_multilib=32", |
| 353 | moduleTypeUnderTest: "apex", |
| 354 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 355 | filesystem: map[string]string{ |
| 356 | "system/sepolicy/apex/Android.bp": ` |
| 357 | filegroup { |
| 358 | name: "com.android.apogee-file_contexts", |
| 359 | srcs: [ "apogee-file_contexts", ], |
| 360 | bazel_module: { bp2build_available: false }, |
| 361 | } |
| 362 | `, |
| 363 | }, |
| 364 | blueprint: createMultilibBlueprint("32"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 365 | expectedBazelTargets: []string{ |
| 366 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 367 | "native_shared_libs_32": `[ |
| 368 | ":native_shared_lib_1", |
| 369 | ":native_shared_lib_3", |
| 370 | ] + select({ |
| 371 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 372 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 373 | "//conditions:default": [], |
| 374 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 375 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 376 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 377 | }), |
| 378 | }}) |
| 379 | } |
| 380 | |
| 381 | func TestApexBundleCompileMultilib64(t *testing.T) { |
| 382 | runApexTestCase(t, bp2buildTestCase{ |
| 383 | description: "apex - example with compile_multilib=64", |
| 384 | moduleTypeUnderTest: "apex", |
| 385 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 386 | filesystem: map[string]string{ |
| 387 | "system/sepolicy/apex/Android.bp": ` |
| 388 | filegroup { |
| 389 | name: "com.android.apogee-file_contexts", |
| 390 | srcs: [ "apogee-file_contexts", ], |
| 391 | bazel_module: { bp2build_available: false }, |
| 392 | } |
| 393 | `, |
| 394 | }, |
| 395 | blueprint: createMultilibBlueprint("64"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 396 | expectedBazelTargets: []string{ |
| 397 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 398 | "native_shared_libs_64": `select({ |
| 399 | "//build/bazel/platforms/arch:arm64": [ |
| 400 | ":native_shared_lib_1", |
| 401 | ":native_shared_lib_4", |
| 402 | ":native_shared_lib_2", |
| 403 | ], |
| 404 | "//build/bazel/platforms/arch:x86_64": [ |
| 405 | ":native_shared_lib_1", |
| 406 | ":native_shared_lib_4", |
| 407 | ":native_shared_lib_2", |
| 408 | ], |
| 409 | "//conditions:default": [], |
| 410 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 411 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 412 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 413 | }), |
| 414 | }}) |
| 415 | } |
| 416 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 417 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
| 418 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 419 | description: "apex - default property values", |
| 420 | moduleTypeUnderTest: "apex", |
| 421 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 422 | filesystem: map[string]string{ |
| 423 | "system/sepolicy/apex/Android.bp": ` |
| 424 | filegroup { |
| 425 | name: "com.android.apogee-file_contexts", |
| 426 | srcs: [ "apogee-file_contexts", ], |
| 427 | bazel_module: { bp2build_available: false }, |
| 428 | } |
| 429 | `, |
| 430 | }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 431 | blueprint: ` |
| 432 | apex { |
| 433 | name: "com.android.apogee", |
| 434 | manifest: "apogee_manifest.json", |
| 435 | } |
| 436 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 437 | expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 438 | "manifest": `"apogee_manifest.json"`, |
| 439 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 440 | }), |
| 441 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 442 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 443 | |
| 444 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
| 445 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 446 | description: "apex - has bazel module props", |
| 447 | moduleTypeUnderTest: "apex", |
| 448 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 449 | filesystem: map[string]string{ |
| 450 | "system/sepolicy/apex/Android.bp": ` |
| 451 | filegroup { |
| 452 | name: "apogee-file_contexts", |
| 453 | srcs: [ "apogee-file_contexts", ], |
| 454 | bazel_module: { bp2build_available: false }, |
| 455 | } |
| 456 | `, |
| 457 | }, |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 458 | blueprint: ` |
| 459 | apex { |
| 460 | name: "apogee", |
| 461 | manifest: "manifest.json", |
| 462 | bazel_module: { bp2build_available: true }, |
| 463 | } |
| 464 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 465 | expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 466 | "manifest": `"manifest.json"`, |
| 467 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 468 | }), |
| 469 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 470 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 471 | |
| 472 | func createMultilibBlueprint(compile_multilib string) string { |
| 473 | return ` |
| 474 | cc_library { |
| 475 | name: "native_shared_lib_1", |
| 476 | bazel_module: { bp2build_available: false }, |
| 477 | } |
| 478 | |
| 479 | cc_library { |
| 480 | name: "native_shared_lib_2", |
| 481 | bazel_module: { bp2build_available: false }, |
| 482 | } |
| 483 | |
| 484 | cc_library { |
| 485 | name: "native_shared_lib_3", |
| 486 | bazel_module: { bp2build_available: false }, |
| 487 | } |
| 488 | |
| 489 | cc_library { |
| 490 | name: "native_shared_lib_4", |
| 491 | bazel_module: { bp2build_available: false }, |
| 492 | } |
| 493 | |
| 494 | apex { |
| 495 | name: "com.android.apogee", |
| 496 | compile_multilib: "` + compile_multilib + `", |
| 497 | multilib: { |
| 498 | both: { |
| 499 | native_shared_libs: [ |
| 500 | "native_shared_lib_1", |
| 501 | ], |
| 502 | }, |
| 503 | first: { |
| 504 | native_shared_libs: [ |
| 505 | "native_shared_lib_2", |
| 506 | ], |
| 507 | }, |
| 508 | lib32: { |
| 509 | native_shared_libs: [ |
| 510 | "native_shared_lib_3", |
| 511 | ], |
| 512 | }, |
| 513 | lib64: { |
| 514 | native_shared_libs: [ |
| 515 | "native_shared_lib_4", |
| 516 | ], |
| 517 | }, |
| 518 | }, |
| 519 | }` |
| 520 | } |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 521 | |
| 522 | func TestBp2BuildOverrideApex(t *testing.T) { |
| 523 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 524 | description: "override_apex", |
| 525 | moduleTypeUnderTest: "override_apex", |
| 526 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 527 | filesystem: map[string]string{}, |
| 528 | blueprint: ` |
| 529 | apex_key { |
| 530 | name: "com.android.apogee.key", |
| 531 | public_key: "com.android.apogee.avbpubkey", |
| 532 | private_key: "com.android.apogee.pem", |
| 533 | bazel_module: { bp2build_available: false }, |
| 534 | } |
| 535 | |
| 536 | android_app_certificate { |
| 537 | name: "com.android.apogee.certificate", |
| 538 | certificate: "com.android.apogee", |
| 539 | bazel_module: { bp2build_available: false }, |
| 540 | } |
| 541 | |
| 542 | cc_library { |
| 543 | name: "native_shared_lib_1", |
| 544 | bazel_module: { bp2build_available: false }, |
| 545 | } |
| 546 | |
| 547 | cc_library { |
| 548 | name: "native_shared_lib_2", |
| 549 | bazel_module: { bp2build_available: false }, |
| 550 | } |
| 551 | |
| 552 | cc_library { |
| 553 | name: "pretend_prebuilt_1", |
| 554 | bazel_module: { bp2build_available: false }, |
| 555 | } |
| 556 | |
| 557 | cc_library { |
| 558 | name: "pretend_prebuilt_2", |
| 559 | bazel_module: { bp2build_available: false }, |
| 560 | } |
| 561 | |
| 562 | filegroup { |
| 563 | name: "com.android.apogee-file_contexts", |
| 564 | srcs: [ |
| 565 | "com.android.apogee-file_contexts", |
| 566 | ], |
| 567 | bazel_module: { bp2build_available: false }, |
| 568 | } |
| 569 | |
| 570 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 571 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 572 | |
| 573 | apex { |
| 574 | name: "com.android.apogee", |
| 575 | manifest: "apogee_manifest.json", |
| 576 | androidManifest: "ApogeeAndroidManifest.xml", |
| 577 | file_contexts: ":com.android.apogee-file_contexts", |
| 578 | min_sdk_version: "29", |
| 579 | key: "com.android.apogee.key", |
| 580 | certificate: "com.android.apogee.certificate", |
| 581 | updatable: false, |
| 582 | installable: false, |
| 583 | compressible: false, |
| 584 | native_shared_libs: [ |
| 585 | "native_shared_lib_1", |
| 586 | "native_shared_lib_2", |
| 587 | ], |
| 588 | binaries: [ |
| 589 | "cc_binary_1", |
| 590 | "sh_binary_2", |
| 591 | ], |
| 592 | prebuilts: [ |
| 593 | "pretend_prebuilt_1", |
| 594 | "pretend_prebuilt_2", |
| 595 | ], |
| 596 | bazel_module: { bp2build_available: false }, |
| 597 | } |
| 598 | |
| 599 | apex_key { |
| 600 | name: "com.google.android.apogee.key", |
| 601 | public_key: "com.google.android.apogee.avbpubkey", |
| 602 | private_key: "com.google.android.apogee.pem", |
| 603 | bazel_module: { bp2build_available: false }, |
| 604 | } |
| 605 | |
| 606 | android_app_certificate { |
| 607 | name: "com.google.android.apogee.certificate", |
| 608 | certificate: "com.google.android.apogee", |
| 609 | bazel_module: { bp2build_available: false }, |
| 610 | } |
| 611 | |
| 612 | override_apex { |
| 613 | name: "com.google.android.apogee", |
| 614 | base: ":com.android.apogee", |
| 615 | key: "com.google.android.apogee.key", |
| 616 | certificate: "com.google.android.apogee.certificate", |
| 617 | prebuilts: [], |
| 618 | compressible: true, |
| 619 | } |
| 620 | `, |
| 621 | expectedBazelTargets: []string{ |
| 622 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 623 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 624 | "binaries": `[ |
| 625 | ":cc_binary_1", |
| 626 | ":sh_binary_2", |
| 627 | ]`, |
| 628 | "certificate": `":com.google.android.apogee.certificate"`, |
| 629 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 630 | "installable": "False", |
| 631 | "key": `":com.google.android.apogee.key"`, |
| 632 | "manifest": `"apogee_manifest.json"`, |
| 633 | "min_sdk_version": `"29"`, |
| 634 | "native_shared_libs_32": `[ |
| 635 | ":native_shared_lib_1", |
| 636 | ":native_shared_lib_2", |
| 637 | ]`, |
| 638 | "native_shared_libs_64": `select({ |
| 639 | "//build/bazel/platforms/arch:arm64": [ |
| 640 | ":native_shared_lib_1", |
| 641 | ":native_shared_lib_2", |
| 642 | ], |
| 643 | "//build/bazel/platforms/arch:x86_64": [ |
| 644 | ":native_shared_lib_1", |
| 645 | ":native_shared_lib_2", |
| 646 | ], |
| 647 | "//conditions:default": [], |
| 648 | })`, |
| 649 | "prebuilts": `[]`, |
| 650 | "updatable": "False", |
| 651 | "compressible": "True", |
| 652 | }), |
| 653 | }}) |
| 654 | } |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 655 | |
| 656 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
| 657 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 658 | description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", |
| 659 | moduleTypeUnderTest: "override_apex", |
| 660 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 661 | filesystem: map[string]string{ |
| 662 | "system/sepolicy/apex/Android.bp": ` |
| 663 | filegroup { |
| 664 | name: "com.android.apogee-file_contexts", |
| 665 | srcs: [ "apogee-file_contexts", ], |
| 666 | bazel_module: { bp2build_available: false }, |
| 667 | }`, |
| 668 | "a/b/Android.bp": ` |
| 669 | apex { |
| 670 | name: "com.android.apogee", |
| 671 | bazel_module: { bp2build_available: false }, |
| 672 | } |
| 673 | `, |
| 674 | }, |
| 675 | blueprint: ` |
| 676 | override_apex { |
| 677 | name: "com.google.android.apogee", |
| 678 | base: ":com.android.apogee", |
| 679 | } |
| 680 | `, |
| 681 | expectedBazelTargets: []string{ |
| 682 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 683 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 684 | "manifest": `"//a/b:apex_manifest.json"`, |
| 685 | }), |
| 686 | }}) |
| 687 | } |
| 688 | |
| 689 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
| 690 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 691 | description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", |
| 692 | moduleTypeUnderTest: "override_apex", |
| 693 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 694 | filesystem: map[string]string{ |
| 695 | "system/sepolicy/apex/Android.bp": ` |
| 696 | filegroup { |
| 697 | name: "com.android.apogee-file_contexts", |
| 698 | srcs: [ "apogee-file_contexts", ], |
| 699 | bazel_module: { bp2build_available: false }, |
| 700 | }`, |
| 701 | "a/b/Android.bp": ` |
| 702 | apex { |
| 703 | name: "com.android.apogee", |
| 704 | manifest: "apogee_manifest.json", |
| 705 | bazel_module: { bp2build_available: false }, |
| 706 | } |
| 707 | `, |
| 708 | }, |
| 709 | blueprint: ` |
| 710 | override_apex { |
| 711 | name: "com.google.android.apogee", |
| 712 | base: ":com.android.apogee", |
| 713 | } |
| 714 | `, |
| 715 | expectedBazelTargets: []string{ |
| 716 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 717 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 718 | "manifest": `"//a/b:apogee_manifest.json"`, |
| 719 | }), |
| 720 | }}) |
| 721 | } |
| 722 | |
| 723 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
| 724 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 725 | description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", |
| 726 | moduleTypeUnderTest: "override_apex", |
| 727 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 728 | filesystem: map[string]string{ |
| 729 | "system/sepolicy/apex/Android.bp": ` |
| 730 | filegroup { |
| 731 | name: "com.android.apogee-file_contexts", |
| 732 | srcs: [ "apogee-file_contexts", ], |
| 733 | bazel_module: { bp2build_available: false }, |
| 734 | }`, |
| 735 | }, |
| 736 | blueprint: ` |
| 737 | apex { |
| 738 | name: "com.android.apogee", |
| 739 | bazel_module: { bp2build_available: false }, |
| 740 | } |
| 741 | |
| 742 | override_apex { |
| 743 | name: "com.google.android.apogee", |
| 744 | base: ":com.android.apogee", |
| 745 | } |
| 746 | `, |
| 747 | expectedBazelTargets: []string{ |
| 748 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 749 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 750 | "manifest": `"apex_manifest.json"`, |
| 751 | }), |
| 752 | }}) |
| 753 | } |
| 754 | |
| 755 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
| 756 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 757 | description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", |
| 758 | moduleTypeUnderTest: "override_apex", |
| 759 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 760 | filesystem: map[string]string{ |
| 761 | "system/sepolicy/apex/Android.bp": ` |
| 762 | filegroup { |
| 763 | name: "com.android.apogee-file_contexts", |
| 764 | srcs: [ "apogee-file_contexts", ], |
| 765 | bazel_module: { bp2build_available: false }, |
| 766 | }`, |
| 767 | }, |
| 768 | blueprint: ` |
| 769 | apex { |
| 770 | name: "com.android.apogee", |
| 771 | manifest: "apogee_manifest.json", |
| 772 | bazel_module: { bp2build_available: false }, |
| 773 | } |
| 774 | |
| 775 | override_apex { |
| 776 | name: "com.google.android.apogee", |
| 777 | base: ":com.android.apogee", |
| 778 | } |
| 779 | `, |
| 780 | expectedBazelTargets: []string{ |
| 781 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 782 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 783 | "manifest": `"apogee_manifest.json"`, |
| 784 | }), |
| 785 | }}) |
| 786 | } |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 787 | |
| 788 | func TestApexBundleSimple_packageNameOverride(t *testing.T) { |
| 789 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 790 | description: "override_apex - override package name", |
| 791 | moduleTypeUnderTest: "override_apex", |
| 792 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 793 | filesystem: map[string]string{ |
| 794 | "system/sepolicy/apex/Android.bp": ` |
| 795 | filegroup { |
| 796 | name: "com.android.apogee-file_contexts", |
| 797 | srcs: [ "apogee-file_contexts", ], |
| 798 | bazel_module: { bp2build_available: false }, |
| 799 | }`, |
| 800 | }, |
| 801 | blueprint: ` |
| 802 | apex { |
| 803 | name: "com.android.apogee", |
| 804 | bazel_module: { bp2build_available: false }, |
| 805 | } |
| 806 | |
| 807 | override_apex { |
| 808 | name: "com.google.android.apogee", |
| 809 | base: ":com.android.apogee", |
| 810 | package_name: "com.google.android.apogee", |
| 811 | } |
| 812 | `, |
| 813 | expectedBazelTargets: []string{ |
| 814 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 815 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 816 | "manifest": `"apex_manifest.json"`, |
| 817 | "package_name": `"com.google.android.apogee"`, |
| 818 | }), |
| 819 | }}) |
| 820 | } |