Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/apex" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 20 | "android/soong/cc" |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 21 | "android/soong/etc" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 22 | "android/soong/java" |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 23 | "android/soong/sh" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 24 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 25 | "fmt" |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 26 | "testing" |
| 27 | ) |
| 28 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 29 | func runApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 30 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 31 | RunBp2BuildTestCase(t, registerApexModuleTypes, tc) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 35 | // CC module types needed as they can be APEX dependencies |
| 36 | cc.RegisterCCBuildComponents(ctx) |
| 37 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 38 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 39 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 40 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 41 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 42 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 43 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 44 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 45 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 48 | func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) { |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 49 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 50 | RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { |
| 54 | // CC module types needed as they can be APEX dependencies |
| 55 | cc.RegisterCCBuildComponents(ctx) |
| 56 | |
| 57 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 58 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
| 59 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 60 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
Liz Kammer | 1a1c9df | 2023-03-28 11:39:50 -0400 | [diff] [blame] | 61 | ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 62 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 63 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 64 | ctx.RegisterModuleType("apex", apex.BundleFactory) |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 65 | ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory) |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 66 | ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 67 | ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory) |
| 68 | ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 71 | func TestApexBundleSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 72 | runApexTestCase(t, Bp2buildTestCase{ |
| 73 | Description: "apex - example with all props, file_context is a module in same Android.bp", |
| 74 | ModuleTypeUnderTest: "apex", |
| 75 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 76 | Filesystem: map[string]string{}, |
| 77 | Blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 78 | apex_key { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 79 | name: "com.android.apogee.key", |
| 80 | public_key: "com.android.apogee.avbpubkey", |
| 81 | private_key: "com.android.apogee.pem", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 82 | bazel_module: { bp2build_available: false }, |
| 83 | } |
| 84 | |
| 85 | android_app_certificate { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 86 | name: "com.android.apogee.certificate", |
| 87 | certificate: "com.android.apogee", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 88 | bazel_module: { bp2build_available: false }, |
| 89 | } |
| 90 | |
| 91 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 92 | name: "native_shared_lib_1", |
| 93 | bazel_module: { bp2build_available: false }, |
| 94 | } |
| 95 | |
| 96 | cc_library { |
| 97 | name: "native_shared_lib_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 98 | bazel_module: { bp2build_available: false }, |
| 99 | } |
| 100 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 101 | prebuilt_etc { |
| 102 | name: "prebuilt_1", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 103 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 106 | prebuilt_etc { |
| 107 | name: "prebuilt_2", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 108 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 111 | filegroup { |
| 112 | name: "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 113 | srcs: [ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 114 | "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 115 | ], |
| 116 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 119 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 120 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 121 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 122 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 123 | name: "com.android.apogee", |
| 124 | manifest: "apogee_manifest.json", |
| 125 | androidManifest: "ApogeeAndroidManifest.xml", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 126 | file_contexts: ":com.android.apogee-file_contexts", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 127 | min_sdk_version: "29", |
| 128 | key: "com.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 129 | certificate: ":com.android.apogee.certificate", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 130 | updatable: false, |
| 131 | installable: false, |
Wei Li | f034cb4 | 2022-01-19 15:54:31 -0800 | [diff] [blame] | 132 | compressible: false, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 133 | native_shared_libs: [ |
| 134 | "native_shared_lib_1", |
| 135 | "native_shared_lib_2", |
| 136 | ], |
| 137 | binaries: [ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 138 | "cc_binary_1", |
| 139 | "sh_binary_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 140 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 141 | prebuilts: [ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 142 | "prebuilt_1", |
| 143 | "prebuilt_2", |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 144 | ], |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 145 | package_name: "com.android.apogee.test.package", |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 146 | logging_parent: "logging.parent", |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 147 | } |
| 148 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 149 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 150 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 151 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 152 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 153 | ":cc_binary_1", |
| 154 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 155 | ]`, |
| 156 | "certificate": `":com.android.apogee.certificate"`, |
| 157 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 158 | "installable": "False", |
| 159 | "key": `":com.android.apogee.key"`, |
| 160 | "manifest": `"apogee_manifest.json"`, |
| 161 | "min_sdk_version": `"29"`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 162 | "native_shared_libs_32": `select({ |
| 163 | "//build/bazel/platforms/arch:arm": [ |
| 164 | ":native_shared_lib_1", |
| 165 | ":native_shared_lib_2", |
| 166 | ], |
| 167 | "//build/bazel/platforms/arch:x86": [ |
| 168 | ":native_shared_lib_1", |
| 169 | ":native_shared_lib_2", |
| 170 | ], |
| 171 | "//conditions:default": [], |
| 172 | })`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 173 | "native_shared_libs_64": `select({ |
| 174 | "//build/bazel/platforms/arch:arm64": [ |
| 175 | ":native_shared_lib_1", |
| 176 | ":native_shared_lib_2", |
| 177 | ], |
| 178 | "//build/bazel/platforms/arch:x86_64": [ |
| 179 | ":native_shared_lib_1", |
| 180 | ":native_shared_lib_2", |
| 181 | ], |
| 182 | "//conditions:default": [], |
| 183 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 184 | "prebuilts": `[ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 185 | ":prebuilt_1", |
| 186 | ":prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 187 | ]`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 188 | "updatable": "False", |
| 189 | "compressible": "False", |
| 190 | "package_name": `"com.android.apogee.test.package"`, |
| 191 | "logging_parent": `"logging.parent"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 192 | }), |
| 193 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 196 | func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 197 | runApexTestCase(t, Bp2buildTestCase{ |
| 198 | Description: "apex - file contexts is a module in another Android.bp", |
| 199 | ModuleTypeUnderTest: "apex", |
| 200 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 201 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 202 | "a/b/Android.bp": ` |
| 203 | filegroup { |
| 204 | name: "com.android.apogee-file_contexts", |
| 205 | srcs: [ |
| 206 | "com.android.apogee-file_contexts", |
| 207 | ], |
| 208 | bazel_module: { bp2build_available: false }, |
| 209 | } |
| 210 | `, |
| 211 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 212 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 213 | apex { |
| 214 | name: "com.android.apogee", |
| 215 | file_contexts: ":com.android.apogee-file_contexts", |
| 216 | } |
| 217 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 218 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 219 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 220 | "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, |
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_fileContextsIsFile(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 227 | runApexTestCase(t, Bp2buildTestCase{ |
| 228 | Description: "apex - file contexts is a file", |
| 229 | ModuleTypeUnderTest: "apex", |
| 230 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 231 | Filesystem: map[string]string{}, |
| 232 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 233 | apex { |
| 234 | name: "com.android.apogee", |
| 235 | file_contexts: "file_contexts_file", |
| 236 | } |
| 237 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 238 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 239 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 240 | "file_contexts": `"file_contexts_file"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 241 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 242 | }), |
| 243 | }}) |
| 244 | } |
| 245 | |
| 246 | func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 247 | runApexTestCase(t, Bp2buildTestCase{ |
| 248 | Description: "apex - file contexts is not specified", |
| 249 | ModuleTypeUnderTest: "apex", |
| 250 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 251 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 252 | "system/sepolicy/apex/Android.bp": ` |
| 253 | filegroup { |
| 254 | name: "com.android.apogee-file_contexts", |
| 255 | srcs: [ |
| 256 | "com.android.apogee-file_contexts", |
| 257 | ], |
| 258 | bazel_module: { bp2build_available: false }, |
| 259 | } |
| 260 | `, |
| 261 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 262 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 263 | apex { |
| 264 | name: "com.android.apogee", |
| 265 | } |
| 266 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 267 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 268 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 269 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 270 | "manifest": `"apex_manifest.json"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 271 | }), |
| 272 | }}) |
| 273 | } |
| 274 | |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 275 | func TestApexBundleCompileMultilibBoth(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 276 | runApexTestCase(t, Bp2buildTestCase{ |
| 277 | Description: "apex - example with compile_multilib=both", |
| 278 | ModuleTypeUnderTest: "apex", |
| 279 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 280 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 281 | "system/sepolicy/apex/Android.bp": ` |
| 282 | filegroup { |
| 283 | name: "com.android.apogee-file_contexts", |
| 284 | srcs: [ "apogee-file_contexts", ], |
| 285 | bazel_module: { bp2build_available: false }, |
| 286 | } |
| 287 | `, |
| 288 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 289 | Blueprint: createMultilibBlueprint(`compile_multilib: "both",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 290 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 291 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 292 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 293 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 294 | ":native_shared_lib_for_both", |
| 295 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 296 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 297 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 298 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 299 | "//conditions:default": [], |
| 300 | })`, |
| 301 | "native_shared_libs_64": `select({ |
| 302 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 303 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 304 | ":native_shared_lib_for_both", |
| 305 | ":native_shared_lib_for_lib64", |
| 306 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 307 | ], |
| 308 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 309 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 310 | ":native_shared_lib_for_both", |
| 311 | ":native_shared_lib_for_lib64", |
| 312 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 313 | ], |
| 314 | "//conditions:default": [], |
| 315 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 316 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 317 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 318 | }), |
| 319 | }}) |
| 320 | } |
| 321 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 322 | func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) { |
| 323 | expectedBazelTargets := []string{ |
| 324 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 325 | "native_shared_libs_32": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 326 | "//build/bazel/platforms/arch:arm": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 327 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 328 | ":native_shared_lib_for_both", |
| 329 | ":native_shared_lib_for_lib32", |
| 330 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 331 | ], |
| 332 | "//build/bazel/platforms/arch:x86": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 333 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 334 | ":native_shared_lib_for_both", |
| 335 | ":native_shared_lib_for_lib32", |
| 336 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 337 | ], |
| 338 | "//conditions:default": [], |
| 339 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 340 | "native_shared_libs_64": `select({ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 341 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 342 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 343 | ":native_shared_lib_for_both", |
| 344 | ":native_shared_lib_for_lib64", |
| 345 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 346 | ], |
| 347 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 348 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 349 | ":native_shared_lib_for_both", |
| 350 | ":native_shared_lib_for_lib64", |
| 351 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 352 | ], |
| 353 | "//conditions:default": [], |
| 354 | })`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 355 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 356 | "manifest": `"apex_manifest.json"`, |
| 357 | }), |
| 358 | } |
| 359 | |
| 360 | // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib |
| 361 | // should result to the same bp2build output |
| 362 | compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""} |
| 363 | for _, compileMultiLibProp := range compileMultiLibPropValues { |
| 364 | descriptionSuffix := compileMultiLibProp |
| 365 | if descriptionSuffix == "" { |
| 366 | descriptionSuffix = "compile_multilib unset" |
| 367 | } |
| 368 | runApexTestCase(t, Bp2buildTestCase{ |
| 369 | Description: "apex - example with " + compileMultiLibProp, |
| 370 | ModuleTypeUnderTest: "apex", |
| 371 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 372 | Filesystem: map[string]string{ |
| 373 | "system/sepolicy/apex/Android.bp": ` |
| 374 | filegroup { |
| 375 | name: "com.android.apogee-file_contexts", |
| 376 | srcs: [ "apogee-file_contexts", ], |
| 377 | bazel_module: { bp2build_available: false }, |
| 378 | } |
| 379 | `, |
| 380 | }, |
| 381 | Blueprint: createMultilibBlueprint(compileMultiLibProp), |
| 382 | ExpectedBazelTargets: expectedBazelTargets, |
| 383 | }) |
| 384 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | func TestApexBundleCompileMultilib32(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 388 | runApexTestCase(t, Bp2buildTestCase{ |
| 389 | Description: "apex - example with compile_multilib=32", |
| 390 | ModuleTypeUnderTest: "apex", |
| 391 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 392 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 393 | "system/sepolicy/apex/Android.bp": ` |
| 394 | filegroup { |
| 395 | name: "com.android.apogee-file_contexts", |
| 396 | srcs: [ "apogee-file_contexts", ], |
| 397 | bazel_module: { bp2build_available: false }, |
| 398 | } |
| 399 | `, |
| 400 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 401 | Blueprint: createMultilibBlueprint(`compile_multilib: "32",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 402 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 403 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 404 | "native_shared_libs_32": `[ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 405 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 406 | ":native_shared_lib_for_both", |
| 407 | ":native_shared_lib_for_lib32", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 408 | ] + select({ |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 409 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], |
| 410 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 411 | "//conditions:default": [], |
| 412 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 413 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 414 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 415 | }), |
| 416 | }}) |
| 417 | } |
| 418 | |
| 419 | func TestApexBundleCompileMultilib64(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 420 | runApexTestCase(t, Bp2buildTestCase{ |
| 421 | Description: "apex - example with compile_multilib=64", |
| 422 | ModuleTypeUnderTest: "apex", |
| 423 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 424 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 425 | "system/sepolicy/apex/Android.bp": ` |
| 426 | filegroup { |
| 427 | name: "com.android.apogee-file_contexts", |
| 428 | srcs: [ "apogee-file_contexts", ], |
| 429 | bazel_module: { bp2build_available: false }, |
| 430 | } |
| 431 | `, |
| 432 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 433 | Blueprint: createMultilibBlueprint(`compile_multilib: "64",`), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 434 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 435 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 436 | "native_shared_libs_64": `select({ |
| 437 | "//build/bazel/platforms/arch:arm64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 438 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 439 | ":native_shared_lib_for_both", |
| 440 | ":native_shared_lib_for_lib64", |
| 441 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 442 | ], |
| 443 | "//build/bazel/platforms/arch:x86_64": [ |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 444 | ":unnested_native_shared_lib", |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 445 | ":native_shared_lib_for_both", |
| 446 | ":native_shared_lib_for_lib64", |
| 447 | ":native_shared_lib_for_first", |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 448 | ], |
| 449 | "//conditions:default": [], |
| 450 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 451 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 452 | "manifest": `"apex_manifest.json"`, |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 453 | }), |
| 454 | }}) |
| 455 | } |
| 456 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 457 | func createMultilibBlueprint(compile_multilib string) string { |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 458 | return fmt.Sprintf(` |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 459 | cc_library { |
| 460 | name: "native_shared_lib_for_both", |
| 461 | bazel_module: { bp2build_available: false }, |
| 462 | } |
| 463 | |
| 464 | cc_library { |
| 465 | name: "native_shared_lib_for_first", |
| 466 | bazel_module: { bp2build_available: false }, |
| 467 | } |
| 468 | |
| 469 | cc_library { |
| 470 | name: "native_shared_lib_for_lib32", |
| 471 | bazel_module: { bp2build_available: false }, |
| 472 | } |
| 473 | |
| 474 | cc_library { |
| 475 | name: "native_shared_lib_for_lib64", |
| 476 | bazel_module: { bp2build_available: false }, |
| 477 | } |
| 478 | |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 479 | cc_library { |
| 480 | name: "unnested_native_shared_lib", |
| 481 | bazel_module: { bp2build_available: false }, |
| 482 | } |
| 483 | |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 484 | apex { |
| 485 | name: "com.android.apogee", |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 486 | %s |
| 487 | native_shared_libs: ["unnested_native_shared_lib"], |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 488 | multilib: { |
| 489 | both: { |
| 490 | native_shared_libs: [ |
| 491 | "native_shared_lib_for_both", |
| 492 | ], |
| 493 | }, |
| 494 | first: { |
| 495 | native_shared_libs: [ |
| 496 | "native_shared_lib_for_first", |
| 497 | ], |
| 498 | }, |
| 499 | lib32: { |
| 500 | native_shared_libs: [ |
| 501 | "native_shared_lib_for_lib32", |
| 502 | ], |
| 503 | }, |
| 504 | lib64: { |
| 505 | native_shared_libs: [ |
| 506 | "native_shared_lib_for_lib64", |
| 507 | ], |
| 508 | }, |
| 509 | }, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 510 | }`, compile_multilib) |
Jingwen Chen | 34feb14 | 2022-10-06 13:02:30 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 513 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 514 | runApexTestCase(t, Bp2buildTestCase{ |
| 515 | Description: "apex - default property values", |
| 516 | ModuleTypeUnderTest: "apex", |
| 517 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 518 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 519 | "system/sepolicy/apex/Android.bp": ` |
| 520 | filegroup { |
| 521 | name: "com.android.apogee-file_contexts", |
| 522 | srcs: [ "apogee-file_contexts", ], |
| 523 | bazel_module: { bp2build_available: false }, |
| 524 | } |
| 525 | `, |
| 526 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 527 | Blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 528 | apex { |
| 529 | name: "com.android.apogee", |
| 530 | manifest: "apogee_manifest.json", |
| 531 | } |
| 532 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 533 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 534 | "manifest": `"apogee_manifest.json"`, |
| 535 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 536 | }), |
| 537 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 538 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 539 | |
| 540 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 541 | runApexTestCase(t, Bp2buildTestCase{ |
| 542 | Description: "apex - has bazel module props", |
| 543 | ModuleTypeUnderTest: "apex", |
| 544 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 545 | Filesystem: map[string]string{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 546 | "system/sepolicy/apex/Android.bp": ` |
| 547 | filegroup { |
| 548 | name: "apogee-file_contexts", |
| 549 | srcs: [ "apogee-file_contexts", ], |
| 550 | bazel_module: { bp2build_available: false }, |
| 551 | } |
| 552 | `, |
| 553 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 554 | Blueprint: ` |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 555 | apex { |
| 556 | name: "apogee", |
| 557 | manifest: "manifest.json", |
| 558 | bazel_module: { bp2build_available: true }, |
| 559 | } |
| 560 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 561 | ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 562 | "manifest": `"manifest.json"`, |
| 563 | "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 564 | }), |
| 565 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 566 | } |
Yu Liu | 4ae55d1 | 2022-01-05 17:17:23 -0800 | [diff] [blame] | 567 | |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 568 | func TestBp2BuildOverrideApex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 569 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 570 | Description: "override_apex", |
| 571 | ModuleTypeUnderTest: "override_apex", |
| 572 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 573 | Filesystem: map[string]string{}, |
| 574 | Blueprint: ` |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 575 | apex_key { |
| 576 | name: "com.android.apogee.key", |
| 577 | public_key: "com.android.apogee.avbpubkey", |
| 578 | private_key: "com.android.apogee.pem", |
| 579 | bazel_module: { bp2build_available: false }, |
| 580 | } |
| 581 | |
| 582 | android_app_certificate { |
| 583 | name: "com.android.apogee.certificate", |
| 584 | certificate: "com.android.apogee", |
| 585 | bazel_module: { bp2build_available: false }, |
| 586 | } |
| 587 | |
| 588 | cc_library { |
| 589 | name: "native_shared_lib_1", |
| 590 | bazel_module: { bp2build_available: false }, |
| 591 | } |
| 592 | |
| 593 | cc_library { |
| 594 | name: "native_shared_lib_2", |
| 595 | bazel_module: { bp2build_available: false }, |
| 596 | } |
| 597 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 598 | prebuilt_etc { |
| 599 | name: "prebuilt_1", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 600 | bazel_module: { bp2build_available: false }, |
| 601 | } |
| 602 | |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 603 | prebuilt_etc { |
| 604 | name: "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 605 | bazel_module: { bp2build_available: false }, |
| 606 | } |
| 607 | |
| 608 | filegroup { |
| 609 | name: "com.android.apogee-file_contexts", |
| 610 | srcs: [ |
| 611 | "com.android.apogee-file_contexts", |
| 612 | ], |
| 613 | bazel_module: { bp2build_available: false }, |
| 614 | } |
| 615 | |
| 616 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 617 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 618 | |
| 619 | apex { |
| 620 | name: "com.android.apogee", |
| 621 | manifest: "apogee_manifest.json", |
| 622 | androidManifest: "ApogeeAndroidManifest.xml", |
| 623 | file_contexts: ":com.android.apogee-file_contexts", |
| 624 | min_sdk_version: "29", |
| 625 | key: "com.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 626 | certificate: ":com.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 627 | updatable: false, |
| 628 | installable: false, |
| 629 | compressible: false, |
| 630 | native_shared_libs: [ |
| 631 | "native_shared_lib_1", |
| 632 | "native_shared_lib_2", |
| 633 | ], |
| 634 | binaries: [ |
| 635 | "cc_binary_1", |
| 636 | "sh_binary_2", |
| 637 | ], |
| 638 | prebuilts: [ |
Jingwen Chen | 81c67d3 | 2022-06-08 16:08:25 +0000 | [diff] [blame] | 639 | "prebuilt_1", |
| 640 | "prebuilt_2", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 641 | ], |
| 642 | bazel_module: { bp2build_available: false }, |
| 643 | } |
| 644 | |
| 645 | apex_key { |
| 646 | name: "com.google.android.apogee.key", |
| 647 | public_key: "com.google.android.apogee.avbpubkey", |
| 648 | private_key: "com.google.android.apogee.pem", |
| 649 | bazel_module: { bp2build_available: false }, |
| 650 | } |
| 651 | |
| 652 | android_app_certificate { |
| 653 | name: "com.google.android.apogee.certificate", |
| 654 | certificate: "com.google.android.apogee", |
| 655 | bazel_module: { bp2build_available: false }, |
| 656 | } |
| 657 | |
| 658 | override_apex { |
| 659 | name: "com.google.android.apogee", |
| 660 | base: ":com.android.apogee", |
| 661 | key: "com.google.android.apogee.key", |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 662 | certificate: ":com.google.android.apogee.certificate", |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 663 | prebuilts: [], |
| 664 | compressible: true, |
| 665 | } |
| 666 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 667 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 668 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 669 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 670 | "base_apex_name": `"com.android.apogee"`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 671 | "binaries": `[ |
| 672 | ":cc_binary_1", |
| 673 | ":sh_binary_2", |
| 674 | ]`, |
| 675 | "certificate": `":com.google.android.apogee.certificate"`, |
| 676 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 677 | "installable": "False", |
| 678 | "key": `":com.google.android.apogee.key"`, |
| 679 | "manifest": `"apogee_manifest.json"`, |
| 680 | "min_sdk_version": `"29"`, |
Vinh Tran | 8f5310f | 2022-10-07 18:16:47 -0400 | [diff] [blame] | 681 | "native_shared_libs_32": `select({ |
| 682 | "//build/bazel/platforms/arch:arm": [ |
| 683 | ":native_shared_lib_1", |
| 684 | ":native_shared_lib_2", |
| 685 | ], |
| 686 | "//build/bazel/platforms/arch:x86": [ |
| 687 | ":native_shared_lib_1", |
| 688 | ":native_shared_lib_2", |
| 689 | ], |
| 690 | "//conditions:default": [], |
| 691 | })`, |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 692 | "native_shared_libs_64": `select({ |
| 693 | "//build/bazel/platforms/arch:arm64": [ |
| 694 | ":native_shared_lib_1", |
| 695 | ":native_shared_lib_2", |
| 696 | ], |
| 697 | "//build/bazel/platforms/arch:x86_64": [ |
| 698 | ":native_shared_lib_1", |
| 699 | ":native_shared_lib_2", |
| 700 | ], |
| 701 | "//conditions:default": [], |
| 702 | })`, |
| 703 | "prebuilts": `[]`, |
| 704 | "updatable": "False", |
| 705 | "compressible": "True", |
| 706 | }), |
| 707 | }}) |
| 708 | } |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 709 | |
Liz Kammer | 1a1c9df | 2023-03-28 11:39:50 -0400 | [diff] [blame] | 710 | func TestOverrideApexTest(t *testing.T) { |
| 711 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 712 | Description: "override_apex", |
| 713 | ModuleTypeUnderTest: "override_apex", |
| 714 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 715 | Filesystem: map[string]string{}, |
| 716 | Blueprint: ` |
| 717 | apex_key { |
| 718 | name: "com.android.apogee.key", |
| 719 | public_key: "com.android.apogee.avbpubkey", |
| 720 | private_key: "com.android.apogee.pem", |
| 721 | bazel_module: { bp2build_available: false }, |
| 722 | } |
| 723 | |
| 724 | android_app_certificate { |
| 725 | name: "com.android.apogee.certificate", |
| 726 | certificate: "com.android.apogee", |
| 727 | bazel_module: { bp2build_available: false }, |
| 728 | } |
| 729 | |
| 730 | cc_library { |
| 731 | name: "native_shared_lib_1", |
| 732 | bazel_module: { bp2build_available: false }, |
| 733 | } |
| 734 | |
| 735 | prebuilt_etc { |
| 736 | name: "prebuilt_1", |
| 737 | bazel_module: { bp2build_available: false }, |
| 738 | } |
| 739 | |
| 740 | filegroup { |
| 741 | name: "com.android.apogee-file_contexts", |
| 742 | srcs: [ |
| 743 | "com.android.apogee-file_contexts", |
| 744 | ], |
| 745 | bazel_module: { bp2build_available: false }, |
| 746 | } |
| 747 | |
| 748 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 749 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 750 | |
| 751 | apex_test { |
| 752 | name: "com.android.apogee", |
| 753 | manifest: "apogee_manifest.json", |
| 754 | androidManifest: "ApogeeAndroidManifest.xml", |
| 755 | file_contexts: ":com.android.apogee-file_contexts", |
| 756 | min_sdk_version: "29", |
| 757 | key: "com.android.apogee.key", |
| 758 | certificate: ":com.android.apogee.certificate", |
| 759 | updatable: false, |
| 760 | installable: false, |
| 761 | compressible: false, |
| 762 | native_shared_libs: [ |
| 763 | "native_shared_lib_1", |
| 764 | ], |
| 765 | binaries: [ |
| 766 | "cc_binary_1", |
| 767 | "sh_binary_2", |
| 768 | ], |
| 769 | prebuilts: [ |
| 770 | "prebuilt_1", |
| 771 | ], |
| 772 | bazel_module: { bp2build_available: false }, |
| 773 | } |
| 774 | |
| 775 | apex_key { |
| 776 | name: "com.google.android.apogee.key", |
| 777 | public_key: "com.google.android.apogee.avbpubkey", |
| 778 | private_key: "com.google.android.apogee.pem", |
| 779 | bazel_module: { bp2build_available: false }, |
| 780 | } |
| 781 | |
| 782 | android_app_certificate { |
| 783 | name: "com.google.android.apogee.certificate", |
| 784 | certificate: "com.google.android.apogee", |
| 785 | bazel_module: { bp2build_available: false }, |
| 786 | } |
| 787 | |
| 788 | override_apex { |
| 789 | name: "com.google.android.apogee", |
| 790 | base: ":com.android.apogee", |
| 791 | key: "com.google.android.apogee.key", |
| 792 | certificate: ":com.google.android.apogee.certificate", |
| 793 | prebuilts: [], |
| 794 | compressible: true, |
| 795 | } |
| 796 | `, |
| 797 | ExpectedBazelTargets: []string{ |
| 798 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
| 799 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 800 | "base_apex_name": `"com.android.apogee"`, |
| 801 | "binaries": `[ |
| 802 | ":cc_binary_1", |
| 803 | ":sh_binary_2", |
| 804 | ]`, |
| 805 | "certificate": `":com.google.android.apogee.certificate"`, |
| 806 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 807 | "installable": "False", |
| 808 | "key": `":com.google.android.apogee.key"`, |
| 809 | "manifest": `"apogee_manifest.json"`, |
| 810 | "min_sdk_version": `"29"`, |
| 811 | "native_shared_libs_32": `select({ |
| 812 | "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"], |
| 813 | "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"], |
| 814 | "//conditions:default": [], |
| 815 | })`, |
| 816 | "native_shared_libs_64": `select({ |
| 817 | "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"], |
| 818 | "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"], |
| 819 | "//conditions:default": [], |
| 820 | })`, |
| 821 | "testonly": "True", |
| 822 | "prebuilts": `[]`, |
| 823 | "updatable": "False", |
| 824 | "compressible": "True", |
| 825 | }), |
| 826 | }}) |
| 827 | } |
| 828 | |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 829 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 830 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 831 | Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", |
| 832 | ModuleTypeUnderTest: "override_apex", |
| 833 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 834 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 835 | "system/sepolicy/apex/Android.bp": ` |
| 836 | filegroup { |
| 837 | name: "com.android.apogee-file_contexts", |
| 838 | srcs: [ "apogee-file_contexts", ], |
| 839 | bazel_module: { bp2build_available: false }, |
| 840 | }`, |
| 841 | "a/b/Android.bp": ` |
| 842 | apex { |
| 843 | name: "com.android.apogee", |
| 844 | bazel_module: { bp2build_available: false }, |
| 845 | } |
| 846 | `, |
| 847 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 848 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 849 | override_apex { |
| 850 | name: "com.google.android.apogee", |
| 851 | base: ":com.android.apogee", |
| 852 | } |
| 853 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 854 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 855 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 856 | "base_apex_name": `"com.android.apogee"`, |
| 857 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 858 | "manifest": `"//a/b:apex_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 859 | }), |
| 860 | }}) |
| 861 | } |
| 862 | |
| 863 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 864 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 865 | Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", |
| 866 | ModuleTypeUnderTest: "override_apex", |
| 867 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 868 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 869 | "system/sepolicy/apex/Android.bp": ` |
| 870 | filegroup { |
| 871 | name: "com.android.apogee-file_contexts", |
| 872 | srcs: [ "apogee-file_contexts", ], |
| 873 | bazel_module: { bp2build_available: false }, |
| 874 | }`, |
| 875 | "a/b/Android.bp": ` |
| 876 | apex { |
| 877 | name: "com.android.apogee", |
| 878 | manifest: "apogee_manifest.json", |
| 879 | bazel_module: { bp2build_available: false }, |
| 880 | } |
| 881 | `, |
| 882 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 883 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 884 | override_apex { |
| 885 | name: "com.google.android.apogee", |
| 886 | base: ":com.android.apogee", |
| 887 | } |
| 888 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 889 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 890 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 891 | "base_apex_name": `"com.android.apogee"`, |
| 892 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 893 | "manifest": `"//a/b:apogee_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 894 | }), |
| 895 | }}) |
| 896 | } |
| 897 | |
| 898 | func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 899 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 900 | Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", |
| 901 | ModuleTypeUnderTest: "override_apex", |
| 902 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 903 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 904 | "system/sepolicy/apex/Android.bp": ` |
| 905 | filegroup { |
| 906 | name: "com.android.apogee-file_contexts", |
| 907 | srcs: [ "apogee-file_contexts", ], |
| 908 | bazel_module: { bp2build_available: false }, |
| 909 | }`, |
| 910 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 911 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 912 | apex { |
| 913 | name: "com.android.apogee", |
| 914 | bazel_module: { bp2build_available: false }, |
| 915 | } |
| 916 | |
| 917 | override_apex { |
| 918 | name: "com.google.android.apogee", |
| 919 | base: ":com.android.apogee", |
| 920 | } |
| 921 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 922 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 923 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 924 | "base_apex_name": `"com.android.apogee"`, |
| 925 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 926 | "manifest": `"apex_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 927 | }), |
| 928 | }}) |
| 929 | } |
| 930 | |
| 931 | func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 932 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 933 | Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", |
| 934 | ModuleTypeUnderTest: "override_apex", |
| 935 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 936 | Filesystem: map[string]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 937 | "system/sepolicy/apex/Android.bp": ` |
| 938 | filegroup { |
| 939 | name: "com.android.apogee-file_contexts", |
| 940 | srcs: [ "apogee-file_contexts", ], |
| 941 | bazel_module: { bp2build_available: false }, |
| 942 | }`, |
| 943 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 944 | Blueprint: ` |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 945 | apex { |
| 946 | name: "com.android.apogee", |
| 947 | manifest: "apogee_manifest.json", |
| 948 | bazel_module: { bp2build_available: false }, |
| 949 | } |
| 950 | |
| 951 | override_apex { |
| 952 | name: "com.google.android.apogee", |
| 953 | base: ":com.android.apogee", |
| 954 | } |
| 955 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 956 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 957 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 958 | "base_apex_name": `"com.android.apogee"`, |
| 959 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 960 | "manifest": `"apogee_manifest.json"`, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 961 | }), |
| 962 | }}) |
| 963 | } |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 964 | |
| 965 | func TestApexBundleSimple_packageNameOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 966 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 967 | Description: "override_apex - override package name", |
| 968 | ModuleTypeUnderTest: "override_apex", |
| 969 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 970 | Filesystem: map[string]string{ |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 971 | "system/sepolicy/apex/Android.bp": ` |
| 972 | filegroup { |
| 973 | name: "com.android.apogee-file_contexts", |
| 974 | srcs: [ "apogee-file_contexts", ], |
| 975 | bazel_module: { bp2build_available: false }, |
| 976 | }`, |
| 977 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 978 | Blueprint: ` |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 979 | apex { |
| 980 | name: "com.android.apogee", |
| 981 | bazel_module: { bp2build_available: false }, |
| 982 | } |
| 983 | |
| 984 | override_apex { |
| 985 | name: "com.google.android.apogee", |
| 986 | base: ":com.android.apogee", |
| 987 | package_name: "com.google.android.apogee", |
| 988 | } |
| 989 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 990 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 991 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 992 | "base_apex_name": `"com.android.apogee"`, |
| 993 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 994 | "manifest": `"apex_manifest.json"`, |
| 995 | "package_name": `"com.google.android.apogee"`, |
Jingwen Chen | 9b7ebca | 2022-06-03 09:11:20 +0000 | [diff] [blame] | 996 | }), |
| 997 | }}) |
| 998 | } |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 999 | |
| 1000 | func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1001 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1002 | Description: "override_apex - no override", |
| 1003 | ModuleTypeUnderTest: "override_apex", |
| 1004 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1005 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1006 | "system/sepolicy/apex/Android.bp": ` |
| 1007 | filegroup { |
| 1008 | name: "com.android.apogee-file_contexts", |
| 1009 | srcs: [ "apogee-file_contexts", ], |
| 1010 | bazel_module: { bp2build_available: false }, |
| 1011 | }`, |
| 1012 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1013 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1014 | prebuilt_etc { |
| 1015 | name: "prebuilt_file", |
| 1016 | bazel_module: { bp2build_available: false }, |
| 1017 | } |
| 1018 | |
| 1019 | apex { |
| 1020 | name: "com.android.apogee", |
| 1021 | bazel_module: { bp2build_available: false }, |
| 1022 | prebuilts: ["prebuilt_file"] |
| 1023 | } |
| 1024 | |
| 1025 | override_apex { |
| 1026 | name: "com.google.android.apogee", |
| 1027 | base: ":com.android.apogee", |
| 1028 | } |
| 1029 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1030 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1031 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1032 | "base_apex_name": `"com.android.apogee"`, |
| 1033 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1034 | "manifest": `"apex_manifest.json"`, |
| 1035 | "prebuilts": `[":prebuilt_file"]`, |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1036 | }), |
| 1037 | }}) |
| 1038 | } |
| 1039 | |
| 1040 | func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1041 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1042 | Description: "override_apex - ooverride", |
| 1043 | ModuleTypeUnderTest: "override_apex", |
| 1044 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1045 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1046 | "system/sepolicy/apex/Android.bp": ` |
| 1047 | filegroup { |
| 1048 | name: "com.android.apogee-file_contexts", |
| 1049 | srcs: [ "apogee-file_contexts", ], |
| 1050 | bazel_module: { bp2build_available: false }, |
| 1051 | }`, |
| 1052 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1053 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1054 | prebuilt_etc { |
| 1055 | name: "prebuilt_file", |
| 1056 | bazel_module: { bp2build_available: false }, |
| 1057 | } |
| 1058 | |
| 1059 | prebuilt_etc { |
| 1060 | name: "prebuilt_file2", |
| 1061 | bazel_module: { bp2build_available: false }, |
| 1062 | } |
| 1063 | |
| 1064 | apex { |
| 1065 | name: "com.android.apogee", |
| 1066 | bazel_module: { bp2build_available: false }, |
| 1067 | prebuilts: ["prebuilt_file"] |
| 1068 | } |
| 1069 | |
| 1070 | override_apex { |
| 1071 | name: "com.google.android.apogee", |
| 1072 | base: ":com.android.apogee", |
| 1073 | prebuilts: ["prebuilt_file2"] |
| 1074 | } |
| 1075 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1076 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1077 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1078 | "base_apex_name": `"com.android.apogee"`, |
| 1079 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1080 | "manifest": `"apex_manifest.json"`, |
| 1081 | "prebuilts": `[":prebuilt_file2"]`, |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1082 | }), |
| 1083 | }}) |
| 1084 | } |
| 1085 | |
| 1086 | func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1087 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1088 | Description: "override_apex - override with empty list", |
| 1089 | ModuleTypeUnderTest: "override_apex", |
| 1090 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1091 | Filesystem: map[string]string{ |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1092 | "system/sepolicy/apex/Android.bp": ` |
| 1093 | filegroup { |
| 1094 | name: "com.android.apogee-file_contexts", |
| 1095 | srcs: [ "apogee-file_contexts", ], |
| 1096 | bazel_module: { bp2build_available: false }, |
| 1097 | }`, |
| 1098 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1099 | Blueprint: ` |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1100 | prebuilt_etc { |
| 1101 | name: "prebuilt_file", |
| 1102 | bazel_module: { bp2build_available: false }, |
| 1103 | } |
| 1104 | |
| 1105 | apex { |
| 1106 | name: "com.android.apogee", |
| 1107 | bazel_module: { bp2build_available: false }, |
| 1108 | prebuilts: ["prebuilt_file"] |
| 1109 | } |
| 1110 | |
| 1111 | override_apex { |
| 1112 | name: "com.google.android.apogee", |
| 1113 | base: ":com.android.apogee", |
| 1114 | prebuilts: [], |
| 1115 | } |
| 1116 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1117 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1118 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1119 | "base_apex_name": `"com.android.apogee"`, |
| 1120 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1121 | "manifest": `"apex_manifest.json"`, |
| 1122 | "prebuilts": `[]`, |
Jingwen Chen | df165c9 | 2022-06-08 16:00:39 +0000 | [diff] [blame] | 1123 | }), |
| 1124 | }}) |
| 1125 | } |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1126 | |
| 1127 | func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1128 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1129 | Description: "override_apex - logging_parent - no override", |
| 1130 | ModuleTypeUnderTest: "override_apex", |
| 1131 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1132 | Filesystem: map[string]string{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1133 | "system/sepolicy/apex/Android.bp": ` |
| 1134 | filegroup { |
| 1135 | name: "com.android.apogee-file_contexts", |
| 1136 | srcs: [ "apogee-file_contexts", ], |
| 1137 | bazel_module: { bp2build_available: false }, |
| 1138 | }`, |
| 1139 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1140 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1141 | apex { |
| 1142 | name: "com.android.apogee", |
| 1143 | bazel_module: { bp2build_available: false }, |
| 1144 | logging_parent: "foo.bar.baz", |
| 1145 | } |
| 1146 | |
| 1147 | override_apex { |
| 1148 | name: "com.google.android.apogee", |
| 1149 | base: ":com.android.apogee", |
| 1150 | } |
| 1151 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1152 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1153 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1154 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1155 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1156 | "manifest": `"apex_manifest.json"`, |
| 1157 | "logging_parent": `"foo.bar.baz"`, |
| 1158 | }), |
| 1159 | }}) |
| 1160 | } |
| 1161 | |
| 1162 | func TestApexBundleSimple_LoggingParentOverride(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1163 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1164 | Description: "override_apex - logging_parent - override", |
| 1165 | ModuleTypeUnderTest: "override_apex", |
| 1166 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1167 | Filesystem: map[string]string{ |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1168 | "system/sepolicy/apex/Android.bp": ` |
| 1169 | filegroup { |
| 1170 | name: "com.android.apogee-file_contexts", |
| 1171 | srcs: [ "apogee-file_contexts", ], |
| 1172 | bazel_module: { bp2build_available: false }, |
| 1173 | }`, |
| 1174 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1175 | Blueprint: ` |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1176 | apex { |
| 1177 | name: "com.android.apogee", |
| 1178 | bazel_module: { bp2build_available: false }, |
| 1179 | logging_parent: "foo.bar.baz", |
| 1180 | } |
| 1181 | |
| 1182 | override_apex { |
| 1183 | name: "com.google.android.apogee", |
| 1184 | base: ":com.android.apogee", |
| 1185 | logging_parent: "foo.bar.baz.override", |
| 1186 | } |
| 1187 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1188 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1189 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1190 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | b732d7c | 2022-06-10 08:14:19 +0000 | [diff] [blame] | 1191 | "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, |
| 1192 | "manifest": `"apex_manifest.json"`, |
| 1193 | "logging_parent": `"foo.bar.baz.override"`, |
| 1194 | }), |
| 1195 | }}) |
| 1196 | } |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1197 | |
| 1198 | func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) { |
| 1199 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1200 | Description: "override_apex - don't set default certificate", |
| 1201 | ModuleTypeUnderTest: "override_apex", |
| 1202 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1203 | Filesystem: map[string]string{}, |
| 1204 | Blueprint: ` |
| 1205 | android_app_certificate { |
| 1206 | name: "com.android.apogee.certificate", |
| 1207 | certificate: "com.android.apogee", |
| 1208 | bazel_module: { bp2build_available: false }, |
| 1209 | } |
| 1210 | |
| 1211 | filegroup { |
| 1212 | name: "com.android.apogee-file_contexts", |
| 1213 | srcs: [ |
| 1214 | "com.android.apogee-file_contexts", |
| 1215 | ], |
| 1216 | bazel_module: { bp2build_available: false }, |
| 1217 | } |
| 1218 | |
| 1219 | apex { |
| 1220 | name: "com.android.apogee", |
| 1221 | manifest: "apogee_manifest.json", |
| 1222 | file_contexts: ":com.android.apogee-file_contexts", |
| 1223 | certificate: ":com.android.apogee.certificate", |
| 1224 | bazel_module: { bp2build_available: false }, |
| 1225 | } |
| 1226 | |
| 1227 | override_apex { |
| 1228 | name: "com.google.android.apogee", |
| 1229 | base: ":com.android.apogee", |
| 1230 | // certificate is deliberately omitted, and not converted to bazel, |
| 1231 | // because the overridden apex shouldn't be using the base apex's cert. |
| 1232 | } |
| 1233 | `, |
| 1234 | ExpectedBazelTargets: []string{ |
| 1235 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1236 | "base_apex_name": `"com.android.apogee"`, |
| 1237 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1238 | "manifest": `"apogee_manifest.json"`, |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1239 | }), |
| 1240 | }}) |
| 1241 | } |
| 1242 | |
| 1243 | func TestApexCertificateIsModule(t *testing.T) { |
| 1244 | runApexTestCase(t, Bp2buildTestCase{ |
| 1245 | Description: "apex - certificate is module", |
| 1246 | ModuleTypeUnderTest: "apex", |
| 1247 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1248 | Filesystem: map[string]string{}, |
| 1249 | Blueprint: ` |
| 1250 | android_app_certificate { |
| 1251 | name: "com.android.apogee.certificate", |
| 1252 | certificate: "com.android.apogee", |
| 1253 | bazel_module: { bp2build_available: false }, |
| 1254 | } |
| 1255 | |
| 1256 | apex { |
| 1257 | name: "com.android.apogee", |
| 1258 | manifest: "apogee_manifest.json", |
| 1259 | file_contexts: ":com.android.apogee-file_contexts", |
| 1260 | certificate: ":com.android.apogee.certificate", |
| 1261 | } |
| 1262 | ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
| 1263 | ExpectedBazelTargets: []string{ |
| 1264 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 1265 | "certificate": `":com.android.apogee.certificate"`, |
| 1266 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1267 | "manifest": `"apogee_manifest.json"`, |
| 1268 | }), |
| 1269 | }}) |
| 1270 | } |
| 1271 | |
Vinh Tran | 55225e3 | 2022-12-20 10:38:48 -0500 | [diff] [blame] | 1272 | func TestApexWithStubLib(t *testing.T) { |
| 1273 | runApexTestCase(t, Bp2buildTestCase{ |
| 1274 | Description: "apex - static variant of stub lib should not have apex_available tag", |
| 1275 | ModuleTypeUnderTest: "apex", |
| 1276 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1277 | Filesystem: map[string]string{}, |
| 1278 | Blueprint: ` |
| 1279 | cc_library{ |
| 1280 | name: "foo", |
| 1281 | stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] }, |
| 1282 | apex_available: ["myapex"], |
| 1283 | } |
| 1284 | |
| 1285 | cc_binary{ |
| 1286 | name: "bar", |
| 1287 | static_libs: ["foo"], |
| 1288 | apex_available: ["myapex"], |
| 1289 | } |
| 1290 | |
| 1291 | apex { |
| 1292 | name: "myapex", |
| 1293 | manifest: "myapex_manifest.json", |
| 1294 | file_contexts: ":myapex-file_contexts", |
| 1295 | binaries: ["bar"], |
| 1296 | native_shared_libs: ["foo"], |
| 1297 | } |
| 1298 | ` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"), |
| 1299 | ExpectedBazelTargets: []string{ |
| 1300 | MakeBazelTarget("cc_binary", "bar", AttrNameToString{ |
| 1301 | "local_includes": `["."]`, |
| 1302 | "deps": `[":foo_bp2build_cc_library_static"]`, |
| 1303 | "tags": `["apex_available=myapex"]`, |
| 1304 | }), |
| 1305 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 1306 | "local_includes": `["."]`, |
| 1307 | }), |
| 1308 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1309 | "local_includes": `["."]`, |
| 1310 | "stubs_symbol_file": `"foo.map.txt"`, |
| 1311 | "tags": `["apex_available=myapex"]`, |
| 1312 | }), |
| 1313 | MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{ |
Sam Delmerico | 5f90649 | 2023-03-15 18:06:18 -0400 | [diff] [blame] | 1314 | "soname": `"foo.so"`, |
| 1315 | "source_library_label": `"//:foo"`, |
| 1316 | "symbol_file": `"foo.map.txt"`, |
Vinh Tran | 55225e3 | 2022-12-20 10:38:48 -0500 | [diff] [blame] | 1317 | "versions": `[ |
| 1318 | "28", |
| 1319 | "29", |
| 1320 | "current", |
| 1321 | ]`, |
| 1322 | }), |
| 1323 | MakeBazelTarget("apex", "myapex", AttrNameToString{ |
| 1324 | "file_contexts": `":myapex-file_contexts"`, |
| 1325 | "manifest": `"myapex_manifest.json"`, |
| 1326 | "binaries": `[":bar"]`, |
| 1327 | "native_shared_libs_32": `select({ |
| 1328 | "//build/bazel/platforms/arch:arm": [":foo"], |
| 1329 | "//build/bazel/platforms/arch:x86": [":foo"], |
| 1330 | "//conditions:default": [], |
| 1331 | })`, |
| 1332 | "native_shared_libs_64": `select({ |
| 1333 | "//build/bazel/platforms/arch:arm64": [":foo"], |
| 1334 | "//build/bazel/platforms/arch:x86_64": [":foo"], |
| 1335 | "//conditions:default": [], |
| 1336 | })`, |
| 1337 | }), |
| 1338 | }, |
| 1339 | }) |
| 1340 | } |
| 1341 | |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1342 | func TestApexCertificateIsSrc(t *testing.T) { |
| 1343 | runApexTestCase(t, Bp2buildTestCase{ |
| 1344 | Description: "apex - certificate is src", |
| 1345 | ModuleTypeUnderTest: "apex", |
| 1346 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1347 | Filesystem: map[string]string{}, |
| 1348 | Blueprint: ` |
| 1349 | apex { |
| 1350 | name: "com.android.apogee", |
| 1351 | manifest: "apogee_manifest.json", |
| 1352 | file_contexts: ":com.android.apogee-file_contexts", |
| 1353 | certificate: "com.android.apogee.certificate", |
| 1354 | } |
| 1355 | ` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), |
| 1356 | ExpectedBazelTargets: []string{ |
| 1357 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 1358 | "certificate_name": `"com.android.apogee.certificate"`, |
| 1359 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1360 | "manifest": `"apogee_manifest.json"`, |
| 1361 | }), |
| 1362 | }}) |
| 1363 | } |
| 1364 | |
| 1365 | func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) { |
| 1366 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1367 | Description: "override_apex - certificate is module", |
| 1368 | ModuleTypeUnderTest: "override_apex", |
| 1369 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1370 | Filesystem: map[string]string{}, |
| 1371 | Blueprint: ` |
| 1372 | android_app_certificate { |
| 1373 | name: "com.android.apogee.certificate", |
| 1374 | certificate: "com.android.apogee", |
| 1375 | bazel_module: { bp2build_available: false }, |
| 1376 | } |
| 1377 | |
| 1378 | filegroup { |
| 1379 | name: "com.android.apogee-file_contexts", |
| 1380 | srcs: [ |
| 1381 | "com.android.apogee-file_contexts", |
| 1382 | ], |
| 1383 | bazel_module: { bp2build_available: false }, |
| 1384 | } |
| 1385 | |
| 1386 | apex { |
| 1387 | name: "com.android.apogee", |
| 1388 | manifest: "apogee_manifest.json", |
| 1389 | file_contexts: ":com.android.apogee-file_contexts", |
| 1390 | certificate: ":com.android.apogee.certificate", |
| 1391 | bazel_module: { bp2build_available: false }, |
| 1392 | } |
| 1393 | |
| 1394 | android_app_certificate { |
| 1395 | name: "com.google.android.apogee.certificate", |
| 1396 | certificate: "com.google.android.apogee", |
| 1397 | bazel_module: { bp2build_available: false }, |
| 1398 | } |
| 1399 | |
| 1400 | override_apex { |
| 1401 | name: "com.google.android.apogee", |
| 1402 | base: ":com.android.apogee", |
| 1403 | certificate: ":com.google.android.apogee.certificate", |
| 1404 | } |
| 1405 | `, |
| 1406 | ExpectedBazelTargets: []string{ |
| 1407 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1408 | "base_apex_name": `"com.android.apogee"`, |
| 1409 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1410 | "certificate": `":com.google.android.apogee.certificate"`, |
| 1411 | "manifest": `"apogee_manifest.json"`, |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1412 | }), |
| 1413 | }}) |
| 1414 | } |
| 1415 | |
| 1416 | func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) { |
| 1417 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1418 | Description: "override_apex - certificate is src", |
| 1419 | ModuleTypeUnderTest: "override_apex", |
| 1420 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1421 | Filesystem: map[string]string{}, |
| 1422 | Blueprint: ` |
| 1423 | android_app_certificate { |
| 1424 | name: "com.android.apogee.certificate", |
| 1425 | certificate: "com.android.apogee", |
| 1426 | bazel_module: { bp2build_available: false }, |
| 1427 | } |
| 1428 | |
| 1429 | filegroup { |
| 1430 | name: "com.android.apogee-file_contexts", |
| 1431 | srcs: [ |
| 1432 | "com.android.apogee-file_contexts", |
| 1433 | ], |
| 1434 | bazel_module: { bp2build_available: false }, |
| 1435 | } |
| 1436 | |
| 1437 | apex { |
| 1438 | name: "com.android.apogee", |
| 1439 | manifest: "apogee_manifest.json", |
| 1440 | file_contexts: ":com.android.apogee-file_contexts", |
| 1441 | certificate: ":com.android.apogee.certificate", |
| 1442 | bazel_module: { bp2build_available: false }, |
| 1443 | } |
| 1444 | |
| 1445 | override_apex { |
| 1446 | name: "com.google.android.apogee", |
| 1447 | base: ":com.android.apogee", |
| 1448 | certificate: "com.google.android.apogee.certificate", |
| 1449 | } |
| 1450 | `, |
| 1451 | ExpectedBazelTargets: []string{ |
| 1452 | MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 1453 | "base_apex_name": `"com.android.apogee"`, |
Jingwen Chen | bea5809 | 2022-09-29 16:56:02 +0000 | [diff] [blame] | 1454 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 1455 | "certificate_name": `"com.google.android.apogee.certificate"`, |
| 1456 | "manifest": `"apogee_manifest.json"`, |
| 1457 | }), |
| 1458 | }}) |
| 1459 | } |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 1460 | |
| 1461 | func TestApexTestBundleSimple(t *testing.T) { |
| 1462 | runApexTestCase(t, Bp2buildTestCase{ |
| 1463 | Description: "apex_test - simple", |
| 1464 | ModuleTypeUnderTest: "apex_test", |
| 1465 | ModuleTypeUnderTestFactory: apex.TestApexBundleFactory, |
| 1466 | Filesystem: map[string]string{}, |
| 1467 | Blueprint: ` |
| 1468 | cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } } |
| 1469 | |
| 1470 | apex_test { |
| 1471 | name: "test_com.android.apogee", |
| 1472 | file_contexts: "file_contexts_file", |
| 1473 | tests: ["cc_test_1"], |
| 1474 | } |
| 1475 | `, |
| 1476 | ExpectedBazelTargets: []string{ |
| 1477 | MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{ |
| 1478 | "file_contexts": `"file_contexts_file"`, |
| 1479 | "manifest": `"apex_manifest.json"`, |
| 1480 | "testonly": `True`, |
| 1481 | "tests": `[":cc_test_1"]`, |
| 1482 | }), |
| 1483 | }}) |
| 1484 | } |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 1485 | |
| 1486 | func TestApexBundle_overridePlusProductVars(t *testing.T) { |
| 1487 | // Reproduction of b/271424349 |
| 1488 | // Tests that overriding an apex that uses product variables correctly copies the product var |
| 1489 | // selects over to the override. |
| 1490 | runOverrideApexTestCase(t, Bp2buildTestCase{ |
| 1491 | Description: "apex - overriding a module that uses product vars", |
| 1492 | ModuleTypeUnderTest: "override_apex", |
| 1493 | ModuleTypeUnderTestFactory: apex.OverrideApexFactory, |
| 1494 | Blueprint: ` |
| 1495 | soong_config_string_variable { |
| 1496 | name: "library_linking_strategy", |
| 1497 | values: [ |
| 1498 | "prefer_static", |
| 1499 | ], |
| 1500 | } |
| 1501 | |
| 1502 | soong_config_module_type { |
| 1503 | name: "library_linking_strategy_apex_defaults", |
| 1504 | module_type: "apex_defaults", |
| 1505 | config_namespace: "ANDROID", |
| 1506 | variables: ["library_linking_strategy"], |
| 1507 | properties: [ |
| 1508 | "manifest", |
| 1509 | "min_sdk_version", |
| 1510 | ], |
| 1511 | } |
| 1512 | |
| 1513 | library_linking_strategy_apex_defaults { |
| 1514 | name: "higher_min_sdk_when_prefer_static", |
| 1515 | soong_config_variables: { |
| 1516 | library_linking_strategy: { |
| 1517 | // Use the R min_sdk_version |
| 1518 | prefer_static: {}, |
| 1519 | // Override the R min_sdk_version to min_sdk_version that supports dcla |
| 1520 | conditions_default: { |
| 1521 | min_sdk_version: "31", |
| 1522 | }, |
| 1523 | }, |
| 1524 | }, |
| 1525 | } |
| 1526 | |
| 1527 | filegroup { |
| 1528 | name: "foo-file_contexts", |
| 1529 | srcs: [ |
| 1530 | "com.android.apogee-file_contexts", |
| 1531 | ], |
| 1532 | bazel_module: { bp2build_available: false }, |
| 1533 | } |
| 1534 | |
| 1535 | apex { |
| 1536 | name: "foo", |
| 1537 | defaults: ["higher_min_sdk_when_prefer_static"], |
| 1538 | min_sdk_version: "30", |
| 1539 | package_name: "pkg_name", |
| 1540 | file_contexts: ":foo-file_contexts", |
| 1541 | } |
| 1542 | override_apex { |
| 1543 | name: "override_foo", |
| 1544 | base: ":foo", |
| 1545 | package_name: "override_pkg_name", |
| 1546 | } |
| 1547 | `, |
| 1548 | ExpectedBazelTargets: []string{ |
| 1549 | MakeBazelTarget("apex", "foo", AttrNameToString{ |
| 1550 | "file_contexts": `":foo-file_contexts"`, |
| 1551 | "manifest": `"apex_manifest.json"`, |
| 1552 | "min_sdk_version": `select({ |
| 1553 | "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30", |
| 1554 | "//conditions:default": "31", |
| 1555 | })`, |
| 1556 | "package_name": `"pkg_name"`, |
| 1557 | }), MakeBazelTarget("apex", "override_foo", AttrNameToString{ |
| 1558 | "base_apex_name": `"foo"`, |
| 1559 | "file_contexts": `":foo-file_contexts"`, |
| 1560 | "manifest": `"apex_manifest.json"`, |
| 1561 | "min_sdk_version": `select({ |
| 1562 | "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30", |
| 1563 | "//conditions:default": "31", |
| 1564 | })`, |
| 1565 | "package_name": `"override_pkg_name"`, |
| 1566 | }), |
| 1567 | }}) |
| 1568 | } |
Jingwen Chen | a8623da | 2023-03-28 13:05:02 +0000 | [diff] [blame] | 1569 | |
| 1570 | func TestApexBundleSimple_customCannedFsConfig(t *testing.T) { |
| 1571 | runApexTestCase(t, Bp2buildTestCase{ |
| 1572 | Description: "apex - custom canned_fs_config", |
| 1573 | ModuleTypeUnderTest: "apex", |
| 1574 | ModuleTypeUnderTestFactory: apex.BundleFactory, |
| 1575 | Filesystem: map[string]string{}, |
| 1576 | Blueprint: ` |
| 1577 | apex { |
| 1578 | name: "com.android.apogee", |
| 1579 | canned_fs_config: "custom.canned_fs_config", |
| 1580 | file_contexts: "file_contexts_file", |
| 1581 | } |
| 1582 | `, |
| 1583 | ExpectedBazelTargets: []string{ |
| 1584 | MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ |
| 1585 | "canned_fs_config": `"custom.canned_fs_config"`, |
| 1586 | "file_contexts": `"file_contexts_file"`, |
| 1587 | "manifest": `"apex_manifest.json"`, |
| 1588 | }), |
| 1589 | }}) |
| 1590 | } |