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