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