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"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 201 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 202 | }), |
| 203 | }}) |
| 204 | } |
| 205 | |
| 206 | func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { |
| 207 | runApexTestCase(t, bp2buildTestCase{ |
| 208 | description: "apex - file contexts is a file", |
| 209 | moduleTypeUnderTest: "apex", |
| 210 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 211 | filesystem: map[string]string{}, |
| 212 | blueprint: ` |
| 213 | apex { |
| 214 | name: "com.android.apogee", |
| 215 | file_contexts: "file_contexts_file", |
| 216 | } |
| 217 | `, |
| 218 | expectedBazelTargets: []string{ |
| 219 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 220 | "file_contexts": `"file_contexts_file"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 221 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 222 | }), |
| 223 | }}) |
| 224 | } |
| 225 | |
| 226 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
| 227 | runApexTestCase(t, bp2buildTestCase{ |
| 228 | description: "apex - file contexts is not specified", |
| 229 | moduleTypeUnderTest: "apex", |
| 230 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 231 | filesystem: map[string]string{ |
| 232 | "system/sepolicy/apex/Android.bp": ` |
| 233 | filegroup { |
| 234 | name: "com.android.apogee-file_contexts", |
| 235 | srcs: [ |
| 236 | "com.android.apogee-file_contexts", |
| 237 | ], |
| 238 | bazel_module: { bp2build_available: false }, |
| 239 | } |
| 240 | `, |
| 241 | }, |
| 242 | blueprint: ` |
| 243 | apex { |
| 244 | name: "com.android.apogee", |
| 245 | } |
| 246 | `, |
| 247 | expectedBazelTargets: []string{ |
| 248 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 249 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 250 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 251 | }), |
| 252 | }}) |
| 253 | } |
| 254 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 255 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
| 256 | runApexTestCase(t, bp2buildTestCase{ |
| 257 | description: "apex - example with compile_multilib=both", |
| 258 | moduleTypeUnderTest: "apex", |
| 259 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 260 | filesystem: map[string]string{ |
| 261 | "system/sepolicy/apex/Android.bp": ` |
| 262 | filegroup { |
| 263 | name: "com.android.apogee-file_contexts", |
| 264 | srcs: [ "apogee-file_contexts", ], |
| 265 | bazel_module: { bp2build_available: false }, |
| 266 | } |
| 267 | `, |
| 268 | }, |
| 269 | blueprint: createMultilibBlueprint("both"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 270 | expectedBazelTargets: []string{ |
| 271 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 272 | "native_shared_libs_32": `[ |
| 273 | ":native_shared_lib_1", |
| 274 | ":native_shared_lib_3", |
| 275 | ] + select({ |
| 276 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 277 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 278 | "//conditions:default": [], |
| 279 | })`, |
| 280 | "native_shared_libs_64": `select({ |
| 281 | "//build/bazel/platforms/arch:arm64": [ |
| 282 | ":native_shared_lib_1", |
| 283 | ":native_shared_lib_4", |
| 284 | ":native_shared_lib_2", |
| 285 | ], |
| 286 | "//build/bazel/platforms/arch:x86_64": [ |
| 287 | ":native_shared_lib_1", |
| 288 | ":native_shared_lib_4", |
| 289 | ":native_shared_lib_2", |
| 290 | ], |
| 291 | "//conditions:default": [], |
| 292 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 293 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 294 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 295 | }), |
| 296 | }}) |
| 297 | } |
| 298 | |
| 299 | func TestApexBundleCompileMultilibFirst(t *testing.T) { |
| 300 | runApexTestCase(t, bp2buildTestCase{ |
| 301 | description: "apex - example with compile_multilib=first", |
| 302 | moduleTypeUnderTest: "apex", |
| 303 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 304 | filesystem: map[string]string{ |
| 305 | "system/sepolicy/apex/Android.bp": ` |
| 306 | filegroup { |
| 307 | name: "com.android.apogee-file_contexts", |
| 308 | srcs: [ "apogee-file_contexts", ], |
| 309 | bazel_module: { bp2build_available: false }, |
| 310 | } |
| 311 | `, |
| 312 | }, |
| 313 | blueprint: createMultilibBlueprint("first"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 314 | expectedBazelTargets: []string{ |
| 315 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 316 | "native_shared_libs_32": `select({ |
| 317 | "//build/bazel/platforms/arch:arm": [ |
| 318 | ":native_shared_lib_1", |
| 319 | ":native_shared_lib_3", |
| 320 | ":native_shared_lib_2", |
| 321 | ], |
| 322 | "//build/bazel/platforms/arch:x86": [ |
| 323 | ":native_shared_lib_1", |
| 324 | ":native_shared_lib_3", |
| 325 | ":native_shared_lib_2", |
| 326 | ], |
| 327 | "//conditions:default": [], |
| 328 | })`, |
| 329 | "native_shared_libs_64": `select({ |
| 330 | "//build/bazel/platforms/arch:arm64": [ |
| 331 | ":native_shared_lib_1", |
| 332 | ":native_shared_lib_4", |
| 333 | ":native_shared_lib_2", |
| 334 | ], |
| 335 | "//build/bazel/platforms/arch:x86_64": [ |
| 336 | ":native_shared_lib_1", |
| 337 | ":native_shared_lib_4", |
| 338 | ":native_shared_lib_2", |
| 339 | ], |
| 340 | "//conditions:default": [], |
| 341 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 342 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 343 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 344 | }), |
| 345 | }}) |
| 346 | } |
| 347 | |
| 348 | func TestApexBundleCompileMultilib32(t *testing.T) { |
| 349 | runApexTestCase(t, bp2buildTestCase{ |
| 350 | description: "apex - example with compile_multilib=32", |
| 351 | moduleTypeUnderTest: "apex", |
| 352 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 353 | filesystem: map[string]string{ |
| 354 | "system/sepolicy/apex/Android.bp": ` |
| 355 | filegroup { |
| 356 | name: "com.android.apogee-file_contexts", |
| 357 | srcs: [ "apogee-file_contexts", ], |
| 358 | bazel_module: { bp2build_available: false }, |
| 359 | } |
| 360 | `, |
| 361 | }, |
| 362 | blueprint: createMultilibBlueprint("32"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 363 | expectedBazelTargets: []string{ |
| 364 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 365 | "native_shared_libs_32": `[ |
| 366 | ":native_shared_lib_1", |
| 367 | ":native_shared_lib_3", |
| 368 | ] + select({ |
| 369 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"], |
| 370 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"], |
| 371 | "//conditions:default": [], |
| 372 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 373 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 374 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 375 | }), |
| 376 | }}) |
| 377 | } |
| 378 | |
| 379 | func TestApexBundleCompileMultilib64(t *testing.T) { |
| 380 | runApexTestCase(t, bp2buildTestCase{ |
| 381 | description: "apex - example with compile_multilib=64", |
| 382 | moduleTypeUnderTest: "apex", |
| 383 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 384 | filesystem: map[string]string{ |
| 385 | "system/sepolicy/apex/Android.bp": ` |
| 386 | filegroup { |
| 387 | name: "com.android.apogee-file_contexts", |
| 388 | srcs: [ "apogee-file_contexts", ], |
| 389 | bazel_module: { bp2build_available: false }, |
| 390 | } |
| 391 | `, |
| 392 | }, |
| 393 | blueprint: createMultilibBlueprint("64"), |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 394 | expectedBazelTargets: []string{ |
| 395 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 396 | "native_shared_libs_64": `select({ |
| 397 | "//build/bazel/platforms/arch:arm64": [ |
| 398 | ":native_shared_lib_1", |
| 399 | ":native_shared_lib_4", |
| 400 | ":native_shared_lib_2", |
| 401 | ], |
| 402 | "//build/bazel/platforms/arch:x86_64": [ |
| 403 | ":native_shared_lib_1", |
| 404 | ":native_shared_lib_4", |
| 405 | ":native_shared_lib_2", |
| 406 | ], |
| 407 | "//conditions:default": [], |
| 408 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 409 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 410 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 411 | }), |
| 412 | }}) |
| 413 | } |
| 414 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 415 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
| 416 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 417 | description: "apex - default property values", |
| 418 | moduleTypeUnderTest: "apex", |
| 419 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 420 | filesystem: map[string]string{ |
| 421 | "system/sepolicy/apex/Android.bp": ` |
| 422 | filegroup { |
| 423 | name: "com.android.apogee-file_contexts", |
| 424 | srcs: [ "apogee-file_contexts", ], |
| 425 | bazel_module: { bp2build_available: false }, |
| 426 | } |
| 427 | `, |
| 428 | }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 429 | blueprint: ` |
| 430 | apex { |
| 431 | name: "com.android.apogee", |
| 432 | manifest: "apogee_manifest.json", |
| 433 | } |
| 434 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 435 | expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 436 | "manifest": `"apogee_manifest.json"`, |
| 437 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 438 | }), |
| 439 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 440 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 441 | |
| 442 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
| 443 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 444 | description: "apex - has bazel module props", |
| 445 | moduleTypeUnderTest: "apex", |
| 446 | moduleTypeUnderTestFactory: apex.BundleFactory, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 447 | filesystem: map[string]string{ |
| 448 | "system/sepolicy/apex/Android.bp": ` |
| 449 | filegroup { |
| 450 | name: "apogee-file_contexts", |
| 451 | srcs: [ "apogee-file_contexts", ], |
| 452 | bazel_module: { bp2build_available: false }, |
| 453 | } |
| 454 | `, |
| 455 | }, |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 456 | blueprint: ` |
| 457 | apex { |
| 458 | name: "apogee", |
| 459 | manifest: "manifest.json", |
| 460 | bazel_module: { bp2build_available: true }, |
| 461 | } |
| 462 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 463 | expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 464 | "manifest": `"manifest.json"`, |
| 465 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 466 | }), |
| 467 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 468 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 469 | |
| 470 | func createMultilibBlueprint(compile_multilib string) string { |
| 471 | return ` |
| 472 | cc_library { |
| 473 | name: "native_shared_lib_1", |
| 474 | bazel_module: { bp2build_available: false }, |
| 475 | } |
| 476 | |
| 477 | cc_library { |
| 478 | name: "native_shared_lib_2", |
| 479 | bazel_module: { bp2build_available: false }, |
| 480 | } |
| 481 | |
| 482 | cc_library { |
| 483 | name: "native_shared_lib_3", |
| 484 | bazel_module: { bp2build_available: false }, |
| 485 | } |
| 486 | |
| 487 | cc_library { |
| 488 | name: "native_shared_lib_4", |
| 489 | bazel_module: { bp2build_available: false }, |
| 490 | } |
| 491 | |
| 492 | apex { |
| 493 | name: "com.android.apogee", |
| 494 | compile_multilib: "` + compile_multilib + `", |
| 495 | multilib: { |
| 496 | both: { |
| 497 | native_shared_libs: [ |
| 498 | "native_shared_lib_1", |
| 499 | ], |
| 500 | }, |
| 501 | first: { |
| 502 | native_shared_libs: [ |
| 503 | "native_shared_lib_2", |
| 504 | ], |
| 505 | }, |
| 506 | lib32: { |
| 507 | native_shared_libs: [ |
| 508 | "native_shared_lib_3", |
| 509 | ], |
| 510 | }, |
| 511 | lib64: { |
| 512 | native_shared_libs: [ |
| 513 | "native_shared_lib_4", |
| 514 | ], |
| 515 | }, |
| 516 | }, |
| 517 | }` |
| 518 | } |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 519 | |
| 520 | func TestBp2BuildOverrideApex(t *testing.T) { |
| 521 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 522 | description: "override_apex", |
| 523 | moduleTypeUnderTest: "override_apex", |
| 524 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 525 | filesystem: map[string]string{}, |
| 526 | blueprint: ` |
| 527 | apex_key { |
| 528 | name: "com.android.apogee.key", |
| 529 | public_key: "com.android.apogee.avbpubkey", |
| 530 | private_key: "com.android.apogee.pem", |
| 531 | bazel_module: { bp2build_available: false }, |
| 532 | } |
| 533 | |
| 534 | android_app_certificate { |
| 535 | name: "com.android.apogee.certificate", |
| 536 | certificate: "com.android.apogee", |
| 537 | bazel_module: { bp2build_available: false }, |
| 538 | } |
| 539 | |
| 540 | cc_library { |
| 541 | name: "native_shared_lib_1", |
| 542 | bazel_module: { bp2build_available: false }, |
| 543 | } |
| 544 | |
| 545 | cc_library { |
| 546 | name: "native_shared_lib_2", |
| 547 | bazel_module: { bp2build_available: false }, |
| 548 | } |
| 549 | |
| 550 | cc_library { |
| 551 | name: "pretend_prebuilt_1", |
| 552 | bazel_module: { bp2build_available: false }, |
| 553 | } |
| 554 | |
| 555 | cc_library { |
| 556 | name: "pretend_prebuilt_2", |
| 557 | bazel_module: { bp2build_available: false }, |
| 558 | } |
| 559 | |
| 560 | filegroup { |
| 561 | name: "com.android.apogee-file_contexts", |
| 562 | srcs: [ |
| 563 | "com.android.apogee-file_contexts", |
| 564 | ], |
| 565 | bazel_module: { bp2build_available: false }, |
| 566 | } |
| 567 | |
| 568 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 569 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 570 | |
| 571 | apex { |
| 572 | name: "com.android.apogee", |
| 573 | manifest: "apogee_manifest.json", |
| 574 | androidManifest: "ApogeeAndroidManifest.xml", |
| 575 | file_contexts: ":com.android.apogee-file_contexts", |
| 576 | min_sdk_version: "29", |
| 577 | key: "com.android.apogee.key", |
| 578 | certificate: "com.android.apogee.certificate", |
| 579 | updatable: false, |
| 580 | installable: false, |
| 581 | compressible: false, |
| 582 | native_shared_libs: [ |
| 583 | "native_shared_lib_1", |
| 584 | "native_shared_lib_2", |
| 585 | ], |
| 586 | binaries: [ |
| 587 | "cc_binary_1", |
| 588 | "sh_binary_2", |
| 589 | ], |
| 590 | prebuilts: [ |
| 591 | "pretend_prebuilt_1", |
| 592 | "pretend_prebuilt_2", |
| 593 | ], |
| 594 | bazel_module: { bp2build_available: false }, |
| 595 | } |
| 596 | |
| 597 | apex_key { |
| 598 | name: "com.google.android.apogee.key", |
| 599 | public_key: "com.google.android.apogee.avbpubkey", |
| 600 | private_key: "com.google.android.apogee.pem", |
| 601 | bazel_module: { bp2build_available: false }, |
| 602 | } |
| 603 | |
| 604 | android_app_certificate { |
| 605 | name: "com.google.android.apogee.certificate", |
| 606 | certificate: "com.google.android.apogee", |
| 607 | bazel_module: { bp2build_available: false }, |
| 608 | } |
| 609 | |
| 610 | override_apex { |
| 611 | name: "com.google.android.apogee", |
| 612 | base: ":com.android.apogee", |
| 613 | key: "com.google.android.apogee.key", |
| 614 | certificate: "com.google.android.apogee.certificate", |
| 615 | prebuilts: [], |
| 616 | compressible: true, |
| 617 | } |
| 618 | `, |
| 619 | expectedBazelTargets: []string{ |
| 620 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 621 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 622 | "binaries": `[ |
| 623 | ":cc_binary_1", |
| 624 | ":sh_binary_2", |
| 625 | ]`, |
| 626 | "certificate": `":com.google.android.apogee.certificate"`, |
| 627 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 628 | "installable": "False", |
| 629 | "key": `":com.google.android.apogee.key"`, |
| 630 | "manifest": `"apogee_manifest.json"`, |
| 631 | "min_sdk_version": `"29"`, |
| 632 | "native_shared_libs_32": `[ |
| 633 | ":native_shared_lib_1", |
| 634 | ":native_shared_lib_2", |
| 635 | ]`, |
| 636 | "native_shared_libs_64": `select({ |
| 637 | "//build/bazel/platforms/arch:arm64": [ |
| 638 | ":native_shared_lib_1", |
| 639 | ":native_shared_lib_2", |
| 640 | ], |
| 641 | "//build/bazel/platforms/arch:x86_64": [ |
| 642 | ":native_shared_lib_1", |
| 643 | ":native_shared_lib_2", |
| 644 | ], |
| 645 | "//conditions:default": [], |
| 646 | })`, |
| 647 | "prebuilts": `[]`, |
| 648 | "updatable": "False", |
| 649 | "compressible": "True", |
| 650 | }), |
| 651 | }}) |
| 652 | } |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame^] | 653 | |
| 654 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
| 655 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 656 | description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", |
| 657 | moduleTypeUnderTest: "override_apex", |
| 658 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 659 | filesystem: map[string]string{ |
| 660 | "system/sepolicy/apex/Android.bp": ` |
| 661 | filegroup { |
| 662 | name: "com.android.apogee-file_contexts", |
| 663 | srcs: [ "apogee-file_contexts", ], |
| 664 | bazel_module: { bp2build_available: false }, |
| 665 | }`, |
| 666 | "a/b/Android.bp": ` |
| 667 | apex { |
| 668 | name: "com.android.apogee", |
| 669 | bazel_module: { bp2build_available: false }, |
| 670 | } |
| 671 | `, |
| 672 | }, |
| 673 | blueprint: ` |
| 674 | override_apex { |
| 675 | name: "com.google.android.apogee", |
| 676 | base: ":com.android.apogee", |
| 677 | } |
| 678 | `, |
| 679 | expectedBazelTargets: []string{ |
| 680 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 681 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 682 | "manifest": `"//a/b:apex_manifest.json"`, |
| 683 | }), |
| 684 | }}) |
| 685 | } |
| 686 | |
| 687 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
| 688 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 689 | description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", |
| 690 | moduleTypeUnderTest: "override_apex", |
| 691 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 692 | filesystem: map[string]string{ |
| 693 | "system/sepolicy/apex/Android.bp": ` |
| 694 | filegroup { |
| 695 | name: "com.android.apogee-file_contexts", |
| 696 | srcs: [ "apogee-file_contexts", ], |
| 697 | bazel_module: { bp2build_available: false }, |
| 698 | }`, |
| 699 | "a/b/Android.bp": ` |
| 700 | apex { |
| 701 | name: "com.android.apogee", |
| 702 | manifest: "apogee_manifest.json", |
| 703 | bazel_module: { bp2build_available: false }, |
| 704 | } |
| 705 | `, |
| 706 | }, |
| 707 | blueprint: ` |
| 708 | override_apex { |
| 709 | name: "com.google.android.apogee", |
| 710 | base: ":com.android.apogee", |
| 711 | } |
| 712 | `, |
| 713 | expectedBazelTargets: []string{ |
| 714 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 715 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 716 | "manifest": `"//a/b:apogee_manifest.json"`, |
| 717 | }), |
| 718 | }}) |
| 719 | } |
| 720 | |
| 721 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
| 722 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 723 | description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", |
| 724 | moduleTypeUnderTest: "override_apex", |
| 725 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 726 | filesystem: map[string]string{ |
| 727 | "system/sepolicy/apex/Android.bp": ` |
| 728 | filegroup { |
| 729 | name: "com.android.apogee-file_contexts", |
| 730 | srcs: [ "apogee-file_contexts", ], |
| 731 | bazel_module: { bp2build_available: false }, |
| 732 | }`, |
| 733 | }, |
| 734 | blueprint: ` |
| 735 | apex { |
| 736 | name: "com.android.apogee", |
| 737 | bazel_module: { bp2build_available: false }, |
| 738 | } |
| 739 | |
| 740 | override_apex { |
| 741 | name: "com.google.android.apogee", |
| 742 | base: ":com.android.apogee", |
| 743 | } |
| 744 | `, |
| 745 | expectedBazelTargets: []string{ |
| 746 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 747 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 748 | "manifest": `"apex_manifest.json"`, |
| 749 | }), |
| 750 | }}) |
| 751 | } |
| 752 | |
| 753 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
| 754 | runOverrideApexTestCase(t, bp2buildTestCase{ |
| 755 | description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", |
| 756 | moduleTypeUnderTest: "override_apex", |
| 757 | moduleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 758 | filesystem: map[string]string{ |
| 759 | "system/sepolicy/apex/Android.bp": ` |
| 760 | filegroup { |
| 761 | name: "com.android.apogee-file_contexts", |
| 762 | srcs: [ "apogee-file_contexts", ], |
| 763 | bazel_module: { bp2build_available: false }, |
| 764 | }`, |
| 765 | }, |
| 766 | blueprint: ` |
| 767 | apex { |
| 768 | name: "com.android.apogee", |
| 769 | manifest: "apogee_manifest.json", |
| 770 | bazel_module: { bp2build_available: false }, |
| 771 | } |
| 772 | |
| 773 | override_apex { |
| 774 | name: "com.google.android.apogee", |
| 775 | base: ":com.android.apogee", |
| 776 | } |
| 777 | `, |
| 778 | expectedBazelTargets: []string{ |
| 779 | makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ |
| 780 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 781 | "manifest": `"apogee_manifest.json"`, |
| 782 | }), |
| 783 | }}) |
| 784 | } |