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