Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/apex" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 20 | "android/soong/cc" |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 21 | "android/soong/etc" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 22 | "android/soong/java" |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 23 | "android/soong/sh" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 24 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 25 | "fmt" |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 26 | "testing" |
| 27 | ) |
| 28 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 29 | func runApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 30 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 31 | RunBp2BuildTestCase(t, registerApexModuleTypes, tc) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 35 | // CC module types needed as they can be APEX dependencies |
| 36 | cc.RegisterCCBuildComponents(ctx) |
| 37 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 38 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 39 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 40 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 41 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 42 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 43 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 44 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame^] | 45 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 48 | func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 49 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 50 | RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { |
| 54 | // CC module types needed as they can be APEX dependencies |
| 55 | cc.RegisterCCBuildComponents(ctx) |
| 56 | |
| 57 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 58 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
| 59 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 60 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 61 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 62 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 63 | ctx.RegisterModuleType("apex", apex.BundleFactory) |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 64 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 67 | func TestApexBundleSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 68 | runApexTestCase(t, Bp2buildTestCase{ |
| 69 | Description: "apex - example with all props, file_context is a module in same Android.bp", |
| 70 | ModuleTypeUnderTest: "apex", |
| 71 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 72 | Filesystem: map[string]string{}, |
| 73 | Blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 74 | apex_key { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 75 | name: "com.android.apogee.key", |
| 76 | public_key: "com.android.apogee.avbpubkey", |
| 77 | private_key: "com.android.apogee.pem", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 78 | bazel_module: { bp2build_available: false }, |
| 79 | } |
| 80 | |
| 81 | android_app_certificate { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 82 | name: "com.android.apogee.certificate", |
| 83 | certificate: "com.android.apogee", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 84 | bazel_module: { bp2build_available: false }, |
| 85 | } |
| 86 | |
| 87 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 88 | name: "native_shared_lib_1", |
| 89 | bazel_module: { bp2build_available: false }, |
| 90 | } |
| 91 | |
| 92 | cc_library { |
| 93 | name: "native_shared_lib_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 94 | bazel_module: { bp2build_available: false }, |
| 95 | } |
| 96 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 97 | prebuilt_etc { |
| 98 | name: "prebuilt_1", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 99 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 102 | prebuilt_etc { |
| 103 | name: "prebuilt_2", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 104 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 107 | filegroup { |
| 108 | name: "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 109 | srcs: [ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 110 | "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 111 | ], |
| 112 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 115 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 116 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 117 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 118 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 119 | name: "com.android.apogee", |
| 120 | manifest: "apogee_manifest.json", |
| 121 | androidManifest: "ApogeeAndroidManifest.xml", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 122 | file_contexts: ":com.android.apogee-file_contexts", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 123 | min_sdk_version: "29", |
| 124 | key: "com.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 125 | certificate: ":com.android.apogee.certificate", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 126 | updatable: false, |
| 127 | installable: false, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 128 | compressible: false, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 129 | native_shared_libs: [ |
| 130 | "native_shared_lib_1", |
| 131 | "native_shared_lib_2", |
| 132 | ], |
| 133 | binaries: [ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 134 | "cc_binary_1", |
| 135 | "sh_binary_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 136 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 137 | prebuilts: [ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 138 | "prebuilt_1", |
| 139 | "prebuilt_2", |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 140 | ], |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 141 | package_name: "com.android.apogee.test.package", |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 142 | logging_parent: "logging.parent", |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 143 | } |
| 144 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 145 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 146 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 147 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 148 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 149 | ":cc_binary_1", |
| 150 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 151 | ]`, |
| 152 | "certificate": `":com.android.apogee.certificate"`, |
| 153 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 154 | "installable": "False", |
| 155 | "key": `":com.android.apogee.key"`, |
| 156 | "manifest": `"apogee_manifest.json"`, |
| 157 | "min_sdk_version": `"29"`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 158 | "native_shared_libs_32": `select({ |
| 159 | "//build/bazel/platforms/arch:arm": [ |
| 160 | ":native_shared_lib_1", |
| 161 | ":native_shared_lib_2", |
| 162 | ], |
| 163 | "//build/bazel/platforms/arch:x86": [ |
| 164 | ":native_shared_lib_1", |
| 165 | ":native_shared_lib_2", |
| 166 | ], |
| 167 | "//conditions:default": [], |
| 168 | })`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 169 | "native_shared_libs_64": `select({ |
| 170 | "//build/bazel/platforms/arch:arm64": [ |
| 171 | ":native_shared_lib_1", |
| 172 | ":native_shared_lib_2", |
| 173 | ], |
| 174 | "//build/bazel/platforms/arch:x86_64": [ |
| 175 | ":native_shared_lib_1", |
| 176 | ":native_shared_lib_2", |
| 177 | ], |
| 178 | "//conditions:default": [], |
| 179 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 180 | "prebuilts": `[ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 181 | ":prebuilt_1", |
| 182 | ":prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 183 | ]`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 184 | "updatable": "False", |
| 185 | "compressible": "False", |
| 186 | "package_name": `"com.android.apogee.test.package"`, |
| 187 | "logging_parent": `"logging.parent"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 188 | }), |
| 189 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 192 | func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 193 | runApexTestCase(t, Bp2buildTestCase{ |
| 194 | Description: "apex - file contexts is a module in another Android.bp", |
| 195 | ModuleTypeUnderTest: "apex", |
| 196 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 197 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 198 | "a/b/Android.bp": ` |
| 199 | filegroup { |
| 200 | name: "com.android.apogee-file_contexts", |
| 201 | srcs: [ |
| 202 | "com.android.apogee-file_contexts", |
| 203 | ], |
| 204 | bazel_module: { bp2build_available: false }, |
| 205 | } |
| 206 | `, |
| 207 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 208 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 209 | apex { |
| 210 | name: "com.android.apogee", |
| 211 | file_contexts: ":com.android.apogee-file_contexts", |
| 212 | } |
| 213 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 214 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 215 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 216 | "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 217 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 218 | }), |
| 219 | }}) |
| 220 | } |
| 221 | |
| 222 | func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 223 | runApexTestCase(t, Bp2buildTestCase{ |
| 224 | Description: "apex - file contexts is a file", |
| 225 | ModuleTypeUnderTest: "apex", |
| 226 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 227 | Filesystem: map[string]string{}, |
| 228 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 229 | apex { |
| 230 | name: "com.android.apogee", |
| 231 | file_contexts: "file_contexts_file", |
| 232 | } |
| 233 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 234 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 235 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 236 | "file_contexts": `"file_contexts_file"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 237 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 238 | }), |
| 239 | }}) |
| 240 | } |
| 241 | |
| 242 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 243 | runApexTestCase(t, Bp2buildTestCase{ |
| 244 | Description: "apex - file contexts is not specified", |
| 245 | ModuleTypeUnderTest: "apex", |
| 246 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 247 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 248 | "system/sepolicy/apex/Android.bp": ` |
| 249 | filegroup { |
| 250 | name: "com.android.apogee-file_contexts", |
| 251 | srcs: [ |
| 252 | "com.android.apogee-file_contexts", |
| 253 | ], |
| 254 | bazel_module: { bp2build_available: false }, |
| 255 | } |
| 256 | `, |
| 257 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 258 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 259 | apex { |
| 260 | name: "com.android.apogee", |
| 261 | } |
| 262 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 263 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 264 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 265 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 266 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 267 | }), |
| 268 | }}) |
| 269 | } |
| 270 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 271 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 272 | runApexTestCase(t, Bp2buildTestCase{ |
| 273 | Description: "apex - example with compile_multilib=both", |
| 274 | ModuleTypeUnderTest: "apex", |
| 275 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 276 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 277 | "system/sepolicy/apex/Android.bp": ` |
| 278 | filegroup { |
| 279 | name: "com.android.apogee-file_contexts", |
| 280 | srcs: [ "apogee-file_contexts", ], |
| 281 | bazel_module: { bp2build_available: false }, |
| 282 | } |
| 283 | `, |
| 284 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 285 | Blueprint: createMultilibBlueprint(`compile_multilib: "both",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 286 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 287 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 288 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 289 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 290 | ":native_shared_lib_for_both", |
| 291 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 292 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 293 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 294 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 295 | "//conditions:default": [], |
| 296 | })`, |
| 297 | "native_shared_libs_64": `select({ |
| 298 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 299 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 300 | ":native_shared_lib_for_both", |
| 301 | ":native_shared_lib_for_lib64", |
| 302 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 303 | ], |
| 304 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 305 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 306 | ":native_shared_lib_for_both", |
| 307 | ":native_shared_lib_for_lib64", |
| 308 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 309 | ], |
| 310 | "//conditions:default": [], |
| 311 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 312 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 313 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 314 | }), |
| 315 | }}) |
| 316 | } |
| 317 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 318 | func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) { |
| 319 | expectedBazelTargets := []string{ |
| 320 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 321 | "native_shared_libs_32": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 322 | "//build/bazel/platforms/arch:arm": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 323 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 324 | ":native_shared_lib_for_both", |
| 325 | ":native_shared_lib_for_lib32", |
| 326 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 327 | ], |
| 328 | "//build/bazel/platforms/arch:x86": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 329 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 330 | ":native_shared_lib_for_both", |
| 331 | ":native_shared_lib_for_lib32", |
| 332 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 333 | ], |
| 334 | "//conditions:default": [], |
| 335 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 336 | "native_shared_libs_64": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 337 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 338 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 339 | ":native_shared_lib_for_both", |
| 340 | ":native_shared_lib_for_lib64", |
| 341 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 342 | ], |
| 343 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 344 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 345 | ":native_shared_lib_for_both", |
| 346 | ":native_shared_lib_for_lib64", |
| 347 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 348 | ], |
| 349 | "//conditions:default": [], |
| 350 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 351 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 352 | "manifest": `"apex_manifest.json"`, |
| 353 | }), |
| 354 | } |
| 355 | |
| 356 | // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib |
| 357 | // should result to the same bp2build output |
| 358 | compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""} |
| 359 | for _, compileMultiLibProp := range compileMultiLibPropValues { |
| 360 | descriptionSuffix := compileMultiLibProp |
| 361 | if descriptionSuffix == "" { |
| 362 | descriptionSuffix = "compile_multilib unset" |
| 363 | } |
| 364 | runApexTestCase(t, Bp2buildTestCase{ |
| 365 | Description: "apex - example with " + compileMultiLibProp, |
| 366 | ModuleTypeUnderTest: "apex", |
| 367 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 368 | Filesystem: map[string]string{ |
| 369 | "system/sepolicy/apex/Android.bp": ` |
| 370 | filegroup { |
| 371 | name: "com.android.apogee-file_contexts", |
| 372 | srcs: [ "apogee-file_contexts", ], |
| 373 | bazel_module: { bp2build_available: false }, |
| 374 | } |
| 375 | `, |
| 376 | }, |
| 377 | Blueprint: createMultilibBlueprint(compileMultiLibProp), |
| 378 | ExpectedBazelTargets: expectedBazelTargets, |
| 379 | }) |
| 380 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | func TestApexBundleCompileMultilib32(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 384 | runApexTestCase(t, Bp2buildTestCase{ |
| 385 | Description: "apex - example with compile_multilib=32", |
| 386 | ModuleTypeUnderTest: "apex", |
| 387 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 388 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 389 | "system/sepolicy/apex/Android.bp": ` |
| 390 | filegroup { |
| 391 | name: "com.android.apogee-file_contexts", |
| 392 | srcs: [ "apogee-file_contexts", ], |
| 393 | bazel_module: { bp2build_available: false }, |
| 394 | } |
| 395 | `, |
| 396 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 397 | Blueprint: createMultilibBlueprint(`compile_multilib: "32",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 398 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 399 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 400 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 401 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 402 | ":native_shared_lib_for_both", |
| 403 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 404 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 405 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 406 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 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 | |
| 415 | func TestApexBundleCompileMultilib64(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 416 | runApexTestCase(t, Bp2buildTestCase{ |
| 417 | Description: "apex - example with compile_multilib=64", |
| 418 | ModuleTypeUnderTest: "apex", |
| 419 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 420 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 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 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 429 | Blueprint: createMultilibBlueprint(`compile_multilib: "64",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 430 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 431 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 432 | "native_shared_libs_64": `select({ |
| 433 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 434 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 435 | ":native_shared_lib_for_both", |
| 436 | ":native_shared_lib_for_lib64", |
| 437 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 438 | ], |
| 439 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 440 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 441 | ":native_shared_lib_for_both", |
| 442 | ":native_shared_lib_for_lib64", |
| 443 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 444 | ], |
| 445 | "//conditions:default": [], |
| 446 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 447 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 448 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 449 | }), |
| 450 | }}) |
| 451 | } |
| 452 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 453 | func createMultilibBlueprint(compile_multilib string) string { |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 454 | return fmt.Sprintf(` |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 455 | cc_library { |
| 456 | name: "native_shared_lib_for_both", |
| 457 | bazel_module: { bp2build_available: false }, |
| 458 | } |
| 459 | |
| 460 | cc_library { |
| 461 | name: "native_shared_lib_for_first", |
| 462 | bazel_module: { bp2build_available: false }, |
| 463 | } |
| 464 | |
| 465 | cc_library { |
| 466 | name: "native_shared_lib_for_lib32", |
| 467 | bazel_module: { bp2build_available: false }, |
| 468 | } |
| 469 | |
| 470 | cc_library { |
| 471 | name: "native_shared_lib_for_lib64", |
| 472 | bazel_module: { bp2build_available: false }, |
| 473 | } |
| 474 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 475 | cc_library { |
| 476 | name: "unnested_native_shared_lib", |
| 477 | bazel_module: { bp2build_available: false }, |
| 478 | } |
| 479 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 480 | apex { |
| 481 | name: "com.android.apogee", |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 482 | %s |
| 483 | native_shared_libs: ["unnested_native_shared_lib"], |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 484 | multilib: { |
| 485 | both: { |
| 486 | native_shared_libs: [ |
| 487 | "native_shared_lib_for_both", |
| 488 | ], |
| 489 | }, |
| 490 | first: { |
| 491 | native_shared_libs: [ |
| 492 | "native_shared_lib_for_first", |
| 493 | ], |
| 494 | }, |
| 495 | lib32: { |
| 496 | native_shared_libs: [ |
| 497 | "native_shared_lib_for_lib32", |
| 498 | ], |
| 499 | }, |
| 500 | lib64: { |
| 501 | native_shared_libs: [ |
| 502 | "native_shared_lib_for_lib64", |
| 503 | ], |
| 504 | }, |
| 505 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 506 | }`, compile_multilib) |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 509 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 510 | runApexTestCase(t, Bp2buildTestCase{ |
| 511 | Description: "apex - default property values", |
| 512 | ModuleTypeUnderTest: "apex", |
| 513 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 514 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 515 | "system/sepolicy/apex/Android.bp": ` |
| 516 | filegroup { |
| 517 | name: "com.android.apogee-file_contexts", |
| 518 | srcs: [ "apogee-file_contexts", ], |
| 519 | bazel_module: { bp2build_available: false }, |
| 520 | } |
| 521 | `, |
| 522 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 523 | Blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 524 | apex { |
| 525 | name: "com.android.apogee", |
| 526 | manifest: "apogee_manifest.json", |
| 527 | } |
| 528 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 529 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 530 | "manifest": `"apogee_manifest.json"`, |
| 531 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 532 | }), |
| 533 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 534 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 535 | |
| 536 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 537 | runApexTestCase(t, Bp2buildTestCase{ |
| 538 | Description: "apex - has bazel module props", |
| 539 | ModuleTypeUnderTest: "apex", |
| 540 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 541 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 542 | "system/sepolicy/apex/Android.bp": ` |
| 543 | filegroup { |
| 544 | name: "apogee-file_contexts", |
| 545 | srcs: [ "apogee-file_contexts", ], |
| 546 | bazel_module: { bp2build_available: false }, |
| 547 | } |
| 548 | `, |
| 549 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 550 | Blueprint: ` |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 551 | apex { |
| 552 | name: "apogee", |
| 553 | manifest: "manifest.json", |
| 554 | bazel_module: { bp2build_available: true }, |
| 555 | } |
| 556 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 557 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 558 | "manifest": `"manifest.json"`, |
| 559 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 560 | }), |
| 561 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 562 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 563 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 564 | func TestBp2BuildOverrideApex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 565 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 566 | Description: "override_apex", |
| 567 | ModuleTypeUnderTest: "override_apex", |
| 568 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 569 | Filesystem: map[string]string{}, |
| 570 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 571 | apex_key { |
| 572 | name: "com.android.apogee.key", |
| 573 | public_key: "com.android.apogee.avbpubkey", |
| 574 | private_key: "com.android.apogee.pem", |
| 575 | bazel_module: { bp2build_available: false }, |
| 576 | } |
| 577 | |
| 578 | android_app_certificate { |
| 579 | name: "com.android.apogee.certificate", |
| 580 | certificate: "com.android.apogee", |
| 581 | bazel_module: { bp2build_available: false }, |
| 582 | } |
| 583 | |
| 584 | cc_library { |
| 585 | name: "native_shared_lib_1", |
| 586 | bazel_module: { bp2build_available: false }, |
| 587 | } |
| 588 | |
| 589 | cc_library { |
| 590 | name: "native_shared_lib_2", |
| 591 | bazel_module: { bp2build_available: false }, |
| 592 | } |
| 593 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 594 | prebuilt_etc { |
| 595 | name: "prebuilt_1", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 596 | bazel_module: { bp2build_available: false }, |
| 597 | } |
| 598 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 599 | prebuilt_etc { |
| 600 | name: "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 601 | bazel_module: { bp2build_available: false }, |
| 602 | } |
| 603 | |
| 604 | filegroup { |
| 605 | name: "com.android.apogee-file_contexts", |
| 606 | srcs: [ |
| 607 | "com.android.apogee-file_contexts", |
| 608 | ], |
| 609 | bazel_module: { bp2build_available: false }, |
| 610 | } |
| 611 | |
| 612 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 613 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 614 | |
| 615 | apex { |
| 616 | name: "com.android.apogee", |
| 617 | manifest: "apogee_manifest.json", |
| 618 | androidManifest: "ApogeeAndroidManifest.xml", |
| 619 | file_contexts: ":com.android.apogee-file_contexts", |
| 620 | min_sdk_version: "29", |
| 621 | key: "com.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 622 | certificate: ":com.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 623 | updatable: false, |
| 624 | installable: false, |
| 625 | compressible: false, |
| 626 | native_shared_libs: [ |
| 627 | "native_shared_lib_1", |
| 628 | "native_shared_lib_2", |
| 629 | ], |
| 630 | binaries: [ |
| 631 | "cc_binary_1", |
| 632 | "sh_binary_2", |
| 633 | ], |
| 634 | prebuilts: [ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 635 | "prebuilt_1", |
| 636 | "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 637 | ], |
| 638 | bazel_module: { bp2build_available: false }, |
| 639 | } |
| 640 | |
| 641 | apex_key { |
| 642 | name: "com.google.android.apogee.key", |
| 643 | public_key: "com.google.android.apogee.avbpubkey", |
| 644 | private_key: "com.google.android.apogee.pem", |
| 645 | bazel_module: { bp2build_available: false }, |
| 646 | } |
| 647 | |
| 648 | android_app_certificate { |
| 649 | name: "com.google.android.apogee.certificate", |
| 650 | certificate: "com.google.android.apogee", |
| 651 | bazel_module: { bp2build_available: false }, |
| 652 | } |
| 653 | |
| 654 | override_apex { |
| 655 | name: "com.google.android.apogee", |
| 656 | base: ":com.android.apogee", |
| 657 | key: "com.google.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 658 | certificate: ":com.google.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 659 | prebuilts: [], |
| 660 | compressible: true, |
| 661 | } |
| 662 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 663 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 664 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 665 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 666 | "binaries": `[ |
| 667 | ":cc_binary_1", |
| 668 | ":sh_binary_2", |
| 669 | ]`, |
| 670 | "certificate": `":com.google.android.apogee.certificate"`, |
| 671 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 672 | "installable": "False", |
| 673 | "key": `":com.google.android.apogee.key"`, |
| 674 | "manifest": `"apogee_manifest.json"`, |
| 675 | "min_sdk_version": `"29"`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 676 | "native_shared_libs_32": `select({ |
| 677 | "//build/bazel/platforms/arch:arm": [ |
| 678 | ":native_shared_lib_1", |
| 679 | ":native_shared_lib_2", |
| 680 | ], |
| 681 | "//build/bazel/platforms/arch:x86": [ |
| 682 | ":native_shared_lib_1", |
| 683 | ":native_shared_lib_2", |
| 684 | ], |
| 685 | "//conditions:default": [], |
| 686 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 687 | "native_shared_libs_64": `select({ |
| 688 | "//build/bazel/platforms/arch:arm64": [ |
| 689 | ":native_shared_lib_1", |
| 690 | ":native_shared_lib_2", |
| 691 | ], |
| 692 | "//build/bazel/platforms/arch:x86_64": [ |
| 693 | ":native_shared_lib_1", |
| 694 | ":native_shared_lib_2", |
| 695 | ], |
| 696 | "//conditions:default": [], |
| 697 | })`, |
| 698 | "prebuilts": `[]`, |
| 699 | "updatable": "False", |
| 700 | "compressible": "True", |
| 701 | }), |
| 702 | }}) |
| 703 | } |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 704 | |
| 705 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 706 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 707 | Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", |
| 708 | ModuleTypeUnderTest: "override_apex", |
| 709 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 710 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 711 | "system/sepolicy/apex/Android.bp": ` |
| 712 | filegroup { |
| 713 | name: "com.android.apogee-file_contexts", |
| 714 | srcs: [ "apogee-file_contexts", ], |
| 715 | bazel_module: { bp2build_available: false }, |
| 716 | }`, |
| 717 | "a/b/Android.bp": ` |
| 718 | apex { |
| 719 | name: "com.android.apogee", |
| 720 | bazel_module: { bp2build_available: false }, |
| 721 | } |
| 722 | `, |
| 723 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 724 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 725 | override_apex { |
| 726 | name: "com.google.android.apogee", |
| 727 | base: ":com.android.apogee", |
| 728 | } |
| 729 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 730 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 731 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 732 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 733 | "manifest": `"//a/b:apex_manifest.json"`, |
| 734 | }), |
| 735 | }}) |
| 736 | } |
| 737 | |
| 738 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 739 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 740 | Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", |
| 741 | ModuleTypeUnderTest: "override_apex", |
| 742 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 743 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 744 | "system/sepolicy/apex/Android.bp": ` |
| 745 | filegroup { |
| 746 | name: "com.android.apogee-file_contexts", |
| 747 | srcs: [ "apogee-file_contexts", ], |
| 748 | bazel_module: { bp2build_available: false }, |
| 749 | }`, |
| 750 | "a/b/Android.bp": ` |
| 751 | apex { |
| 752 | name: "com.android.apogee", |
| 753 | manifest: "apogee_manifest.json", |
| 754 | bazel_module: { bp2build_available: false }, |
| 755 | } |
| 756 | `, |
| 757 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 758 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 759 | override_apex { |
| 760 | name: "com.google.android.apogee", |
| 761 | base: ":com.android.apogee", |
| 762 | } |
| 763 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 764 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 765 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 766 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 767 | "manifest": `"//a/b:apogee_manifest.json"`, |
| 768 | }), |
| 769 | }}) |
| 770 | } |
| 771 | |
| 772 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 773 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 774 | Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", |
| 775 | ModuleTypeUnderTest: "override_apex", |
| 776 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 777 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 778 | "system/sepolicy/apex/Android.bp": ` |
| 779 | filegroup { |
| 780 | name: "com.android.apogee-file_contexts", |
| 781 | srcs: [ "apogee-file_contexts", ], |
| 782 | bazel_module: { bp2build_available: false }, |
| 783 | }`, |
| 784 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 785 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 786 | apex { |
| 787 | name: "com.android.apogee", |
| 788 | bazel_module: { bp2build_available: false }, |
| 789 | } |
| 790 | |
| 791 | override_apex { |
| 792 | name: "com.google.android.apogee", |
| 793 | base: ":com.android.apogee", |
| 794 | } |
| 795 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 796 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 797 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 798 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 799 | "manifest": `"apex_manifest.json"`, |
| 800 | }), |
| 801 | }}) |
| 802 | } |
| 803 | |
| 804 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 805 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 806 | Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", |
| 807 | ModuleTypeUnderTest: "override_apex", |
| 808 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 809 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 810 | "system/sepolicy/apex/Android.bp": ` |
| 811 | filegroup { |
| 812 | name: "com.android.apogee-file_contexts", |
| 813 | srcs: [ "apogee-file_contexts", ], |
| 814 | bazel_module: { bp2build_available: false }, |
| 815 | }`, |
| 816 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 817 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 818 | apex { |
| 819 | name: "com.android.apogee", |
| 820 | manifest: "apogee_manifest.json", |
| 821 | bazel_module: { bp2build_available: false }, |
| 822 | } |
| 823 | |
| 824 | override_apex { |
| 825 | name: "com.google.android.apogee", |
| 826 | base: ":com.android.apogee", |
| 827 | } |
| 828 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 829 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 830 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 831 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 832 | "manifest": `"apogee_manifest.json"`, |
| 833 | }), |
| 834 | }}) |
| 835 | } |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 836 | |
| 837 | func TestApexBundleSimple_packageNameOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 838 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 839 | Description: "override_apex - override package name", |
| 840 | ModuleTypeUnderTest: "override_apex", |
| 841 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 842 | Filesystem: map[string]string{ |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 843 | "system/sepolicy/apex/Android.bp": ` |
| 844 | filegroup { |
| 845 | name: "com.android.apogee-file_contexts", |
| 846 | srcs: [ "apogee-file_contexts", ], |
| 847 | bazel_module: { bp2build_available: false }, |
| 848 | }`, |
| 849 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 850 | Blueprint: ` |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 851 | apex { |
| 852 | name: "com.android.apogee", |
| 853 | bazel_module: { bp2build_available: false }, |
| 854 | } |
| 855 | |
| 856 | override_apex { |
| 857 | name: "com.google.android.apogee", |
| 858 | base: ":com.android.apogee", |
| 859 | package_name: "com.google.android.apogee", |
| 860 | } |
| 861 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 862 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 863 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 864 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 865 | "manifest": `"apex_manifest.json"`, |
| 866 | "package_name": `"com.google.android.apogee"`, |
| 867 | }), |
| 868 | }}) |
| 869 | } |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 870 | |
| 871 | func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 872 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 873 | Description: "override_apex - no override", |
| 874 | ModuleTypeUnderTest: "override_apex", |
| 875 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 876 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 877 | "system/sepolicy/apex/Android.bp": ` |
| 878 | filegroup { |
| 879 | name: "com.android.apogee-file_contexts", |
| 880 | srcs: [ "apogee-file_contexts", ], |
| 881 | bazel_module: { bp2build_available: false }, |
| 882 | }`, |
| 883 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 884 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 885 | prebuilt_etc { |
| 886 | name: "prebuilt_file", |
| 887 | bazel_module: { bp2build_available: false }, |
| 888 | } |
| 889 | |
| 890 | apex { |
| 891 | name: "com.android.apogee", |
| 892 | bazel_module: { bp2build_available: false }, |
| 893 | prebuilts: ["prebuilt_file"] |
| 894 | } |
| 895 | |
| 896 | override_apex { |
| 897 | name: "com.google.android.apogee", |
| 898 | base: ":com.android.apogee", |
| 899 | } |
| 900 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 901 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 902 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 903 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 904 | "manifest": `"apex_manifest.json"`, |
| 905 | "prebuilts": `[":prebuilt_file"]`, |
| 906 | }), |
| 907 | }}) |
| 908 | } |
| 909 | |
| 910 | func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 911 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 912 | Description: "override_apex - ooverride", |
| 913 | ModuleTypeUnderTest: "override_apex", |
| 914 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 915 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 916 | "system/sepolicy/apex/Android.bp": ` |
| 917 | filegroup { |
| 918 | name: "com.android.apogee-file_contexts", |
| 919 | srcs: [ "apogee-file_contexts", ], |
| 920 | bazel_module: { bp2build_available: false }, |
| 921 | }`, |
| 922 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 923 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 924 | prebuilt_etc { |
| 925 | name: "prebuilt_file", |
| 926 | bazel_module: { bp2build_available: false }, |
| 927 | } |
| 928 | |
| 929 | prebuilt_etc { |
| 930 | name: "prebuilt_file2", |
| 931 | bazel_module: { bp2build_available: false }, |
| 932 | } |
| 933 | |
| 934 | apex { |
| 935 | name: "com.android.apogee", |
| 936 | bazel_module: { bp2build_available: false }, |
| 937 | prebuilts: ["prebuilt_file"] |
| 938 | } |
| 939 | |
| 940 | override_apex { |
| 941 | name: "com.google.android.apogee", |
| 942 | base: ":com.android.apogee", |
| 943 | prebuilts: ["prebuilt_file2"] |
| 944 | } |
| 945 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 946 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 947 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 948 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 949 | "manifest": `"apex_manifest.json"`, |
| 950 | "prebuilts": `[":prebuilt_file2"]`, |
| 951 | }), |
| 952 | }}) |
| 953 | } |
| 954 | |
| 955 | func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 956 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 957 | Description: "override_apex - override with empty list", |
| 958 | ModuleTypeUnderTest: "override_apex", |
| 959 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 960 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 961 | "system/sepolicy/apex/Android.bp": ` |
| 962 | filegroup { |
| 963 | name: "com.android.apogee-file_contexts", |
| 964 | srcs: [ "apogee-file_contexts", ], |
| 965 | bazel_module: { bp2build_available: false }, |
| 966 | }`, |
| 967 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 968 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 969 | prebuilt_etc { |
| 970 | name: "prebuilt_file", |
| 971 | bazel_module: { bp2build_available: false }, |
| 972 | } |
| 973 | |
| 974 | apex { |
| 975 | name: "com.android.apogee", |
| 976 | bazel_module: { bp2build_available: false }, |
| 977 | prebuilts: ["prebuilt_file"] |
| 978 | } |
| 979 | |
| 980 | override_apex { |
| 981 | name: "com.google.android.apogee", |
| 982 | base: ":com.android.apogee", |
| 983 | prebuilts: [], |
| 984 | } |
| 985 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 986 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 987 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 988 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 989 | "manifest": `"apex_manifest.json"`, |
| 990 | "prebuilts": `[]`, |
| 991 | }), |
| 992 | }}) |
| 993 | } |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 994 | |
| 995 | func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 996 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 997 | Description: "override_apex - logging_parent - no override", |
| 998 | ModuleTypeUnderTest: "override_apex", |
| 999 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1000 | Filesystem: map[string]string{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1001 | "system/sepolicy/apex/Android.bp": ` |
| 1002 | filegroup { |
| 1003 | name: "com.android.apogee-file_contexts", |
| 1004 | srcs: [ "apogee-file_contexts", ], |
| 1005 | bazel_module: { bp2build_available: false }, |
| 1006 | }`, |
| 1007 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1008 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1009 | apex { |
| 1010 | name: "com.android.apogee", |
| 1011 | bazel_module: { bp2build_available: false }, |
| 1012 | logging_parent: "foo.bar.baz", |
| 1013 | } |
| 1014 | |
| 1015 | override_apex { |
| 1016 | name: "com.google.android.apogee", |
| 1017 | base: ":com.android.apogee", |
| 1018 | } |
| 1019 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1020 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1021 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1022 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1023 | "manifest": `"apex_manifest.json"`, |
| 1024 | "logging_parent": `"foo.bar.baz"`, |
| 1025 | }), |
| 1026 | }}) |
| 1027 | } |
| 1028 | |
| 1029 | func TestApexBundleSimple_LoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1030 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1031 | Description: "override_apex - logging_parent - override", |
| 1032 | ModuleTypeUnderTest: "override_apex", |
| 1033 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1034 | Filesystem: map[string]string{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1035 | "system/sepolicy/apex/Android.bp": ` |
| 1036 | filegroup { |
| 1037 | name: "com.android.apogee-file_contexts", |
| 1038 | srcs: [ "apogee-file_contexts", ], |
| 1039 | bazel_module: { bp2build_available: false }, |
| 1040 | }`, |
| 1041 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1042 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1043 | apex { |
| 1044 | name: "com.android.apogee", |
| 1045 | bazel_module: { bp2build_available: false }, |
| 1046 | logging_parent: "foo.bar.baz", |
| 1047 | } |
| 1048 | |
| 1049 | override_apex { |
| 1050 | name: "com.google.android.apogee", |
| 1051 | base: ":com.android.apogee", |
| 1052 | logging_parent: "foo.bar.baz.override", |
| 1053 | } |
| 1054 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1055 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1056 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1057 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1058 | "manifest": `"apex_manifest.json"`, |
| 1059 | "logging_parent": `"foo.bar.baz.override"`, |
| 1060 | }), |
| 1061 | }}) |
| 1062 | } |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1063 | |
| 1064 | func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) { |
| 1065 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1066 | Description: "override_apex - don't set default certificate", |
| 1067 | ModuleTypeUnderTest: "override_apex", |
| 1068 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1069 | Filesystem: map[string]string{}, |
| 1070 | Blueprint: ` |
| 1071 | android_app_certificate { |
| 1072 | name: "com.android.apogee.certificate", |
| 1073 | certificate: "com.android.apogee", |
| 1074 | bazel_module: { bp2build_available: false }, |
| 1075 | } |
| 1076 | |
| 1077 | filegroup { |
| 1078 | name: "com.android.apogee-file_contexts", |
| 1079 | srcs: [ |
| 1080 | "com.android.apogee-file_contexts", |
| 1081 | ], |
| 1082 | bazel_module: { bp2build_available: false }, |
| 1083 | } |
| 1084 | |
| 1085 | apex { |
| 1086 | name: "com.android.apogee", |
| 1087 | manifest: "apogee_manifest.json", |
| 1088 | file_contexts: ":com.android.apogee-file_contexts", |
| 1089 | certificate: ":com.android.apogee.certificate", |
| 1090 | bazel_module: { bp2build_available: false }, |
| 1091 | } |
| 1092 | |
| 1093 | override_apex { |
| 1094 | name: "com.google.android.apogee", |
| 1095 | base: ":com.android.apogee", |
| 1096 | // certificate is deliberately omitted, and not converted to bazel, |
| 1097 | // because the overridden apex shouldn't be using the base apex's cert. |
| 1098 | } |
| 1099 | `, |
| 1100 | ExpectedBazelTargets: []string{ |
| 1101 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
| 1102 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1103 | "manifest": `"apogee_manifest.json"`, |
| 1104 | }), |
| 1105 | }}) |
| 1106 | } |
| 1107 | |
| 1108 | func TestApexCertificateIsModule(t *testing.T) { |
| 1109 | runApexTestCase(t, Bp2buildTestCase{ |
| 1110 | Description: "apex - certificate is module", |
| 1111 | ModuleTypeUnderTest: "apex", |
| 1112 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1113 | Filesystem: map[string]string{}, |
| 1114 | Blueprint: ` |
| 1115 | android_app_certificate { |
| 1116 | name: "com.android.apogee.certificate", |
| 1117 | certificate: "com.android.apogee", |
| 1118 | bazel_module: { bp2build_available: false }, |
| 1119 | } |
| 1120 | |
| 1121 | apex { |
| 1122 | name: "com.android.apogee", |
| 1123 | manifest: "apogee_manifest.json", |
| 1124 | file_contexts: ":com.android.apogee-file_contexts", |
| 1125 | certificate: ":com.android.apogee.certificate", |
| 1126 | } |
| 1127 | ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
| 1128 | ExpectedBazelTargets: []string{ |
| 1129 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 1130 | "certificate": `":com.android.apogee.certificate"`, |
| 1131 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1132 | "manifest": `"apogee_manifest.json"`, |
| 1133 | }), |
| 1134 | }}) |
| 1135 | } |
| 1136 | |
| 1137 | func TestApexCertificateIsSrc(t *testing.T) { |
| 1138 | runApexTestCase(t, Bp2buildTestCase{ |
| 1139 | Description: "apex - certificate is src", |
| 1140 | ModuleTypeUnderTest: "apex", |
| 1141 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1142 | Filesystem: map[string]string{}, |
| 1143 | Blueprint: ` |
| 1144 | apex { |
| 1145 | name: "com.android.apogee", |
| 1146 | manifest: "apogee_manifest.json", |
| 1147 | file_contexts: ":com.android.apogee-file_contexts", |
| 1148 | certificate: "com.android.apogee.certificate", |
| 1149 | } |
| 1150 | ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
| 1151 | ExpectedBazelTargets: []string{ |
| 1152 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 1153 | "certificate_name": `"com.android.apogee.certificate"`, |
| 1154 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1155 | "manifest": `"apogee_manifest.json"`, |
| 1156 | }), |
| 1157 | }}) |
| 1158 | } |
| 1159 | |
| 1160 | func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) { |
| 1161 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1162 | Description: "override_apex - certificate is module", |
| 1163 | ModuleTypeUnderTest: "override_apex", |
| 1164 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1165 | Filesystem: map[string]string{}, |
| 1166 | Blueprint: ` |
| 1167 | android_app_certificate { |
| 1168 | name: "com.android.apogee.certificate", |
| 1169 | certificate: "com.android.apogee", |
| 1170 | bazel_module: { bp2build_available: false }, |
| 1171 | } |
| 1172 | |
| 1173 | filegroup { |
| 1174 | name: "com.android.apogee-file_contexts", |
| 1175 | srcs: [ |
| 1176 | "com.android.apogee-file_contexts", |
| 1177 | ], |
| 1178 | bazel_module: { bp2build_available: false }, |
| 1179 | } |
| 1180 | |
| 1181 | apex { |
| 1182 | name: "com.android.apogee", |
| 1183 | manifest: "apogee_manifest.json", |
| 1184 | file_contexts: ":com.android.apogee-file_contexts", |
| 1185 | certificate: ":com.android.apogee.certificate", |
| 1186 | bazel_module: { bp2build_available: false }, |
| 1187 | } |
| 1188 | |
| 1189 | android_app_certificate { |
| 1190 | name: "com.google.android.apogee.certificate", |
| 1191 | certificate: "com.google.android.apogee", |
| 1192 | bazel_module: { bp2build_available: false }, |
| 1193 | } |
| 1194 | |
| 1195 | override_apex { |
| 1196 | name: "com.google.android.apogee", |
| 1197 | base: ":com.android.apogee", |
| 1198 | certificate: ":com.google.android.apogee.certificate", |
| 1199 | } |
| 1200 | `, |
| 1201 | ExpectedBazelTargets: []string{ |
| 1202 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
| 1203 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1204 | "certificate": `":com.google.android.apogee.certificate"`, |
| 1205 | "manifest": `"apogee_manifest.json"`, |
| 1206 | }), |
| 1207 | }}) |
| 1208 | } |
| 1209 | |
| 1210 | func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) { |
| 1211 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1212 | Description: "override_apex - certificate is src", |
| 1213 | ModuleTypeUnderTest: "override_apex", |
| 1214 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1215 | Filesystem: map[string]string{}, |
| 1216 | Blueprint: ` |
| 1217 | android_app_certificate { |
| 1218 | name: "com.android.apogee.certificate", |
| 1219 | certificate: "com.android.apogee", |
| 1220 | bazel_module: { bp2build_available: false }, |
| 1221 | } |
| 1222 | |
| 1223 | filegroup { |
| 1224 | name: "com.android.apogee-file_contexts", |
| 1225 | srcs: [ |
| 1226 | "com.android.apogee-file_contexts", |
| 1227 | ], |
| 1228 | bazel_module: { bp2build_available: false }, |
| 1229 | } |
| 1230 | |
| 1231 | apex { |
| 1232 | name: "com.android.apogee", |
| 1233 | manifest: "apogee_manifest.json", |
| 1234 | file_contexts: ":com.android.apogee-file_contexts", |
| 1235 | certificate: ":com.android.apogee.certificate", |
| 1236 | bazel_module: { bp2build_available: false }, |
| 1237 | } |
| 1238 | |
| 1239 | override_apex { |
| 1240 | name: "com.google.android.apogee", |
| 1241 | base: ":com.android.apogee", |
| 1242 | certificate: "com.google.android.apogee.certificate", |
| 1243 | } |
| 1244 | `, |
| 1245 | ExpectedBazelTargets: []string{ |
| 1246 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
| 1247 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1248 | "certificate_name": `"com.google.android.apogee.certificate"`, |
| 1249 | "manifest": `"apogee_manifest.json"`, |
| 1250 | }), |
| 1251 | }}) |
| 1252 | } |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame^] | 1253 | |
| 1254 | func TestApexTestBundleSimple(t *testing.T) { |
| 1255 | runApexTestCase(t, Bp2buildTestCase{ |
| 1256 | Description: "apex_test - simple", |
| 1257 | ModuleTypeUnderTest: "apex_test", |
| 1258 | ModuleTypeUnderTestFactory: apex.TestApexBundleFactory, |
| 1259 | Filesystem: map[string]string{}, |
| 1260 | Blueprint: ` |
| 1261 | cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } } |
| 1262 | |
| 1263 | apex_test { |
| 1264 | name: "test_com.android.apogee", |
| 1265 | file_contexts: "file_contexts_file", |
| 1266 | tests: ["cc_test_1"], |
| 1267 | } |
| 1268 | `, |
| 1269 | ExpectedBazelTargets: []string{ |
| 1270 | MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{ |
| 1271 | "file_contexts": `"file_contexts_file"`, |
| 1272 | "manifest": `"apex_manifest.json"`, |
| 1273 | "testonly": `True`, |
| 1274 | "tests": `[":cc_test_1"]`, |
| 1275 | }), |
| 1276 | }}) |
| 1277 | } |