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 | ], |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 136 | } |
| 137 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 138 | expectedBazelTargets: []string{ |
| 139 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 140 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 141 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 142 | ":cc_binary_1", |
| 143 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 144 | ]`, |
| 145 | "certificate": `":com.android.apogee.certificate"`, |
| 146 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 147 | "installable": "False", |
| 148 | "key": `":com.android.apogee.key"`, |
| 149 | "manifest": `"apogee_manifest.json"`, |
| 150 | "min_sdk_version": `"29"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 151 | "native_shared_libs_32": `[ |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 152 | ":native_shared_lib_1", |
| 153 | ":native_shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 154 | ]`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 155 | "native_shared_libs_64": `select({ |
| 156 | "//build/bazel/platforms/arch:arm64": [ |
| 157 | ":native_shared_lib_1", |
| 158 | ":native_shared_lib_2", |
| 159 | ], |
| 160 | "//build/bazel/platforms/arch:x86_64": [ |
| 161 | ":native_shared_lib_1", |
| 162 | ":native_shared_lib_2", |
| 163 | ], |
| 164 | "//conditions:default": [], |
| 165 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 166 | "prebuilts": `[ |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 167 | ":pretend_prebuilt_1", |
| 168 | ":pretend_prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 169 | ]`, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 170 | "updatable": "False", |
| 171 | "compressible": "False", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 172 | }), |
| 173 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 174 | } |
| 175 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 176 | func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { |
| 177 | runApexTestCase(t, bp2buildTestCase{ |
| 178 | description: "apex - file contexts is a module in another Android.bp", |
| 179 | moduleTypeUnderTest: "apex", |
| 180 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 181 | filesystem: map[string]string{ |
| 182 | "a/b/Android.bp": ` |
| 183 | filegroup { |
| 184 | name: "com.android.apogee-file_contexts", |
| 185 | srcs: [ |
| 186 | "com.android.apogee-file_contexts", |
| 187 | ], |
| 188 | bazel_module: { bp2build_available: false }, |
| 189 | } |
| 190 | `, |
| 191 | }, |
| 192 | blueprint: ` |
| 193 | apex { |
| 194 | name: "com.android.apogee", |
| 195 | file_contexts: ":com.android.apogee-file_contexts", |
| 196 | } |
| 197 | `, |
| 198 | expectedBazelTargets: []string{ |
| 199 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 200 | "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, |
| 201 | }), |
| 202 | }}) |
| 203 | } |
| 204 | |
| 205 | func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { |
| 206 | runApexTestCase(t, bp2buildTestCase{ |
| 207 | description: "apex - file contexts is a file", |
| 208 | moduleTypeUnderTest: "apex", |
| 209 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 210 | filesystem: map[string]string{}, |
| 211 | blueprint: ` |
| 212 | apex { |
| 213 | name: "com.android.apogee", |
| 214 | file_contexts: "file_contexts_file", |
| 215 | } |
| 216 | `, |
| 217 | expectedBazelTargets: []string{ |
| 218 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 219 | "file_contexts": `"file_contexts_file"`, |
| 220 | }), |
| 221 | }}) |
| 222 | } |
| 223 | |
| 224 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
| 225 | runApexTestCase(t, bp2buildTestCase{ |
| 226 | description: "apex - file contexts is not specified", |
| 227 | moduleTypeUnderTest: "apex", |
| 228 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 229 | filesystem: map[string]string{ |
| 230 | "system/sepolicy/apex/Android.bp": ` |
| 231 | filegroup { |
| 232 | name: "com.android.apogee-file_contexts", |
| 233 | srcs: [ |
| 234 | "com.android.apogee-file_contexts", |
| 235 | ], |
| 236 | bazel_module: { bp2build_available: false }, |
| 237 | } |
| 238 | `, |
| 239 | }, |
| 240 | blueprint: ` |
| 241 | apex { |
| 242 | name: "com.android.apogee", |
| 243 | } |
| 244 | `, |
| 245 | expectedBazelTargets: []string{ |
| 246 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 247 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 248 | }), |
| 249 | }}) |
| 250 | } |
| 251 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 252 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
| 253 | runApexTestCase(t, bp2buildTestCase{ |
| 254 | description: "apex - example with compile_multilib=both", |
| 255 | moduleTypeUnderTest: "apex", |
| 256 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 257 | filesystem: map[string]string{ |
| 258 | "system/sepolicy/apex/Android.bp": ` |
| 259 | filegroup { |
| 260 | name: "com.android.apogee-file_contexts", |
| 261 | srcs: [ "apogee-file_contexts", ], |
| 262 | bazel_module: { bp2build_available: false }, |
| 263 | } |
| 264 | `, |
| 265 | }, |
| 266 | blueprint: createMultilibBlueprint("both"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 267 | expectedBazelTargets: []string{ |
| 268 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 269 | "native_shared_libs_32": `[ |
| 270 | ":native_shared_lib_1", |
| 271 | ":native_shared_lib_3", |
| 272 | ] + select({ |
| 273 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 274 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 275 | "//conditions:default": [], |
| 276 | })`, |
| 277 | "native_shared_libs_64": `select({ |
| 278 | "//build/bazel/platforms/arch:arm64": [ |
| 279 | ":native_shared_lib_1", |
| 280 | ":native_shared_lib_4", |
| 281 | ":native_shared_lib_2", |
| 282 | ], |
| 283 | "//build/bazel/platforms/arch:x86_64": [ |
| 284 | ":native_shared_lib_1", |
| 285 | ":native_shared_lib_4", |
| 286 | ":native_shared_lib_2", |
| 287 | ], |
| 288 | "//conditions:default": [], |
| 289 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 290 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 291 | }), |
| 292 | }}) |
| 293 | } |
| 294 | |
| 295 | func TestApexBundleCompileMultilibFirst(t *testing.T) { |
| 296 | runApexTestCase(t, bp2buildTestCase{ |
| 297 | description: "apex - example with compile_multilib=first", |
| 298 | moduleTypeUnderTest: "apex", |
| 299 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 300 | filesystem: map[string]string{ |
| 301 | "system/sepolicy/apex/Android.bp": ` |
| 302 | filegroup { |
| 303 | name: "com.android.apogee-file_contexts", |
| 304 | srcs: [ "apogee-file_contexts", ], |
| 305 | bazel_module: { bp2build_available: false }, |
| 306 | } |
| 307 | `, |
| 308 | }, |
| 309 | blueprint: createMultilibBlueprint("first"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 310 | expectedBazelTargets: []string{ |
| 311 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 312 | "native_shared_libs_32": `select({ |
| 313 | "//build/bazel/platforms/arch:arm": [ |
| 314 | ":native_shared_lib_1", |
| 315 | ":native_shared_lib_3", |
| 316 | ":native_shared_lib_2", |
| 317 | ], |
| 318 | "//build/bazel/platforms/arch:x86": [ |
| 319 | ":native_shared_lib_1", |
| 320 | ":native_shared_lib_3", |
| 321 | ":native_shared_lib_2", |
| 322 | ], |
| 323 | "//conditions:default": [], |
| 324 | })`, |
| 325 | "native_shared_libs_64": `select({ |
| 326 | "//build/bazel/platforms/arch:arm64": [ |
| 327 | ":native_shared_lib_1", |
| 328 | ":native_shared_lib_4", |
| 329 | ":native_shared_lib_2", |
| 330 | ], |
| 331 | "//build/bazel/platforms/arch:x86_64": [ |
| 332 | ":native_shared_lib_1", |
| 333 | ":native_shared_lib_4", |
| 334 | ":native_shared_lib_2", |
| 335 | ], |
| 336 | "//conditions:default": [], |
| 337 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 338 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 339 | }), |
| 340 | }}) |
| 341 | } |
| 342 | |
| 343 | func TestApexBundleCompileMultilib32(t *testing.T) { |
| 344 | runApexTestCase(t, bp2buildTestCase{ |
| 345 | description: "apex - example with compile_multilib=32", |
| 346 | moduleTypeUnderTest: "apex", |
| 347 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 348 | filesystem: map[string]string{ |
| 349 | "system/sepolicy/apex/Android.bp": ` |
| 350 | filegroup { |
| 351 | name: "com.android.apogee-file_contexts", |
| 352 | srcs: [ "apogee-file_contexts", ], |
| 353 | bazel_module: { bp2build_available: false }, |
| 354 | } |
| 355 | `, |
| 356 | }, |
| 357 | blueprint: createMultilibBlueprint("32"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 358 | expectedBazelTargets: []string{ |
| 359 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 360 | "native_shared_libs_32": `[ |
| 361 | ":native_shared_lib_1", |
| 362 | ":native_shared_lib_3", |
| 363 | ] + select({ |
| 364 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 365 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 366 | "//conditions:default": [], |
| 367 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 368 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 369 | }), |
| 370 | }}) |
| 371 | } |
| 372 | |
| 373 | func TestApexBundleCompileMultilib64(t *testing.T) { |
| 374 | runApexTestCase(t, bp2buildTestCase{ |
| 375 | description: "apex - example with compile_multilib=64", |
| 376 | moduleTypeUnderTest: "apex", |
| 377 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 378 | filesystem: map[string]string{ |
| 379 | "system/sepolicy/apex/Android.bp": ` |
| 380 | filegroup { |
| 381 | name: "com.android.apogee-file_contexts", |
| 382 | srcs: [ "apogee-file_contexts", ], |
| 383 | bazel_module: { bp2build_available: false }, |
| 384 | } |
| 385 | `, |
| 386 | }, |
| 387 | blueprint: createMultilibBlueprint("64"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 388 | expectedBazelTargets: []string{ |
| 389 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 390 | "native_shared_libs_64": `select({ |
| 391 | "//build/bazel/platforms/arch:arm64": [ |
| 392 | ":native_shared_lib_1", |
| 393 | ":native_shared_lib_4", |
| 394 | ":native_shared_lib_2", |
| 395 | ], |
| 396 | "//build/bazel/platforms/arch:x86_64": [ |
| 397 | ":native_shared_lib_1", |
| 398 | ":native_shared_lib_4", |
| 399 | ":native_shared_lib_2", |
| 400 | ], |
| 401 | "//conditions:default": [], |
| 402 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 403 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 404 | }), |
| 405 | }}) |
| 406 | } |
| 407 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 408 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
| 409 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 410 | description: "apex - default property values", |
| 411 | moduleTypeUnderTest: "apex", |
| 412 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 413 | filesystem: map[string]string{ |
| 414 | "system/sepolicy/apex/Android.bp": ` |
| 415 | filegroup { |
| 416 | name: "com.android.apogee-file_contexts", |
| 417 | srcs: [ "apogee-file_contexts", ], |
| 418 | bazel_module: { bp2build_available: false }, |
| 419 | } |
| 420 | `, |
| 421 | }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 422 | blueprint: ` |
| 423 | apex { |
| 424 | name: "com.android.apogee", |
| 425 | manifest: "apogee_manifest.json", |
| 426 | } |
| 427 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 428 | expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 429 | "manifest": `"apogee_manifest.json"`, |
| 430 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 431 | }), |
| 432 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 433 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 434 | |
| 435 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
| 436 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 437 | description: "apex - has bazel module props", |
| 438 | moduleTypeUnderTest: "apex", |
| 439 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 440 | filesystem: map[string]string{ |
| 441 | "system/sepolicy/apex/Android.bp": ` |
| 442 | filegroup { |
| 443 | name: "apogee-file_contexts", |
| 444 | srcs: [ "apogee-file_contexts", ], |
| 445 | bazel_module: { bp2build_available: false }, |
| 446 | } |
| 447 | `, |
| 448 | }, |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 449 | blueprint: ` |
| 450 | apex { |
| 451 | name: "apogee", |
| 452 | manifest: "manifest.json", |
| 453 | bazel_module: { bp2build_available: true }, |
| 454 | } |
| 455 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 456 | expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 457 | "manifest": `"manifest.json"`, |
| 458 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 459 | }), |
| 460 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 461 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 462 | |
| 463 | func createMultilibBlueprint(compile_multilib string) string { |
| 464 | return ` |
| 465 | cc_library { |
| 466 | name: "native_shared_lib_1", |
| 467 | bazel_module: { bp2build_available: false }, |
| 468 | } |
| 469 | |
| 470 | cc_library { |
| 471 | name: "native_shared_lib_2", |
| 472 | bazel_module: { bp2build_available: false }, |
| 473 | } |
| 474 | |
| 475 | cc_library { |
| 476 | name: "native_shared_lib_3", |
| 477 | bazel_module: { bp2build_available: false }, |
| 478 | } |
| 479 | |
| 480 | cc_library { |
| 481 | name: "native_shared_lib_4", |
| 482 | bazel_module: { bp2build_available: false }, |
| 483 | } |
| 484 | |
| 485 | apex { |
| 486 | name: "com.android.apogee", |
| 487 | compile_multilib: "` + compile_multilib + `", |
| 488 | multilib: { |
| 489 | both: { |
| 490 | native_shared_libs: [ |
| 491 | "native_shared_lib_1", |
| 492 | ], |
| 493 | }, |
| 494 | first: { |
| 495 | native_shared_libs: [ |
| 496 | "native_shared_lib_2", |
| 497 | ], |
| 498 | }, |
| 499 | lib32: { |
| 500 | native_shared_libs: [ |
| 501 | "native_shared_lib_3", |
| 502 | ], |
| 503 | }, |
| 504 | lib64: { |
| 505 | native_shared_libs: [ |
| 506 | "native_shared_lib_4", |
| 507 | ], |
| 508 | }, |
| 509 | }, |
| 510 | }` |
| 511 | } |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame^] | 512 | |
| 513 | func TestBp2BuildOverrideApex(t *testing.T) { |
| 514 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 515 | description: "override_apex", |
| 516 | moduleTypeUnderTest: "override_apex", |
| 517 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 518 | filesystem: map[string]string{}, |
| 519 | blueprint: ` |
| 520 | apex_key { |
| 521 | name: "com.android.apogee.key", |
| 522 | public_key: "com.android.apogee.avbpubkey", |
| 523 | private_key: "com.android.apogee.pem", |
| 524 | bazel_module: { bp2build_available: false }, |
| 525 | } |
| 526 | |
| 527 | android_app_certificate { |
| 528 | name: "com.android.apogee.certificate", |
| 529 | certificate: "com.android.apogee", |
| 530 | bazel_module: { bp2build_available: false }, |
| 531 | } |
| 532 | |
| 533 | cc_library { |
| 534 | name: "native_shared_lib_1", |
| 535 | bazel_module: { bp2build_available: false }, |
| 536 | } |
| 537 | |
| 538 | cc_library { |
| 539 | name: "native_shared_lib_2", |
| 540 | bazel_module: { bp2build_available: false }, |
| 541 | } |
| 542 | |
| 543 | cc_library { |
| 544 | name: "pretend_prebuilt_1", |
| 545 | bazel_module: { bp2build_available: false }, |
| 546 | } |
| 547 | |
| 548 | cc_library { |
| 549 | name: "pretend_prebuilt_2", |
| 550 | bazel_module: { bp2build_available: false }, |
| 551 | } |
| 552 | |
| 553 | filegroup { |
| 554 | name: "com.android.apogee-file_contexts", |
| 555 | srcs: [ |
| 556 | "com.android.apogee-file_contexts", |
| 557 | ], |
| 558 | bazel_module: { bp2build_available: false }, |
| 559 | } |
| 560 | |
| 561 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 562 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 563 | |
| 564 | apex { |
| 565 | name: "com.android.apogee", |
| 566 | manifest: "apogee_manifest.json", |
| 567 | androidManifest: "ApogeeAndroidManifest.xml", |
| 568 | file_contexts: ":com.android.apogee-file_contexts", |
| 569 | min_sdk_version: "29", |
| 570 | key: "com.android.apogee.key", |
| 571 | certificate: "com.android.apogee.certificate", |
| 572 | updatable: false, |
| 573 | installable: false, |
| 574 | compressible: false, |
| 575 | native_shared_libs: [ |
| 576 | "native_shared_lib_1", |
| 577 | "native_shared_lib_2", |
| 578 | ], |
| 579 | binaries: [ |
| 580 | "cc_binary_1", |
| 581 | "sh_binary_2", |
| 582 | ], |
| 583 | prebuilts: [ |
| 584 | "pretend_prebuilt_1", |
| 585 | "pretend_prebuilt_2", |
| 586 | ], |
| 587 | bazel_module: { bp2build_available: false }, |
| 588 | } |
| 589 | |
| 590 | apex_key { |
| 591 | name: "com.google.android.apogee.key", |
| 592 | public_key: "com.google.android.apogee.avbpubkey", |
| 593 | private_key: "com.google.android.apogee.pem", |
| 594 | bazel_module: { bp2build_available: false }, |
| 595 | } |
| 596 | |
| 597 | android_app_certificate { |
| 598 | name: "com.google.android.apogee.certificate", |
| 599 | certificate: "com.google.android.apogee", |
| 600 | bazel_module: { bp2build_available: false }, |
| 601 | } |
| 602 | |
| 603 | override_apex { |
| 604 | name: "com.google.android.apogee", |
| 605 | base: ":com.android.apogee", |
| 606 | key: "com.google.android.apogee.key", |
| 607 | certificate: "com.google.android.apogee.certificate", |
| 608 | prebuilts: [], |
| 609 | compressible: true, |
| 610 | } |
| 611 | `, |
| 612 | expectedBazelTargets: []string{ |
| 613 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 614 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 615 | "binaries": `[ |
| 616 | ":cc_binary_1", |
| 617 | ":sh_binary_2", |
| 618 | ]`, |
| 619 | "certificate": `":com.google.android.apogee.certificate"`, |
| 620 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 621 | "installable": "False", |
| 622 | "key": `":com.google.android.apogee.key"`, |
| 623 | "manifest": `"apogee_manifest.json"`, |
| 624 | "min_sdk_version": `"29"`, |
| 625 | "native_shared_libs_32": `[ |
| 626 | ":native_shared_lib_1", |
| 627 | ":native_shared_lib_2", |
| 628 | ]`, |
| 629 | "native_shared_libs_64": `select({ |
| 630 | "//build/bazel/platforms/arch:arm64": [ |
| 631 | ":native_shared_lib_1", |
| 632 | ":native_shared_lib_2", |
| 633 | ], |
| 634 | "//build/bazel/platforms/arch:x86_64": [ |
| 635 | ":native_shared_lib_1", |
| 636 | ":native_shared_lib_2", |
| 637 | ], |
| 638 | "//conditions:default": [], |
| 639 | })`, |
| 640 | "prebuilts": `[]`, |
| 641 | "updatable": "False", |
| 642 | "compressible": "True", |
| 643 | }), |
| 644 | }}) |
| 645 | } |