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 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame^] | 226 | rust_library { |
| 227 | name: "liblogger", // test mock |
| 228 | crate_name: "logger", |
| 229 | srcs: ["src/lib.rs"], |
| 230 | apex_available: ["myapex"], |
| 231 | } |
| 232 | rust_library { |
| 233 | name: "liblog_rust", // test mock |
| 234 | crate_name: "log_rust", |
| 235 | srcs: ["src/lib.rs"], |
| 236 | apex_available: ["myapex"], |
| 237 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 238 | rust_ffi_shared { |
| 239 | name: "libmy_rust_library", |
| 240 | srcs: ["src/lib.rs"], |
| 241 | rustlibs: ["libmy_rust_aconfig_library_foo"], |
| 242 | crate_name: "my_rust_library", |
| 243 | apex_available: ["myapex"], |
| 244 | } |
| 245 | rust_binary { |
| 246 | name: "my_rust_binary", |
| 247 | srcs: ["foo/bar/MyClass.rs"], |
| 248 | rustlibs: ["libmy_rust_aconfig_library_bar"], |
| 249 | apex_available: ["myapex"], |
| 250 | } |
| 251 | aconfig_declarations { |
| 252 | name: "my_aconfig_declarations_foo", |
| 253 | package: "com.example.package", |
| 254 | container: "otherapex", |
| 255 | srcs: ["foo.aconfig"], |
| 256 | } |
| 257 | aconfig_declarations { |
| 258 | name: "my_aconfig_declarations_bar", |
| 259 | package: "com.example.package", |
| 260 | container: "otherapex", |
| 261 | srcs: ["bar.aconfig"], |
| 262 | } |
| 263 | rust_aconfig_library { |
| 264 | name: "libmy_rust_aconfig_library_foo", |
| 265 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 266 | crate_name: "my_rust_aconfig_library_foo", |
| 267 | apex_available: ["myapex"], |
| 268 | mode: "exported", |
| 269 | } |
| 270 | rust_aconfig_library { |
| 271 | name: "libmy_rust_aconfig_library_bar", |
| 272 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 273 | crate_name: "my_rust_aconfig_library_bar", |
| 274 | apex_available: ["myapex"], |
| 275 | mode: "exported", |
| 276 | }`, |
| 277 | }, |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 278 | } |
| 279 | for _, test := range testCases { |
| 280 | t.Run(test.name, func(t *testing.T) { |
| 281 | android.GroupFixturePreparers( |
| 282 | java.PrepareForTestWithJavaDefaultModules, |
| 283 | cc.PrepareForTestWithCcBuildComponents, |
| 284 | rust.PrepareForTestWithRustDefaultModules, |
| 285 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 286 | PrepareForTestWithApexBuildComponents, |
| 287 | prepareForTestWithMyapex, |
| 288 | withAconfigValidationError, |
| 289 | ). |
| 290 | RunTestWithBp(t, test.bp) |
| 291 | }) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestValidationAcrossContainersNotExportedFail(t *testing.T) { |
| 296 | testCases := []struct { |
| 297 | name string |
| 298 | expectedError string |
| 299 | bp string |
| 300 | }{ |
| 301 | { |
| 302 | name: "Java lib fails for non-exported containers cross", |
| 303 | bp: apex_default_bp + ` |
| 304 | apex { |
| 305 | name: "myapex", |
| 306 | manifest: ":myapex.manifest", |
| 307 | androidManifest: ":myapex.androidmanifest", |
| 308 | key: "myapex.key", |
| 309 | java_libs: [ |
| 310 | "my_java_library_foo", |
| 311 | ], |
| 312 | updatable: false, |
| 313 | } |
| 314 | java_library { |
| 315 | name: "my_java_library_foo", |
| 316 | srcs: ["foo/bar/MyClass.java"], |
| 317 | sdk_version: "none", |
| 318 | system_modules: "none", |
| 319 | static_libs: ["my_java_aconfig_library_foo"], |
| 320 | apex_available: [ |
| 321 | "myapex", |
| 322 | ], |
| 323 | } |
| 324 | aconfig_declarations { |
| 325 | name: "my_aconfig_declarations_foo", |
| 326 | package: "com.example.package", |
| 327 | container: "otherapex", |
| 328 | srcs: ["foo.aconfig"], |
| 329 | } |
| 330 | java_aconfig_library { |
| 331 | name: "my_java_aconfig_library_foo", |
| 332 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 333 | apex_available: [ |
| 334 | "myapex", |
| 335 | ], |
| 336 | }`, |
| 337 | expectedError: `.*my_java_library_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 338 | }, |
| 339 | { |
| 340 | name: "Android app fails for non-exported containers cross", |
| 341 | bp: apex_default_bp + ` |
| 342 | apex { |
| 343 | name: "myapex", |
| 344 | manifest: ":myapex.manifest", |
| 345 | androidManifest: ":myapex.androidmanifest", |
| 346 | key: "myapex.key", |
| 347 | apps: [ |
| 348 | "my_android_app_foo", |
| 349 | ], |
| 350 | updatable: false, |
| 351 | } |
| 352 | android_app { |
| 353 | name: "my_android_app_foo", |
| 354 | srcs: ["foo/MyClass.java"], |
| 355 | sdk_version: "none", |
| 356 | system_modules: "none", |
| 357 | stl: "none", |
| 358 | static_libs: ["my_java_library_foo"], |
| 359 | apex_available: [ "myapex" ], |
| 360 | } |
| 361 | java_library { |
| 362 | name: "my_java_library_foo", |
| 363 | srcs: ["foo/bar/MyClass.java"], |
| 364 | sdk_version: "none", |
| 365 | system_modules: "none", |
| 366 | static_libs: ["my_java_aconfig_library_foo"], |
| 367 | apex_available: [ |
| 368 | "myapex", |
| 369 | ], |
| 370 | } |
| 371 | aconfig_declarations { |
| 372 | name: "my_aconfig_declarations_foo", |
| 373 | package: "com.example.package", |
| 374 | container: "otherapex", |
| 375 | srcs: ["bar.aconfig"], |
| 376 | } |
| 377 | java_aconfig_library { |
| 378 | name: "my_java_aconfig_library_foo", |
| 379 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 380 | apex_available: [ |
| 381 | "myapex", |
| 382 | ], |
| 383 | }`, |
| 384 | expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 385 | }, |
| 386 | { |
| 387 | name: "Cc lib fails for non-exported containers cross", |
| 388 | bp: apex_default_bp + ` |
| 389 | apex { |
| 390 | name: "myapex", |
| 391 | manifest: ":myapex.manifest", |
| 392 | androidManifest: ":myapex.androidmanifest", |
| 393 | key: "myapex.key", |
| 394 | native_shared_libs: [ |
| 395 | "my_cc_library_foo", |
| 396 | ], |
| 397 | updatable: false, |
| 398 | } |
| 399 | cc_library { |
| 400 | name: "my_cc_library_foo", |
| 401 | srcs: ["foo/bar/MyClass.cc"], |
| 402 | shared_libs: [ |
| 403 | "my_cc_aconfig_library_foo", |
| 404 | ], |
| 405 | apex_available: [ |
| 406 | "myapex", |
| 407 | ], |
| 408 | } |
| 409 | cc_library { |
| 410 | name: "server_configurable_flags", |
| 411 | srcs: ["server_configurable_flags.cc"], |
| 412 | } |
| 413 | aconfig_declarations { |
| 414 | name: "my_aconfig_declarations_foo", |
| 415 | package: "com.example.package", |
| 416 | container: "otherapex", |
| 417 | srcs: ["foo.aconfig"], |
| 418 | } |
| 419 | cc_aconfig_library { |
| 420 | name: "my_cc_aconfig_library_foo", |
| 421 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 422 | apex_available: [ |
| 423 | "myapex", |
| 424 | ], |
| 425 | }`, |
| 426 | expectedError: `.*my_cc_library_foo/myapex depends on my_cc_aconfig_library_foo/otherapex/production across containers`, |
| 427 | }, |
| 428 | { |
| 429 | name: "Cc binary fails for non-exported containers cross", |
| 430 | bp: apex_default_bp + ` |
| 431 | apex { |
| 432 | name: "myapex", |
| 433 | manifest: ":myapex.manifest", |
| 434 | androidManifest: ":myapex.androidmanifest", |
| 435 | key: "myapex.key", |
| 436 | binaries: [ |
| 437 | "my_cc_binary_foo", |
| 438 | ], |
| 439 | updatable: false, |
| 440 | } |
| 441 | cc_library { |
| 442 | name: "my_cc_library_foo", |
| 443 | srcs: ["foo/bar/MyClass.cc"], |
| 444 | static_libs: [ |
| 445 | "my_cc_aconfig_library_foo", |
| 446 | ], |
| 447 | apex_available: [ |
| 448 | "myapex", |
| 449 | ], |
| 450 | } |
| 451 | cc_binary { |
| 452 | name: "my_cc_binary_foo", |
| 453 | srcs: ["foo/bar/MyClass.cc"], |
| 454 | static_libs: ["my_cc_library_foo"], |
| 455 | apex_available: [ |
| 456 | "myapex", |
| 457 | ], |
| 458 | } |
| 459 | cc_library { |
| 460 | name: "server_configurable_flags", |
| 461 | srcs: ["server_configurable_flags.cc"], |
| 462 | } |
| 463 | aconfig_declarations { |
| 464 | name: "my_aconfig_declarations_foo", |
| 465 | package: "com.example.package", |
| 466 | container: "otherapex", |
| 467 | srcs: ["foo.aconfig"], |
| 468 | } |
| 469 | cc_aconfig_library { |
| 470 | name: "my_cc_aconfig_library_foo", |
| 471 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 472 | apex_available: [ |
| 473 | "myapex", |
| 474 | ], |
| 475 | }`, |
| 476 | expectedError: `.*my_cc_binary_foo/myapex depends on my_cc_aconfig_library_foo/otherapex/production across containers`, |
| 477 | }, |
| 478 | { |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 479 | name: "Rust lib fails for non-exported containers cross", |
| 480 | bp: apex_default_bp + ` |
| 481 | apex { |
| 482 | name: "myapex", |
| 483 | manifest: ":myapex.manifest", |
| 484 | androidManifest: ":myapex.androidmanifest", |
| 485 | key: "myapex.key", |
| 486 | native_shared_libs: ["libmy_rust_library"], |
| 487 | updatable: false, |
| 488 | } |
| 489 | rust_library { |
| 490 | name: "libflags_rust", // test mock |
| 491 | crate_name: "flags_rust", |
| 492 | srcs: ["lib.rs"], |
| 493 | apex_available: ["myapex"], |
| 494 | } |
| 495 | rust_library { |
| 496 | name: "liblazy_static", // test mock |
| 497 | crate_name: "lazy_static", |
| 498 | srcs: ["src/lib.rs"], |
| 499 | apex_available: ["myapex"], |
| 500 | } |
Ted Bauer | 02d475c | 2024-03-27 20:56:26 +0000 | [diff] [blame] | 501 | rust_library { |
| 502 | name: "libaconfig_storage_read_api", // test mock |
| 503 | crate_name: "aconfig_storage_read_api", |
| 504 | srcs: ["src/lib.rs"], |
| 505 | apex_available: ["myapex"], |
| 506 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame^] | 507 | rust_library { |
| 508 | name: "liblogger", // test mock |
| 509 | crate_name: "logger", |
| 510 | srcs: ["src/lib.rs"], |
| 511 | apex_available: ["myapex"], |
| 512 | } |
| 513 | rust_library { |
| 514 | name: "liblog_rust", // test mock |
| 515 | crate_name: "log_rust", |
| 516 | srcs: ["src/lib.rs"], |
| 517 | apex_available: ["myapex"], |
| 518 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 519 | rust_ffi_shared { |
| 520 | name: "libmy_rust_library", |
| 521 | srcs: ["src/lib.rs"], |
| 522 | rustlibs: ["libmy_rust_aconfig_library_foo"], |
| 523 | crate_name: "my_rust_library", |
| 524 | apex_available: ["myapex"], |
| 525 | } |
| 526 | aconfig_declarations { |
| 527 | name: "my_aconfig_declarations_foo", |
| 528 | package: "com.example.package", |
| 529 | container: "otherapex", |
| 530 | srcs: ["foo.aconfig"], |
| 531 | } |
| 532 | rust_aconfig_library { |
| 533 | name: "libmy_rust_aconfig_library_foo", |
| 534 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 535 | crate_name: "my_rust_aconfig_library_foo", |
| 536 | apex_available: ["myapex"], |
| 537 | }`, |
| 538 | expectedError: `.*libmy_rust_aconfig_library_foo/myapex depends on libmy_rust_aconfig_library_foo/otherapex/production across containers`, |
| 539 | }, |
| 540 | { |
| 541 | name: "Rust binary fails for non-exported containers cross", |
| 542 | bp: apex_default_bp + ` |
| 543 | apex { |
| 544 | name: "myapex", |
| 545 | manifest: ":myapex.manifest", |
| 546 | androidManifest: ":myapex.androidmanifest", |
| 547 | key: "myapex.key", |
| 548 | binaries: ["my_rust_binary"], |
| 549 | updatable: false, |
| 550 | } |
| 551 | rust_library { |
| 552 | name: "libflags_rust", // test mock |
| 553 | crate_name: "flags_rust", |
| 554 | srcs: ["lib.rs"], |
| 555 | apex_available: ["myapex"], |
| 556 | } |
| 557 | rust_library { |
| 558 | name: "liblazy_static", // test mock |
| 559 | crate_name: "lazy_static", |
| 560 | srcs: ["src/lib.rs"], |
| 561 | apex_available: ["myapex"], |
| 562 | } |
Ted Bauer | 02d475c | 2024-03-27 20:56:26 +0000 | [diff] [blame] | 563 | rust_library { |
| 564 | name: "libaconfig_storage_read_api", // test mock |
| 565 | crate_name: "aconfig_storage_read_api", |
| 566 | srcs: ["src/lib.rs"], |
| 567 | apex_available: ["myapex"], |
| 568 | } |
Ted Bauer | 6ef40db | 2024-03-29 14:04:10 +0000 | [diff] [blame^] | 569 | rust_library { |
| 570 | name: "liblogger", // test mock |
| 571 | crate_name: "logger", |
| 572 | srcs: ["src/lib.rs"], |
| 573 | apex_available: ["myapex"], |
| 574 | } |
| 575 | rust_library { |
| 576 | name: "liblog_rust", // test mock |
| 577 | crate_name: "log_rust", |
| 578 | srcs: ["src/lib.rs"], |
| 579 | apex_available: ["myapex"], |
| 580 | } |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 581 | rust_binary { |
| 582 | name: "my_rust_binary", |
| 583 | srcs: ["foo/bar/MyClass.rs"], |
| 584 | rustlibs: ["libmy_rust_aconfig_library_bar"], |
| 585 | apex_available: ["myapex"], |
| 586 | } |
| 587 | aconfig_declarations { |
| 588 | name: "my_aconfig_declarations_bar", |
| 589 | package: "com.example.package", |
| 590 | container: "otherapex", |
| 591 | srcs: ["bar.aconfig"], |
| 592 | } |
| 593 | rust_aconfig_library { |
| 594 | name: "libmy_rust_aconfig_library_bar", |
| 595 | aconfig_declarations: "my_aconfig_declarations_bar", |
| 596 | crate_name: "my_rust_aconfig_library_bar", |
| 597 | apex_available: ["myapex"], |
| 598 | }`, |
| 599 | expectedError: `.*libmy_rust_aconfig_library_bar/myapex depends on libmy_rust_aconfig_library_bar/otherapex/production across containers`, |
| 600 | }, |
| 601 | { |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 602 | name: "Aconfig validation propagate along sourceOrOutputDependencyTag", |
| 603 | bp: apex_default_bp + ` |
| 604 | apex { |
| 605 | name: "myapex", |
| 606 | manifest: ":myapex.manifest", |
| 607 | androidManifest: ":myapex.androidmanifest", |
| 608 | key: "myapex.key", |
| 609 | apps: [ |
| 610 | "my_android_app_foo", |
| 611 | ], |
| 612 | updatable: false, |
| 613 | } |
| 614 | android_app { |
| 615 | name: "my_android_app_foo", |
| 616 | srcs: ["foo/MyClass.java"], |
| 617 | sdk_version: "none", |
| 618 | system_modules: "none", |
| 619 | stl: "none", |
| 620 | static_libs: ["my_java_library_foo"], |
| 621 | apex_available: [ "myapex" ], |
| 622 | } |
| 623 | java_library { |
| 624 | name: "my_java_library_foo", |
| 625 | srcs: [":my_genrule_foo"], |
| 626 | sdk_version: "none", |
| 627 | system_modules: "none", |
| 628 | apex_available: [ |
| 629 | "myapex", |
| 630 | ], |
| 631 | } |
| 632 | aconfig_declarations_group { |
| 633 | name: "my_aconfig_declarations_group_foo", |
| 634 | java_aconfig_libraries: [ |
| 635 | "my_java_aconfig_library_foo", |
| 636 | ], |
| 637 | } |
| 638 | filegroup { |
| 639 | name: "my_filegroup_foo_srcjars", |
| 640 | srcs: [ |
| 641 | ":my_aconfig_declarations_group_foo{.srcjars}", |
| 642 | ], |
| 643 | } |
| 644 | genrule { |
| 645 | name: "my_genrule_foo", |
| 646 | srcs: [":my_filegroup_foo_srcjars"], |
| 647 | cmd: "cp $(in) $(out)", |
| 648 | out: ["my_genrule_foo.srcjar"], |
| 649 | } |
| 650 | aconfig_declarations { |
| 651 | name: "my_aconfig_declarations_foo", |
| 652 | package: "com.example.package", |
| 653 | container: "otherapex", |
| 654 | srcs: ["bar.aconfig"], |
| 655 | } |
| 656 | java_aconfig_library { |
| 657 | name: "my_java_aconfig_library_foo", |
| 658 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 659 | apex_available: [ |
| 660 | "myapex", |
| 661 | ], |
| 662 | }`, |
| 663 | expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`, |
| 664 | }, |
| 665 | } |
| 666 | for _, test := range testCases { |
| 667 | t.Run(test.name, func(t *testing.T) { |
| 668 | errorHandler := android.FixtureExpectsNoErrors |
| 669 | if test.expectedError != "" { |
| 670 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
| 671 | } |
| 672 | android.GroupFixturePreparers( |
| 673 | java.PrepareForTestWithJavaDefaultModules, |
| 674 | cc.PrepareForTestWithCcBuildComponents, |
| 675 | rust.PrepareForTestWithRustDefaultModules, |
| 676 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 677 | genrule.PrepareForIntegrationTestWithGenrule, |
| 678 | PrepareForTestWithApexBuildComponents, |
| 679 | prepareForTestWithMyapex, |
| 680 | withAconfigValidationError, |
| 681 | ). |
| 682 | ExtendWithErrorHandler(errorHandler). |
| 683 | RunTestWithBp(t, test.bp) |
| 684 | }) |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | func TestValidationNotPropagateAcrossShared(t *testing.T) { |
| 689 | testCases := []struct { |
| 690 | name string |
| 691 | bp string |
| 692 | }{ |
| 693 | { |
| 694 | name: "Java shared lib not propagate aconfig validation", |
| 695 | bp: apex_default_bp + ` |
| 696 | apex { |
| 697 | name: "myapex", |
| 698 | manifest: ":myapex.manifest", |
| 699 | androidManifest: ":myapex.androidmanifest", |
| 700 | key: "myapex.key", |
| 701 | java_libs: [ |
| 702 | "my_java_library_bar", |
| 703 | ], |
| 704 | updatable: false, |
| 705 | } |
| 706 | java_library { |
| 707 | name: "my_java_library_bar", |
| 708 | srcs: ["foo/bar/MyClass.java"], |
| 709 | sdk_version: "none", |
| 710 | system_modules: "none", |
| 711 | libs: ["my_java_library_foo"], |
| 712 | apex_available: [ |
| 713 | "myapex", |
| 714 | ], |
| 715 | } |
| 716 | java_library { |
| 717 | name: "my_java_library_foo", |
| 718 | srcs: ["foo/bar/MyClass.java"], |
| 719 | sdk_version: "none", |
| 720 | system_modules: "none", |
| 721 | static_libs: ["my_java_aconfig_library_foo"], |
| 722 | apex_available: [ |
| 723 | "myapex", |
| 724 | ], |
| 725 | } |
| 726 | aconfig_declarations { |
| 727 | name: "my_aconfig_declarations_foo", |
| 728 | package: "com.example.package", |
| 729 | container: "otherapex", |
| 730 | srcs: ["foo.aconfig"], |
| 731 | } |
| 732 | java_aconfig_library { |
| 733 | name: "my_java_aconfig_library_foo", |
| 734 | aconfig_declarations: "my_aconfig_declarations_foo", |
| 735 | apex_available: [ |
| 736 | "myapex", |
| 737 | ], |
| 738 | }`, |
| 739 | }, |
| 740 | } |
| 741 | for _, test := range testCases { |
| 742 | t.Run(test.name, func(t *testing.T) { |
| 743 | android.GroupFixturePreparers( |
| 744 | java.PrepareForTestWithJavaDefaultModules, |
| 745 | cc.PrepareForTestWithCcBuildComponents, |
| 746 | rust.PrepareForTestWithRustDefaultModules, |
| 747 | codegen.PrepareForTestWithAconfigBuildComponents, |
| 748 | PrepareForTestWithApexBuildComponents, |
| 749 | prepareForTestWithMyapex, |
| 750 | withAconfigValidationError, |
| 751 | ). |
| 752 | RunTestWithBp(t, test.bp) |
| 753 | }) |
| 754 | } |
| 755 | } |