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