Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 1 | // Copyright 2024 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 apex |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/aconfig/codegen" |
| 21 | "android/soong/android" |
| 22 | "android/soong/cc" |
| 23 | "android/soong/genrule" |
| 24 | "android/soong/java" |
| 25 | "android/soong/rust" |
Dennis Shen | 6a7ffb3 | 2024-05-22 21:40:15 +0000 | [diff] [blame] | 26 | |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
| 30 | var withAconfigValidationError = android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 31 | variables.AconfigContainerValidation = "error" |
| 32 | variables.BuildId = proptools.StringPtr("TEST.BUILD_ID") |
| 33 | }) |
| 34 | |
| 35 | func TestValidationAcrossContainersExportedPass(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 36 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 37 | testCases := []struct { |
| 38 | name string |
| 39 | bp string |
| 40 | }{ |
| 41 | { |
| 42 | name: "Java lib passes for exported containers cross", |
| 43 | bp: apex_default_bp + ` |
| 44 | apex { |
| 45 | name: "myapex", |
| 46 | manifest: ":myapex.manifest", |
| 47 | androidManifest: ":myapex.androidmanifest", |
| 48 | key: "myapex.key", |
| 49 | java_libs: [ |
| 50 | "my_java_library_foo", |
| 51 | ], |
| 52 | updatable: false, |
| 53 | } |
| 54 | java_library { |
| 55 | name: "my_java_library_foo", |
| 56 | srcs: ["foo/bar/MyClass.java"], |
| 57 | sdk_version: "none", |
| 58 | system_modules: "none", |
| 59 | static_libs: ["my_java_aconfig_library_foo"], |
| 60 | apex_available: [ |
| 61 | "myapex", |
| 62 | ], |
| 63 | } |
| 64 | aconfig_declarations { |
| 65 | name: "my_aconfig_declarations_foo", |
| 66 | package: "com.example.package", |
| 67 | container: "otherapex", |
| 68 | srcs: ["foo.aconfig"], |
| 69 | exportable: true, |
| 70 | } |
| 71 | java_aconfig_library { |
| 72 | name: "my_java_aconfig_library_foo", |
| 73 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 74 | mode: "exported", |
| 75 | apex_available: [ |
| 76 | "myapex", |
| 77 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 78 | sdk_version: "none", |
| 79 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 80 | }`, |
| 81 | }, |
| 82 | { |
| 83 | name: "Android app passes for exported containers cross", |
| 84 | bp: apex_default_bp + ` |
| 85 | apex { |
| 86 | name: "myapex", |
| 87 | manifest: ":myapex.manifest", |
| 88 | androidManifest: ":myapex.androidmanifest", |
| 89 | key: "myapex.key", |
| 90 | apps: [ |
| 91 | "my_android_app_foo", |
| 92 | ], |
| 93 | updatable: false, |
| 94 | } |
| 95 | android_app { |
| 96 | name: "my_android_app_foo", |
| 97 | srcs: ["foo/MyClass.java"], |
| 98 | sdk_version: "none", |
| 99 | system_modules: "none", |
| 100 | stl: "none", |
| 101 | static_libs: ["my_java_library_bar"], |
| 102 | apex_available: [ "myapex" ], |
| 103 | } |
| 104 | java_library { |
| 105 | name: "my_java_library_bar", |
| 106 | srcs: ["foo/bar/MyClass.java"], |
| 107 | sdk_version: "none", |
| 108 | system_modules: "none", |
| 109 | static_libs: ["my_java_aconfig_library_bar"], |
| 110 | apex_available: [ |
| 111 | "myapex", |
| 112 | ], |
| 113 | } |
| 114 | aconfig_declarations { |
| 115 | name: "my_aconfig_declarations_bar", |
| 116 | package: "com.example.package", |
| 117 | container: "otherapex", |
| 118 | srcs: ["bar.aconfig"], |
| 119 | exportable: true, |
| 120 | } |
| 121 | java_aconfig_library { |
| 122 | name: "my_java_aconfig_library_bar", |
| 123 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 124 | mode: "exported", |
| 125 | apex_available: [ |
| 126 | "myapex", |
| 127 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 128 | sdk_version: "none", |
| 129 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 130 | }`, |
| 131 | }, |
| 132 | { |
| 133 | name: "Cc lib passes for exported containers cross", |
| 134 | bp: apex_default_bp + ` |
| 135 | apex { |
| 136 | name: "myapex", |
| 137 | manifest: ":myapex.manifest", |
| 138 | androidManifest: ":myapex.androidmanifest", |
| 139 | key: "myapex.key", |
| 140 | native_shared_libs: [ |
| 141 | "my_cc_library_bar", |
| 142 | ], |
| 143 | binaries: [ |
| 144 | "my_cc_binary_baz", |
| 145 | ], |
| 146 | updatable: false, |
| 147 | } |
| 148 | cc_library { |
| 149 | name: "my_cc_library_bar", |
| 150 | srcs: ["foo/bar/MyClass.cc"], |
| 151 | static_libs: [ |
| 152 | "my_cc_aconfig_library_bar", |
| 153 | "my_cc_aconfig_library_baz", |
| 154 | ], |
| 155 | apex_available: [ |
| 156 | "myapex", |
| 157 | ], |
| 158 | } |
| 159 | cc_binary { |
| 160 | name: "my_cc_binary_baz", |
| 161 | srcs: ["foo/bar/MyClass.cc"], |
| 162 | static_libs: ["my_cc_aconfig_library_baz"], |
| 163 | apex_available: [ |
| 164 | "myapex", |
| 165 | ], |
| 166 | } |
| 167 | cc_library { |
| 168 | name: "server_configurable_flags", |
| 169 | srcs: ["server_configurable_flags.cc"], |
| 170 | } |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 171 | cc_library { |
| 172 | name: "libbase", |
| 173 | srcs: ["libbase.cc"], |
Ted Bauer | 1e96f8c | 2024-04-25 19:50:01 +0000 | [diff] [blame] | 174 | apex_available: [ |
| 175 | "myapex", |
| 176 | ], |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 177 | } |
| 178 | cc_library { |
| 179 | name: "libaconfig_storage_read_api_cc", |
| 180 | srcs: ["libaconfig_storage_read_api_cc.cc"], |
| 181 | } |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 182 | aconfig_declarations { |
| 183 | name: "my_aconfig_declarations_bar", |
| 184 | package: "com.example.package", |
| 185 | container: "otherapex", |
| 186 | srcs: ["bar.aconfig"], |
| 187 | exportable: true, |
| 188 | } |
| 189 | cc_aconfig_library { |
| 190 | name: "my_cc_aconfig_library_bar", |
| 191 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 192 | apex_available: [ |
| 193 | "myapex", |
| 194 | ], |
| 195 | mode: "exported", |
| 196 | } |
| 197 | aconfig_declarations { |
| 198 | name: "my_aconfig_declarations_baz", |
| 199 | package: "com.example.package", |
| 200 | container: "otherapex", |
| 201 | srcs: ["baz.aconfig"], |
| 202 | exportable: true, |
| 203 | } |
| 204 | cc_aconfig_library { |
| 205 | name: "my_cc_aconfig_library_baz", |
| 206 | aconfig_declarations: "my_aconfig_declarations_baz", |
| 207 | apex_available: [ |
| 208 | "myapex", |
| 209 | ], |
| 210 | mode: "exported", |
| 211 | }`, |
| 212 | }, |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 213 | { |
| 214 | name: "Rust lib passes for exported containers cross", |
| 215 | bp: apex_default_bp + ` |
| 216 | apex { |
| 217 | name: "myapex", |
| 218 | manifest: ":myapex.manifest", |
| 219 | androidManifest: ":myapex.androidmanifest", |
| 220 | key: "myapex.key", |
| 221 | native_shared_libs: ["libmy_rust_library"], |
| 222 | binaries: ["my_rust_binary"], |
| 223 | updatable: false, |
| 224 | } |
| 225 | rust_library { |
| 226 | name: "libflags_rust", // test mock |
| 227 | crate_name: "flags_rust", |
| 228 | srcs: ["lib.rs"], |
| 229 | apex_available: ["myapex"], |
| 230 | } |
| 231 | rust_library { |
| 232 | name: "liblazy_static", // test mock |
| 233 | crate_name: "lazy_static", |
| 234 | srcs: ["src/lib.rs"], |
| 235 | apex_available: ["myapex"], |
| 236 | } |
Ted Bauer | 02d475c | 2024-03-27 20:56:26 +0000 | [diff] [blame] | 237 | rust_library { |
| 238 | name: "libaconfig_storage_read_api", // test mock |
| 239 | crate_name: "aconfig_storage_read_api", |
| 240 | srcs: ["src/lib.rs"], |
| 241 | apex_available: ["myapex"], |
| 242 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame] | 243 | rust_library { |
| 244 | name: "liblogger", // test mock |
| 245 | crate_name: "logger", |
| 246 | srcs: ["src/lib.rs"], |
| 247 | apex_available: ["myapex"], |
| 248 | } |
| 249 | rust_library { |
| 250 | name: "liblog_rust", // test mock |
| 251 | crate_name: "log_rust", |
| 252 | srcs: ["src/lib.rs"], |
| 253 | apex_available: ["myapex"], |
| 254 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 255 | rust_ffi_shared { |
| 256 | name: "libmy_rust_library", |
| 257 | srcs: ["src/lib.rs"], |
| 258 | rustlibs: ["libmy_rust_aconfig_library_foo"], |
| 259 | crate_name: "my_rust_library", |
| 260 | apex_available: ["myapex"], |
| 261 | } |
| 262 | rust_binary { |
| 263 | name: "my_rust_binary", |
| 264 | srcs: ["foo/bar/MyClass.rs"], |
| 265 | rustlibs: ["libmy_rust_aconfig_library_bar"], |
| 266 | apex_available: ["myapex"], |
| 267 | } |
| 268 | aconfig_declarations { |
| 269 | name: "my_aconfig_declarations_foo", |
| 270 | package: "com.example.package", |
| 271 | container: "otherapex", |
| 272 | srcs: ["foo.aconfig"], |
| 273 | } |
| 274 | aconfig_declarations { |
| 275 | name: "my_aconfig_declarations_bar", |
| 276 | package: "com.example.package", |
| 277 | container: "otherapex", |
| 278 | srcs: ["bar.aconfig"], |
| 279 | } |
| 280 | rust_aconfig_library { |
| 281 | name: "libmy_rust_aconfig_library_foo", |
| 282 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 283 | crate_name: "my_rust_aconfig_library_foo", |
| 284 | apex_available: ["myapex"], |
| 285 | mode: "exported", |
| 286 | } |
| 287 | rust_aconfig_library { |
| 288 | name: "libmy_rust_aconfig_library_bar", |
| 289 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 290 | crate_name: "my_rust_aconfig_library_bar", |
| 291 | apex_available: ["myapex"], |
| 292 | mode: "exported", |
| 293 | }`, |
| 294 | }, |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 295 | } |
| 296 | for _, test := range testCases { |
| 297 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 298 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 299 | android.GroupFixturePreparers( |
| 300 | java.PrepareForTestWithJavaDefaultModules, |
| 301 | cc.PrepareForTestWithCcBuildComponents, |
| 302 | rust.PrepareForTestWithRustDefaultModules, |
| 303 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 304 | PrepareForTestWithApexBuildComponents, |
| 305 | prepareForTestWithMyapex, |
| 306 | withAconfigValidationError, |
| 307 | ). |
| 308 | RunTestWithBp(t, test.bp) |
| 309 | }) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func TestValidationAcrossContainersNotExportedFail(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 314 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 315 | testCases := []struct { |
| 316 | name string |
| 317 | expectedError string |
| 318 | bp string |
| 319 | }{ |
| 320 | { |
| 321 | name: "Java lib fails for non-exported containers cross", |
| 322 | bp: apex_default_bp + ` |
| 323 | apex { |
| 324 | name: "myapex", |
| 325 | manifest: ":myapex.manifest", |
| 326 | androidManifest: ":myapex.androidmanifest", |
| 327 | key: "myapex.key", |
| 328 | java_libs: [ |
| 329 | "my_java_library_foo", |
| 330 | ], |
| 331 | updatable: false, |
| 332 | } |
| 333 | java_library { |
| 334 | name: "my_java_library_foo", |
| 335 | srcs: ["foo/bar/MyClass.java"], |
| 336 | sdk_version: "none", |
| 337 | system_modules: "none", |
| 338 | static_libs: ["my_java_aconfig_library_foo"], |
| 339 | apex_available: [ |
| 340 | "myapex", |
| 341 | ], |
| 342 | } |
| 343 | aconfig_declarations { |
| 344 | name: "my_aconfig_declarations_foo", |
| 345 | package: "com.example.package", |
| 346 | container: "otherapex", |
| 347 | srcs: ["foo.aconfig"], |
| 348 | } |
| 349 | java_aconfig_library { |
| 350 | name: "my_java_aconfig_library_foo", |
| 351 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 352 | apex_available: [ |
| 353 | "myapex", |
| 354 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 355 | sdk_version: "none", |
| 356 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 357 | }`, |
| 358 | expectedError: `.*my_java_library_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 359 | }, |
| 360 | { |
| 361 | name: "Android app fails for non-exported containers cross", |
| 362 | bp: apex_default_bp + ` |
| 363 | apex { |
| 364 | name: "myapex", |
| 365 | manifest: ":myapex.manifest", |
| 366 | androidManifest: ":myapex.androidmanifest", |
| 367 | key: "myapex.key", |
| 368 | apps: [ |
| 369 | "my_android_app_foo", |
| 370 | ], |
| 371 | updatable: false, |
| 372 | } |
| 373 | android_app { |
| 374 | name: "my_android_app_foo", |
| 375 | srcs: ["foo/MyClass.java"], |
| 376 | sdk_version: "none", |
| 377 | system_modules: "none", |
| 378 | stl: "none", |
| 379 | static_libs: ["my_java_library_foo"], |
| 380 | apex_available: [ "myapex" ], |
| 381 | } |
| 382 | java_library { |
| 383 | name: "my_java_library_foo", |
| 384 | srcs: ["foo/bar/MyClass.java"], |
| 385 | sdk_version: "none", |
| 386 | system_modules: "none", |
| 387 | static_libs: ["my_java_aconfig_library_foo"], |
| 388 | apex_available: [ |
| 389 | "myapex", |
| 390 | ], |
| 391 | } |
| 392 | aconfig_declarations { |
| 393 | name: "my_aconfig_declarations_foo", |
| 394 | package: "com.example.package", |
| 395 | container: "otherapex", |
| 396 | srcs: ["bar.aconfig"], |
| 397 | } |
| 398 | java_aconfig_library { |
| 399 | name: "my_java_aconfig_library_foo", |
| 400 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 401 | apex_available: [ |
| 402 | "myapex", |
| 403 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 404 | sdk_version: "none", |
| 405 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 406 | }`, |
| 407 | expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 408 | }, |
| 409 | { |
| 410 | name: "Cc lib fails for non-exported containers cross", |
| 411 | bp: apex_default_bp + ` |
| 412 | apex { |
| 413 | name: "myapex", |
| 414 | manifest: ":myapex.manifest", |
| 415 | androidManifest: ":myapex.androidmanifest", |
| 416 | key: "myapex.key", |
| 417 | native_shared_libs: [ |
| 418 | "my_cc_library_foo", |
| 419 | ], |
| 420 | updatable: false, |
| 421 | } |
| 422 | cc_library { |
| 423 | name: "my_cc_library_foo", |
| 424 | srcs: ["foo/bar/MyClass.cc"], |
| 425 | shared_libs: [ |
| 426 | "my_cc_aconfig_library_foo", |
| 427 | ], |
| 428 | apex_available: [ |
| 429 | "myapex", |
| 430 | ], |
| 431 | } |
| 432 | cc_library { |
| 433 | name: "server_configurable_flags", |
| 434 | srcs: ["server_configurable_flags.cc"], |
| 435 | } |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 436 | cc_library { |
| 437 | name: "libbase", |
| 438 | srcs: ["libbase.cc"], |
Ted Bauer | 1e96f8c | 2024-04-25 19:50:01 +0000 | [diff] [blame] | 439 | apex_available: [ |
| 440 | "myapex", |
| 441 | ], |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 442 | } |
| 443 | cc_library { |
| 444 | name: "libaconfig_storage_read_api_cc", |
| 445 | srcs: ["libaconfig_storage_read_api_cc.cc"], |
| 446 | } |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 447 | aconfig_declarations { |
| 448 | name: "my_aconfig_declarations_foo", |
| 449 | package: "com.example.package", |
| 450 | container: "otherapex", |
| 451 | srcs: ["foo.aconfig"], |
| 452 | } |
| 453 | cc_aconfig_library { |
| 454 | name: "my_cc_aconfig_library_foo", |
| 455 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 456 | apex_available: [ |
| 457 | "myapex", |
| 458 | ], |
| 459 | }`, |
| 460 | expectedError: `.*my_cc_library_foo/myapex depends on my_cc_aconfig_library_foo/otherapex/production across containers`, |
| 461 | }, |
| 462 | { |
| 463 | name: "Cc binary fails for non-exported containers cross", |
| 464 | bp: apex_default_bp + ` |
| 465 | apex { |
| 466 | name: "myapex", |
| 467 | manifest: ":myapex.manifest", |
| 468 | androidManifest: ":myapex.androidmanifest", |
| 469 | key: "myapex.key", |
| 470 | binaries: [ |
| 471 | "my_cc_binary_foo", |
| 472 | ], |
| 473 | updatable: false, |
| 474 | } |
| 475 | cc_library { |
| 476 | name: "my_cc_library_foo", |
| 477 | srcs: ["foo/bar/MyClass.cc"], |
| 478 | static_libs: [ |
| 479 | "my_cc_aconfig_library_foo", |
| 480 | ], |
| 481 | apex_available: [ |
| 482 | "myapex", |
| 483 | ], |
| 484 | } |
| 485 | cc_binary { |
| 486 | name: "my_cc_binary_foo", |
| 487 | srcs: ["foo/bar/MyClass.cc"], |
| 488 | static_libs: ["my_cc_library_foo"], |
| 489 | apex_available: [ |
| 490 | "myapex", |
| 491 | ], |
| 492 | } |
| 493 | cc_library { |
| 494 | name: "server_configurable_flags", |
| 495 | srcs: ["server_configurable_flags.cc"], |
| 496 | } |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 497 | cc_library { |
| 498 | name: "libbase", |
| 499 | srcs: ["libbase.cc"], |
Ted Bauer | 1e96f8c | 2024-04-25 19:50:01 +0000 | [diff] [blame] | 500 | apex_available: [ |
| 501 | "myapex", |
| 502 | ], |
Ted Bauer | f0f1859 | 2024-04-23 18:25:26 +0000 | [diff] [blame] | 503 | } |
| 504 | cc_library { |
| 505 | name: "libaconfig_storage_read_api_cc", |
| 506 | srcs: ["libaconfig_storage_read_api_cc.cc"], |
| 507 | } |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 508 | aconfig_declarations { |
| 509 | name: "my_aconfig_declarations_foo", |
| 510 | package: "com.example.package", |
| 511 | container: "otherapex", |
| 512 | srcs: ["foo.aconfig"], |
| 513 | } |
| 514 | cc_aconfig_library { |
| 515 | name: "my_cc_aconfig_library_foo", |
| 516 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 517 | apex_available: [ |
| 518 | "myapex", |
| 519 | ], |
| 520 | }`, |
| 521 | expectedError: `.*my_cc_binary_foo/myapex depends on my_cc_aconfig_library_foo/otherapex/production across containers`, |
| 522 | }, |
| 523 | { |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 524 | name: "Rust lib fails for non-exported containers cross", |
| 525 | bp: apex_default_bp + ` |
| 526 | apex { |
| 527 | name: "myapex", |
| 528 | manifest: ":myapex.manifest", |
| 529 | androidManifest: ":myapex.androidmanifest", |
| 530 | key: "myapex.key", |
| 531 | native_shared_libs: ["libmy_rust_library"], |
| 532 | updatable: false, |
| 533 | } |
| 534 | rust_library { |
| 535 | name: "libflags_rust", // test mock |
| 536 | crate_name: "flags_rust", |
| 537 | srcs: ["lib.rs"], |
| 538 | apex_available: ["myapex"], |
| 539 | } |
| 540 | rust_library { |
| 541 | name: "liblazy_static", // test mock |
| 542 | crate_name: "lazy_static", |
| 543 | srcs: ["src/lib.rs"], |
| 544 | apex_available: ["myapex"], |
| 545 | } |
Ted Bauer | 02d475c | 2024-03-27 20:56:26 +0000 | [diff] [blame] | 546 | rust_library { |
| 547 | name: "libaconfig_storage_read_api", // test mock |
| 548 | crate_name: "aconfig_storage_read_api", |
| 549 | srcs: ["src/lib.rs"], |
| 550 | apex_available: ["myapex"], |
| 551 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame] | 552 | rust_library { |
| 553 | name: "liblogger", // test mock |
| 554 | crate_name: "logger", |
| 555 | srcs: ["src/lib.rs"], |
| 556 | apex_available: ["myapex"], |
| 557 | } |
| 558 | rust_library { |
| 559 | name: "liblog_rust", // test mock |
| 560 | crate_name: "log_rust", |
| 561 | srcs: ["src/lib.rs"], |
| 562 | apex_available: ["myapex"], |
| 563 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 564 | rust_ffi_shared { |
| 565 | name: "libmy_rust_library", |
| 566 | srcs: ["src/lib.rs"], |
| 567 | rustlibs: ["libmy_rust_aconfig_library_foo"], |
| 568 | crate_name: "my_rust_library", |
| 569 | apex_available: ["myapex"], |
| 570 | } |
| 571 | aconfig_declarations { |
| 572 | name: "my_aconfig_declarations_foo", |
| 573 | package: "com.example.package", |
| 574 | container: "otherapex", |
| 575 | srcs: ["foo.aconfig"], |
| 576 | } |
| 577 | rust_aconfig_library { |
| 578 | name: "libmy_rust_aconfig_library_foo", |
| 579 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 580 | crate_name: "my_rust_aconfig_library_foo", |
| 581 | apex_available: ["myapex"], |
| 582 | }`, |
| 583 | expectedError: `.*libmy_rust_aconfig_library_foo/myapex depends on libmy_rust_aconfig_library_foo/otherapex/production across containers`, |
| 584 | }, |
| 585 | { |
| 586 | name: "Rust binary fails for non-exported containers cross", |
| 587 | bp: apex_default_bp + ` |
| 588 | apex { |
| 589 | name: "myapex", |
| 590 | manifest: ":myapex.manifest", |
| 591 | androidManifest: ":myapex.androidmanifest", |
| 592 | key: "myapex.key", |
| 593 | binaries: ["my_rust_binary"], |
| 594 | updatable: false, |
| 595 | } |
| 596 | rust_library { |
| 597 | name: "libflags_rust", // test mock |
| 598 | crate_name: "flags_rust", |
| 599 | srcs: ["lib.rs"], |
| 600 | apex_available: ["myapex"], |
| 601 | } |
| 602 | rust_library { |
| 603 | name: "liblazy_static", // test mock |
| 604 | crate_name: "lazy_static", |
| 605 | srcs: ["src/lib.rs"], |
| 606 | apex_available: ["myapex"], |
| 607 | } |
Ted Bauer | 02d475c | 2024-03-27 20:56:26 +0000 | [diff] [blame] | 608 | rust_library { |
| 609 | name: "libaconfig_storage_read_api", // test mock |
| 610 | crate_name: "aconfig_storage_read_api", |
| 611 | srcs: ["src/lib.rs"], |
| 612 | apex_available: ["myapex"], |
| 613 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame] | 614 | rust_library { |
| 615 | name: "liblogger", // test mock |
| 616 | crate_name: "logger", |
| 617 | srcs: ["src/lib.rs"], |
| 618 | apex_available: ["myapex"], |
| 619 | } |
| 620 | rust_library { |
| 621 | name: "liblog_rust", // test mock |
| 622 | crate_name: "log_rust", |
| 623 | srcs: ["src/lib.rs"], |
| 624 | apex_available: ["myapex"], |
| 625 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 626 | rust_binary { |
| 627 | name: "my_rust_binary", |
| 628 | srcs: ["foo/bar/MyClass.rs"], |
| 629 | rustlibs: ["libmy_rust_aconfig_library_bar"], |
| 630 | apex_available: ["myapex"], |
| 631 | } |
| 632 | aconfig_declarations { |
| 633 | name: "my_aconfig_declarations_bar", |
| 634 | package: "com.example.package", |
| 635 | container: "otherapex", |
| 636 | srcs: ["bar.aconfig"], |
| 637 | } |
| 638 | rust_aconfig_library { |
| 639 | name: "libmy_rust_aconfig_library_bar", |
| 640 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 641 | crate_name: "my_rust_aconfig_library_bar", |
| 642 | apex_available: ["myapex"], |
| 643 | }`, |
| 644 | expectedError: `.*libmy_rust_aconfig_library_bar/myapex depends on libmy_rust_aconfig_library_bar/otherapex/production across containers`, |
| 645 | }, |
| 646 | { |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 647 | name: "Aconfig validation propagate along sourceOrOutputDependencyTag", |
| 648 | bp: apex_default_bp + ` |
| 649 | apex { |
| 650 | name: "myapex", |
| 651 | manifest: ":myapex.manifest", |
| 652 | androidManifest: ":myapex.androidmanifest", |
| 653 | key: "myapex.key", |
| 654 | apps: [ |
| 655 | "my_android_app_foo", |
| 656 | ], |
| 657 | updatable: false, |
| 658 | } |
| 659 | android_app { |
| 660 | name: "my_android_app_foo", |
| 661 | srcs: ["foo/MyClass.java"], |
| 662 | sdk_version: "none", |
| 663 | system_modules: "none", |
| 664 | stl: "none", |
| 665 | static_libs: ["my_java_library_foo"], |
| 666 | apex_available: [ "myapex" ], |
| 667 | } |
| 668 | java_library { |
| 669 | name: "my_java_library_foo", |
| 670 | srcs: [":my_genrule_foo"], |
| 671 | sdk_version: "none", |
| 672 | system_modules: "none", |
| 673 | apex_available: [ |
| 674 | "myapex", |
| 675 | ], |
| 676 | } |
| 677 | aconfig_declarations_group { |
| 678 | name: "my_aconfig_declarations_group_foo", |
| 679 | java_aconfig_libraries: [ |
| 680 | "my_java_aconfig_library_foo", |
| 681 | ], |
| 682 | } |
| 683 | filegroup { |
| 684 | name: "my_filegroup_foo_srcjars", |
| 685 | srcs: [ |
| 686 | ":my_aconfig_declarations_group_foo{.srcjars}", |
| 687 | ], |
| 688 | } |
| 689 | genrule { |
| 690 | name: "my_genrule_foo", |
| 691 | srcs: [":my_filegroup_foo_srcjars"], |
| 692 | cmd: "cp $(in) $(out)", |
| 693 | out: ["my_genrule_foo.srcjar"], |
| 694 | } |
| 695 | aconfig_declarations { |
| 696 | name: "my_aconfig_declarations_foo", |
| 697 | package: "com.example.package", |
| 698 | container: "otherapex", |
| 699 | srcs: ["bar.aconfig"], |
| 700 | } |
| 701 | java_aconfig_library { |
| 702 | name: "my_java_aconfig_library_foo", |
| 703 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 704 | apex_available: [ |
| 705 | "myapex", |
| 706 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 707 | sdk_version: "none", |
| 708 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 709 | }`, |
| 710 | expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 711 | }, |
| 712 | } |
| 713 | for _, test := range testCases { |
| 714 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 715 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 716 | errorHandler := android.FixtureExpectsNoErrors |
| 717 | if test.expectedError != "" { |
| 718 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
| 719 | } |
| 720 | android.GroupFixturePreparers( |
| 721 | java.PrepareForTestWithJavaDefaultModules, |
| 722 | cc.PrepareForTestWithCcBuildComponents, |
| 723 | rust.PrepareForTestWithRustDefaultModules, |
| 724 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 725 | genrule.PrepareForIntegrationTestWithGenrule, |
| 726 | PrepareForTestWithApexBuildComponents, |
| 727 | prepareForTestWithMyapex, |
| 728 | withAconfigValidationError, |
| 729 | ). |
| 730 | ExtendWithErrorHandler(errorHandler). |
| 731 | RunTestWithBp(t, test.bp) |
| 732 | }) |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | func TestValidationNotPropagateAcrossShared(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 737 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 738 | testCases := []struct { |
| 739 | name string |
| 740 | bp string |
| 741 | }{ |
| 742 | { |
| 743 | name: "Java shared lib not propagate aconfig validation", |
| 744 | bp: apex_default_bp + ` |
| 745 | apex { |
| 746 | name: "myapex", |
| 747 | manifest: ":myapex.manifest", |
| 748 | androidManifest: ":myapex.androidmanifest", |
| 749 | key: "myapex.key", |
| 750 | java_libs: [ |
| 751 | "my_java_library_bar", |
| 752 | ], |
| 753 | updatable: false, |
| 754 | } |
| 755 | java_library { |
| 756 | name: "my_java_library_bar", |
| 757 | srcs: ["foo/bar/MyClass.java"], |
| 758 | sdk_version: "none", |
| 759 | system_modules: "none", |
| 760 | libs: ["my_java_library_foo"], |
| 761 | apex_available: [ |
| 762 | "myapex", |
| 763 | ], |
| 764 | } |
| 765 | java_library { |
| 766 | name: "my_java_library_foo", |
| 767 | srcs: ["foo/bar/MyClass.java"], |
| 768 | sdk_version: "none", |
| 769 | system_modules: "none", |
| 770 | static_libs: ["my_java_aconfig_library_foo"], |
| 771 | apex_available: [ |
| 772 | "myapex", |
| 773 | ], |
| 774 | } |
| 775 | aconfig_declarations { |
| 776 | name: "my_aconfig_declarations_foo", |
| 777 | package: "com.example.package", |
| 778 | container: "otherapex", |
| 779 | srcs: ["foo.aconfig"], |
| 780 | } |
| 781 | java_aconfig_library { |
| 782 | name: "my_java_aconfig_library_foo", |
| 783 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 784 | apex_available: [ |
| 785 | "myapex", |
| 786 | ], |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 787 | sdk_version: "none", |
| 788 | system_modules: "none", |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 789 | }`, |
| 790 | }, |
| 791 | } |
| 792 | for _, test := range testCases { |
| 793 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | a2fdb61 | 2024-10-11 12:52:56 -0700 | [diff] [blame^] | 794 | t.Parallel() |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 795 | android.GroupFixturePreparers( |
| 796 | java.PrepareForTestWithJavaDefaultModules, |
| 797 | cc.PrepareForTestWithCcBuildComponents, |
| 798 | rust.PrepareForTestWithRustDefaultModules, |
| 799 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 800 | PrepareForTestWithApexBuildComponents, |
| 801 | prepareForTestWithMyapex, |
| 802 | withAconfigValidationError, |
| 803 | ). |
| 804 | RunTestWithBp(t, test.bp) |
| 805 | }) |
| 806 | } |
| 807 | } |