| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "fmt" |
| 20 | "path/filepath" |
| 21 | "regexp" |
| 22 | "testing" |
| 23 | |
| 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
| 27 | func TestJavaSdkLibrary(t *testing.T) { |
| 28 | result := android.GroupFixturePreparers( |
| 29 | prepareForJavaTest, |
| 30 | PrepareForTestWithJavaSdkLibraryFiles, |
| 31 | FixtureWithPrebuiltApis(map[string][]string{ |
| 32 | "28": {"foo"}, |
| 33 | "29": {"foo"}, |
| 34 | "30": {"bar", "barney", "baz", "betty", "foo", "fred", "quuz", "wilma"}, |
| 35 | }), |
| 36 | ).RunTestWithBp(t, ` |
| 37 | droiddoc_exported_dir { |
| 38 | name: "droiddoc-templates-sdk", |
| 39 | path: ".", |
| 40 | } |
| 41 | java_sdk_library { |
| 42 | name: "foo", |
| 43 | srcs: ["a.java", "b.java"], |
| 44 | api_packages: ["foo"], |
| 45 | } |
| 46 | java_sdk_library { |
| 47 | name: "bar", |
| 48 | srcs: ["a.java", "b.java"], |
| 49 | api_packages: ["bar"], |
| Wei Li | d9100a5 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 50 | exclude_kotlinc_generated_files: true, |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 51 | } |
| 52 | java_library { |
| 53 | name: "baz", |
| 54 | srcs: ["c.java"], |
| 55 | libs: ["foo", "bar.stubs"], |
| 56 | sdk_version: "system_current", |
| 57 | } |
| 58 | java_sdk_library { |
| 59 | name: "barney", |
| 60 | srcs: ["c.java"], |
| 61 | api_only: true, |
| 62 | } |
| 63 | java_sdk_library { |
| 64 | name: "betty", |
| 65 | srcs: ["c.java"], |
| 66 | shared_library: false, |
| 67 | } |
| 68 | java_sdk_library_import { |
| 69 | name: "quuz", |
| 70 | public: { |
| 71 | jars: ["c.jar"], |
| 72 | }, |
| 73 | } |
| 74 | java_sdk_library_import { |
| 75 | name: "fred", |
| 76 | public: { |
| 77 | jars: ["b.jar"], |
| 78 | }, |
| 79 | } |
| 80 | java_sdk_library_import { |
| 81 | name: "wilma", |
| 82 | public: { |
| 83 | jars: ["b.jar"], |
| 84 | }, |
| 85 | shared_library: false, |
| 86 | } |
| 87 | java_library { |
| 88 | name: "qux", |
| 89 | srcs: ["c.java"], |
| 90 | libs: ["baz", "fred", "quuz.stubs", "wilma", "barney", "betty"], |
| 91 | sdk_version: "system_current", |
| 92 | } |
| 93 | java_library { |
| 94 | name: "baz-test", |
| 95 | srcs: ["c.java"], |
| 96 | libs: ["foo"], |
| 97 | sdk_version: "test_current", |
| 98 | } |
| 99 | java_library { |
| 100 | name: "baz-29", |
| 101 | srcs: ["c.java"], |
| 102 | libs: ["foo"], |
| 103 | sdk_version: "system_29", |
| 104 | } |
| 105 | java_library { |
| 106 | name: "baz-module-30", |
| 107 | srcs: ["c.java"], |
| 108 | libs: ["foo"], |
| 109 | sdk_version: "module_30", |
| 110 | } |
| 111 | `) |
| 112 | |
| 113 | // check the existence of the internal modules |
| Paul Duffin | a1aa738 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 114 | foo := result.ModuleForTests("foo", "android_common") |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 115 | result.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common") |
| 116 | result.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") |
| 117 | result.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common") |
| 118 | result.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common") |
| 119 | result.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common") |
| 120 | result.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common") |
| 121 | result.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") |
| 122 | result.ModuleForTests("foo.api.public.28", "") |
| 123 | result.ModuleForTests("foo.api.system.28", "") |
| 124 | result.ModuleForTests("foo.api.test.28", "") |
| 125 | |
| Paul Duffin | a1aa738 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 126 | exportedComponentsInfo := result.ModuleProvider(foo.Module(), ExportedComponentsInfoProvider).(ExportedComponentsInfo) |
| 127 | expectedFooExportedComponents := []string{ |
| 128 | "foo.stubs", |
| 129 | "foo.stubs.source", |
| 130 | "foo.stubs.source.system", |
| 131 | "foo.stubs.source.test", |
| 132 | "foo.stubs.system", |
| 133 | "foo.stubs.test", |
| 134 | } |
| 135 | android.AssertArrayString(t, "foo exported components", expectedFooExportedComponents, exportedComponentsInfo.Components) |
| 136 | |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 137 | bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac") |
| 138 | // tests if baz is actually linked to the stubs lib |
| 139 | android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.jar") |
| 140 | // ... and not to the impl lib |
| 141 | android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.jar") |
| 142 | // test if baz is not linked to the system variant of foo |
| 143 | android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.jar") |
| 144 | |
| 145 | bazTestJavac := result.ModuleForTests("baz-test", "android_common").Rule("javac") |
| 146 | // tests if baz-test is actually linked to the test stubs lib |
| 147 | android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.jar") |
| 148 | |
| 149 | baz29Javac := result.ModuleForTests("baz-29", "android_common").Rule("javac") |
| 150 | // tests if baz-29 is actually linked to the system 29 stubs lib |
| 151 | android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/29/system/foo.jar") |
| 152 | |
| 153 | bazModule30Javac := result.ModuleForTests("baz-module-30", "android_common").Rule("javac") |
| 154 | // tests if "baz-module-30" is actually linked to the module 30 stubs lib |
| 155 | android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/30/module-lib/foo.jar") |
| 156 | |
| 157 | // test if baz has exported SDK lib names foo and bar to qux |
| 158 | qux := result.ModuleForTests("qux", "android_common") |
| 159 | if quxLib, ok := qux.Module().(*Library); ok { |
| 160 | sdkLibs := quxLib.ClassLoaderContexts().UsesLibs() |
| 161 | android.AssertDeepEquals(t, "qux exports", []string{"foo", "bar", "fred", "quuz"}, sdkLibs) |
| 162 | } |
| Wei Li | d9100a5 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 163 | |
| 164 | fooDexJar := result.ModuleForTests("foo", "android_common").Rule("d8") |
| 165 | // tests if kotlinc generated files are NOT excluded from output of foo. |
| 166 | android.AssertStringDoesNotContain(t, "foo dex", fooDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module") |
| 167 | |
| 168 | barDexJar := result.ModuleForTests("bar", "android_common").Rule("d8") |
| 169 | // tests if kotlinc generated files are excluded from output of bar. |
| 170 | android.AssertStringDoesContain(t, "bar dex", barDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module") |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { |
| 174 | result := android.GroupFixturePreparers( |
| 175 | prepareForJavaTest, |
| 176 | PrepareForTestWithJavaSdkLibraryFiles, |
| 177 | FixtureWithLastReleaseApis("sdklib"), |
| 178 | ).RunTestWithBp(t, ` |
| 179 | java_sdk_library { |
| 180 | name: "sdklib", |
| 181 | srcs: ["a.java"], |
| 182 | libs: ["lib"], |
| 183 | static_libs: ["static-lib"], |
| 184 | impl_only_libs: ["impl-only-lib"], |
| 185 | stub_only_libs: ["stub-only-lib"], |
| 186 | stub_only_static_libs: ["stub-only-static-lib"], |
| 187 | } |
| 188 | java_defaults { |
| 189 | name: "defaults", |
| 190 | srcs: ["a.java"], |
| 191 | sdk_version: "current", |
| 192 | } |
| 193 | java_library { name: "lib", defaults: ["defaults"] } |
| 194 | java_library { name: "static-lib", defaults: ["defaults"] } |
| 195 | java_library { name: "impl-only-lib", defaults: ["defaults"] } |
| 196 | java_library { name: "stub-only-lib", defaults: ["defaults"] } |
| 197 | java_library { name: "stub-only-static-lib", defaults: ["defaults"] } |
| 198 | `) |
| 199 | var expectations = []struct { |
| 200 | lib string |
| 201 | on_impl_classpath bool |
| 202 | on_stub_classpath bool |
| 203 | in_impl_combined bool |
| 204 | in_stub_combined bool |
| 205 | }{ |
| 206 | {lib: "lib", on_impl_classpath: true}, |
| 207 | {lib: "static-lib", in_impl_combined: true}, |
| 208 | {lib: "impl-only-lib", on_impl_classpath: true}, |
| 209 | {lib: "stub-only-lib", on_stub_classpath: true}, |
| 210 | {lib: "stub-only-static-lib", in_stub_combined: true}, |
| 211 | } |
| 212 | verify := func(sdklib, dep string, cp, combined bool) { |
| 213 | sdklibCp := result.ModuleForTests(sdklib, "android_common").Rule("javac").Args["classpath"] |
| 214 | expected := cp || combined // Every combined jar is also on the classpath. |
| 215 | android.AssertStringContainsEquals(t, "bad classpath for "+sdklib, sdklibCp, "/"+dep+".jar", expected) |
| 216 | |
| 217 | combineJarInputs := result.ModuleForTests(sdklib, "android_common").Rule("combineJar").Inputs.Strings() |
| 218 | depPath := filepath.Join("out", "soong", ".intermediates", dep, "android_common", "turbine-combined", dep+".jar") |
| 219 | android.AssertStringListContainsEquals(t, "bad combined inputs for "+sdklib, combineJarInputs, depPath, combined) |
| 220 | } |
| 221 | for _, expectation := range expectations { |
| 222 | verify("sdklib", expectation.lib, expectation.on_impl_classpath, expectation.in_impl_combined) |
| 223 | verify("sdklib.impl", expectation.lib, expectation.on_impl_classpath, expectation.in_impl_combined) |
| 224 | |
| 225 | stubName := apiScopePublic.stubsLibraryModuleName("sdklib") |
| 226 | verify(stubName, expectation.lib, expectation.on_stub_classpath, expectation.in_stub_combined) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { |
| 231 | result := android.GroupFixturePreparers( |
| 232 | prepareForJavaTest, |
| 233 | PrepareForTestWithJavaSdkLibraryFiles, |
| 234 | FixtureWithLastReleaseApis("foo"), |
| 235 | ).RunTestWithBp(t, ` |
| 236 | java_sdk_library { |
| 237 | name: "foo", |
| 238 | srcs: ["a.java"], |
| 239 | api_only: true, |
| 240 | public: { |
| 241 | enabled: true, |
| 242 | }, |
| 243 | } |
| 244 | |
| 245 | java_library { |
| 246 | name: "bar", |
| 247 | srcs: ["b.java"], |
| 248 | libs: ["foo"], |
| 249 | } |
| 250 | `) |
| 251 | |
| 252 | // The bar library should depend on the stubs jar. |
| 253 | barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac") |
| 254 | if expected, actual := `^-classpath .*:out/soong/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 255 | t.Errorf("expected %q, found %#q", expected, actual) |
| 256 | } |
| 257 | } |
| 258 | |
| Anton Hansson | 3adf3c5 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 259 | func TestJavaSdkLibrary_AccessOutputFiles(t *testing.T) { |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 260 | android.GroupFixturePreparers( |
| 261 | prepareForJavaTest, |
| 262 | PrepareForTestWithJavaSdkLibraryFiles, |
| 263 | FixtureWithLastReleaseApis("foo"), |
| 264 | ).RunTestWithBp(t, ` |
| 265 | java_sdk_library { |
| 266 | name: "foo", |
| 267 | srcs: ["a.java"], |
| 268 | api_packages: ["foo"], |
| Anton Hansson | 3adf3c5 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 269 | annotations_enabled: true, |
| 270 | public: { |
| 271 | enabled: true, |
| 272 | }, |
| 273 | } |
| 274 | java_library { |
| 275 | name: "bar", |
| 276 | srcs: ["b.java", ":foo{.public.stubs.source}"], |
| 277 | java_resources: [":foo{.public.annotations.zip}"], |
| 278 | } |
| 279 | `) |
| 280 | } |
| 281 | |
| 282 | func TestJavaSdkLibrary_AccessOutputFiles_NoAnnotations(t *testing.T) { |
| 283 | android.GroupFixturePreparers( |
| 284 | prepareForJavaTest, |
| 285 | PrepareForTestWithJavaSdkLibraryFiles, |
| 286 | FixtureWithLastReleaseApis("foo"), |
| 287 | ). |
| 288 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": path dependency ":foo{.public.annotations.zip}": annotations.zip not available for api scope public`)). |
| 289 | RunTestWithBp(t, ` |
| 290 | java_sdk_library { |
| 291 | name: "foo", |
| 292 | srcs: ["a.java"], |
| 293 | api_packages: ["foo"], |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 294 | public: { |
| 295 | enabled: true, |
| 296 | }, |
| 297 | } |
| 298 | |
| 299 | java_library { |
| 300 | name: "bar", |
| 301 | srcs: ["b.java", ":foo{.public.stubs.source}"], |
| Anton Hansson | 3adf3c5 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 302 | java_resources: [":foo{.public.annotations.zip}"], |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 303 | } |
| 304 | `) |
| 305 | } |
| 306 | |
| 307 | func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { |
| 308 | android.GroupFixturePreparers( |
| 309 | prepareForJavaTest, |
| 310 | PrepareForTestWithJavaSdkLibraryFiles, |
| 311 | FixtureWithLastReleaseApis("foo"), |
| 312 | ). |
| 313 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`"foo" does not provide api scope system`)). |
| 314 | RunTestWithBp(t, ` |
| 315 | java_sdk_library { |
| 316 | name: "foo", |
| 317 | srcs: ["a.java"], |
| 318 | api_packages: ["foo"], |
| 319 | public: { |
| 320 | enabled: true, |
| 321 | }, |
| 322 | } |
| 323 | |
| 324 | java_library { |
| 325 | name: "bar", |
| 326 | srcs: ["b.java", ":foo{.system.stubs.source}"], |
| 327 | } |
| 328 | `) |
| 329 | } |
| 330 | |
| 331 | func TestJavaSdkLibrary_Deps(t *testing.T) { |
| 332 | result := android.GroupFixturePreparers( |
| 333 | prepareForJavaTest, |
| 334 | PrepareForTestWithJavaSdkLibraryFiles, |
| 335 | FixtureWithLastReleaseApis("sdklib"), |
| 336 | ).RunTestWithBp(t, ` |
| 337 | java_sdk_library { |
| 338 | name: "sdklib", |
| 339 | srcs: ["a.java"], |
| 340 | sdk_version: "none", |
| 341 | system_modules: "none", |
| 342 | public: { |
| 343 | enabled: true, |
| 344 | }, |
| 345 | } |
| 346 | `) |
| 347 | |
| 348 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
| 349 | `dex2oatd`, |
| 350 | `sdklib.impl`, |
| 351 | `sdklib.stubs`, |
| 352 | `sdklib.stubs.source`, |
| 353 | `sdklib.xml`, |
| 354 | }) |
| 355 | } |
| 356 | |
| 357 | func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) { |
| 358 | prepareForJavaTest.RunTestWithBp(t, ` |
| 359 | java_sdk_library_import { |
| 360 | name: "foo", |
| 361 | public: { |
| 362 | jars: ["a.jar"], |
| 363 | stub_srcs: ["a.java"], |
| 364 | current_api: "api/current.txt", |
| 365 | removed_api: "api/removed.txt", |
| Anton Hansson | 3adf3c5 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 366 | annotations: "x/annotations.zip", |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 367 | }, |
| 368 | } |
| 369 | |
| 370 | java_library { |
| 371 | name: "bar", |
| 372 | srcs: [":foo{.public.stubs.source}"], |
| 373 | java_resources: [ |
| 374 | ":foo{.public.api.txt}", |
| 375 | ":foo{.public.removed-api.txt}", |
| Anton Hansson | 3adf3c5 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 376 | ":foo{.public.annotations.zip}", |
| Colin Cross | 76069a3 | 2021-06-01 13:18:08 -0700 | [diff] [blame] | 377 | ], |
| 378 | } |
| 379 | `) |
| 380 | } |
| 381 | |
| 382 | func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { |
| 383 | bp := ` |
| 384 | java_sdk_library_import { |
| 385 | name: "foo", |
| 386 | public: { |
| 387 | jars: ["a.jar"], |
| 388 | }, |
| 389 | } |
| 390 | ` |
| 391 | |
| 392 | t.Run("stubs.source", func(t *testing.T) { |
| 393 | prepareForJavaTest. |
| 394 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`stubs.source not available for api scope public`)). |
| 395 | RunTestWithBp(t, bp+` |
| 396 | java_library { |
| 397 | name: "bar", |
| 398 | srcs: [":foo{.public.stubs.source}"], |
| 399 | java_resources: [ |
| 400 | ":foo{.public.api.txt}", |
| 401 | ":foo{.public.removed-api.txt}", |
| 402 | ], |
| 403 | } |
| 404 | `) |
| 405 | }) |
| 406 | |
| 407 | t.Run("api.txt", func(t *testing.T) { |
| 408 | prepareForJavaTest. |
| 409 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`api.txt not available for api scope public`)). |
| 410 | RunTestWithBp(t, bp+` |
| 411 | java_library { |
| 412 | name: "bar", |
| 413 | srcs: ["a.java"], |
| 414 | java_resources: [ |
| 415 | ":foo{.public.api.txt}", |
| 416 | ], |
| 417 | } |
| 418 | `) |
| 419 | }) |
| 420 | |
| 421 | t.Run("removed-api.txt", func(t *testing.T) { |
| 422 | prepareForJavaTest. |
| 423 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`removed-api.txt not available for api scope public`)). |
| 424 | RunTestWithBp(t, bp+` |
| 425 | java_library { |
| 426 | name: "bar", |
| 427 | srcs: ["a.java"], |
| 428 | java_resources: [ |
| 429 | ":foo{.public.removed-api.txt}", |
| 430 | ], |
| 431 | } |
| 432 | `) |
| 433 | }) |
| 434 | } |
| 435 | |
| 436 | func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { |
| 437 | prepareForJavaTest. |
| 438 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "foo": enabled api scope "system" depends on disabled scope "public"`)). |
| 439 | RunTestWithBp(t, ` |
| 440 | java_sdk_library { |
| 441 | name: "foo", |
| 442 | srcs: ["a.java", "b.java"], |
| 443 | api_packages: ["foo"], |
| 444 | // Explicitly disable public to test the check that ensures the set of enabled |
| 445 | // scopes is consistent. |
| 446 | public: { |
| 447 | enabled: false, |
| 448 | }, |
| 449 | system: { |
| 450 | enabled: true, |
| 451 | }, |
| 452 | } |
| 453 | `) |
| 454 | } |
| 455 | |
| 456 | func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { |
| 457 | android.GroupFixturePreparers( |
| 458 | prepareForJavaTest, |
| 459 | PrepareForTestWithJavaSdkLibraryFiles, |
| 460 | FixtureWithLastReleaseApis("foo"), |
| 461 | ).RunTestWithBp(t, ` |
| 462 | java_sdk_library { |
| 463 | name: "foo", |
| 464 | srcs: ["a.java", "b.java"], |
| 465 | api_packages: ["foo"], |
| 466 | system: { |
| 467 | enabled: true, |
| 468 | sdk_version: "module_current", |
| 469 | }, |
| 470 | } |
| 471 | `) |
| 472 | } |
| 473 | |
| 474 | func TestJavaSdkLibrary_ModuleLib(t *testing.T) { |
| 475 | android.GroupFixturePreparers( |
| 476 | prepareForJavaTest, |
| 477 | PrepareForTestWithJavaSdkLibraryFiles, |
| 478 | FixtureWithLastReleaseApis("foo"), |
| 479 | ).RunTestWithBp(t, ` |
| 480 | java_sdk_library { |
| 481 | name: "foo", |
| 482 | srcs: ["a.java", "b.java"], |
| 483 | api_packages: ["foo"], |
| 484 | system: { |
| 485 | enabled: true, |
| 486 | }, |
| 487 | module_lib: { |
| 488 | enabled: true, |
| 489 | }, |
| 490 | } |
| 491 | `) |
| 492 | } |
| 493 | |
| 494 | func TestJavaSdkLibrary_SystemServer(t *testing.T) { |
| 495 | android.GroupFixturePreparers( |
| 496 | prepareForJavaTest, |
| 497 | PrepareForTestWithJavaSdkLibraryFiles, |
| 498 | FixtureWithLastReleaseApis("foo"), |
| 499 | ).RunTestWithBp(t, ` |
| 500 | java_sdk_library { |
| 501 | name: "foo", |
| 502 | srcs: ["a.java", "b.java"], |
| 503 | api_packages: ["foo"], |
| 504 | system: { |
| 505 | enabled: true, |
| 506 | }, |
| 507 | system_server: { |
| 508 | enabled: true, |
| 509 | }, |
| 510 | } |
| 511 | `) |
| 512 | } |
| 513 | |
| 514 | func TestJavaSdkLibrary_MissingScope(t *testing.T) { |
| 515 | prepareForJavaTest. |
| 516 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`requires api scope module-lib from foo but it only has \[\] available`)). |
| 517 | RunTestWithBp(t, ` |
| 518 | java_sdk_library { |
| 519 | name: "foo", |
| 520 | srcs: ["a.java"], |
| 521 | public: { |
| 522 | enabled: false, |
| 523 | }, |
| 524 | } |
| 525 | |
| 526 | java_library { |
| 527 | name: "baz", |
| 528 | srcs: ["a.java"], |
| 529 | libs: ["foo"], |
| 530 | sdk_version: "module_current", |
| 531 | } |
| 532 | `) |
| 533 | } |
| 534 | |
| 535 | func TestJavaSdkLibrary_FallbackScope(t *testing.T) { |
| 536 | android.GroupFixturePreparers( |
| 537 | prepareForJavaTest, |
| 538 | PrepareForTestWithJavaSdkLibraryFiles, |
| 539 | FixtureWithLastReleaseApis("foo"), |
| 540 | ).RunTestWithBp(t, ` |
| 541 | java_sdk_library { |
| 542 | name: "foo", |
| 543 | srcs: ["a.java"], |
| 544 | system: { |
| 545 | enabled: true, |
| 546 | }, |
| 547 | } |
| 548 | |
| 549 | java_library { |
| 550 | name: "baz", |
| 551 | srcs: ["a.java"], |
| 552 | libs: ["foo"], |
| 553 | // foo does not have module-lib scope so it should fallback to system |
| 554 | sdk_version: "module_current", |
| 555 | } |
| 556 | `) |
| 557 | } |
| 558 | |
| 559 | func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) { |
| 560 | result := android.GroupFixturePreparers( |
| 561 | prepareForJavaTest, |
| 562 | PrepareForTestWithJavaSdkLibraryFiles, |
| 563 | FixtureWithLastReleaseApis("foo"), |
| 564 | ).RunTestWithBp(t, ` |
| 565 | java_sdk_library { |
| 566 | name: "foo", |
| 567 | srcs: ["a.java"], |
| 568 | system: { |
| 569 | enabled: true, |
| 570 | }, |
| 571 | default_to_stubs: true, |
| 572 | } |
| 573 | |
| 574 | java_library { |
| 575 | name: "baz", |
| 576 | srcs: ["a.java"], |
| 577 | libs: ["foo"], |
| 578 | // does not have sdk_version set, should fallback to module, |
| 579 | // which will then fallback to system because the module scope |
| 580 | // is not enabled. |
| 581 | } |
| 582 | `) |
| 583 | // The baz library should depend on the system stubs jar. |
| 584 | bazLibrary := result.ModuleForTests("baz", "android_common").Rule("javac") |
| 585 | if expected, actual := `^-classpath .*:out/soong/[^:]*/turbine-combined/foo\.stubs.system\.jar$`, bazLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 586 | t.Errorf("expected %q, found %#q", expected, actual) |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | func TestJavaSdkLibraryImport(t *testing.T) { |
| 591 | result := prepareForJavaTest.RunTestWithBp(t, ` |
| 592 | java_library { |
| 593 | name: "foo", |
| 594 | srcs: ["a.java"], |
| 595 | libs: ["sdklib"], |
| 596 | sdk_version: "current", |
| 597 | } |
| 598 | |
| 599 | java_library { |
| 600 | name: "foo.system", |
| 601 | srcs: ["a.java"], |
| 602 | libs: ["sdklib"], |
| 603 | sdk_version: "system_current", |
| 604 | } |
| 605 | |
| 606 | java_library { |
| 607 | name: "foo.test", |
| 608 | srcs: ["a.java"], |
| 609 | libs: ["sdklib"], |
| 610 | sdk_version: "test_current", |
| 611 | } |
| 612 | |
| 613 | java_sdk_library_import { |
| 614 | name: "sdklib", |
| 615 | public: { |
| 616 | jars: ["a.jar"], |
| 617 | }, |
| 618 | system: { |
| 619 | jars: ["b.jar"], |
| 620 | }, |
| 621 | test: { |
| 622 | jars: ["c.jar"], |
| 623 | stub_srcs: ["c.java"], |
| 624 | }, |
| 625 | } |
| 626 | `) |
| 627 | |
| 628 | for _, scope := range []string{"", ".system", ".test"} { |
| 629 | fooModule := result.ModuleForTests("foo"+scope, "android_common") |
| 630 | javac := fooModule.Rule("javac") |
| 631 | |
| 632 | sdklibStubsJar := result.ModuleForTests("sdklib.stubs"+scope, "android_common").Rule("combineJar").Output |
| 633 | android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], sdklibStubsJar.String()) |
| 634 | } |
| 635 | |
| 636 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
| 637 | `prebuilt_sdklib.stubs`, |
| 638 | `prebuilt_sdklib.stubs.source.test`, |
| 639 | `prebuilt_sdklib.stubs.system`, |
| 640 | `prebuilt_sdklib.stubs.test`, |
| 641 | }) |
| 642 | } |
| 643 | |
| 644 | func TestJavaSdkLibraryImport_WithSource(t *testing.T) { |
| 645 | result := android.GroupFixturePreparers( |
| 646 | prepareForJavaTest, |
| 647 | PrepareForTestWithJavaSdkLibraryFiles, |
| 648 | FixtureWithLastReleaseApis("sdklib"), |
| 649 | ).RunTestWithBp(t, ` |
| 650 | java_sdk_library { |
| 651 | name: "sdklib", |
| 652 | srcs: ["a.java"], |
| 653 | sdk_version: "none", |
| 654 | system_modules: "none", |
| 655 | public: { |
| 656 | enabled: true, |
| 657 | }, |
| 658 | } |
| 659 | |
| 660 | java_sdk_library_import { |
| 661 | name: "sdklib", |
| 662 | public: { |
| 663 | jars: ["a.jar"], |
| 664 | }, |
| 665 | } |
| 666 | `) |
| 667 | |
| 668 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
| 669 | `dex2oatd`, |
| 670 | `prebuilt_sdklib`, |
| 671 | `sdklib.impl`, |
| 672 | `sdklib.stubs`, |
| 673 | `sdklib.stubs.source`, |
| 674 | `sdklib.xml`, |
| 675 | }) |
| 676 | |
| 677 | CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{ |
| 678 | `prebuilt_sdklib.stubs`, |
| 679 | `sdklib.impl`, |
| 680 | // This should be prebuilt_sdklib.stubs but is set to sdklib.stubs because the |
| 681 | // dependency is added after prebuilts may have been renamed and so has to use |
| 682 | // the renamed name. |
| 683 | `sdklib.xml`, |
| 684 | }) |
| 685 | } |
| 686 | |
| 687 | func TestJavaSdkLibraryImport_Preferred(t *testing.T) { |
| 688 | result := android.GroupFixturePreparers( |
| 689 | prepareForJavaTest, |
| 690 | PrepareForTestWithJavaSdkLibraryFiles, |
| 691 | FixtureWithLastReleaseApis("sdklib"), |
| 692 | ).RunTestWithBp(t, ` |
| 693 | java_sdk_library { |
| 694 | name: "sdklib", |
| 695 | srcs: ["a.java"], |
| 696 | sdk_version: "none", |
| 697 | system_modules: "none", |
| 698 | public: { |
| 699 | enabled: true, |
| 700 | }, |
| 701 | } |
| 702 | |
| 703 | java_sdk_library_import { |
| 704 | name: "sdklib", |
| 705 | prefer: true, |
| 706 | public: { |
| 707 | jars: ["a.jar"], |
| 708 | }, |
| 709 | } |
| 710 | `) |
| 711 | |
| 712 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
| 713 | `dex2oatd`, |
| 714 | `prebuilt_sdklib`, |
| 715 | `sdklib.impl`, |
| 716 | `sdklib.stubs`, |
| 717 | `sdklib.stubs.source`, |
| 718 | `sdklib.xml`, |
| 719 | }) |
| 720 | |
| 721 | CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{ |
| 722 | `prebuilt_sdklib.stubs`, |
| 723 | `sdklib.impl`, |
| 724 | `sdklib.xml`, |
| 725 | }) |
| 726 | } |
| 727 | |
| 728 | func TestJavaSdkLibraryEnforce(t *testing.T) { |
| 729 | partitionToBpOption := func(partition string) string { |
| 730 | switch partition { |
| 731 | case "system": |
| 732 | return "" |
| 733 | case "vendor": |
| 734 | return "soc_specific: true," |
| 735 | case "product": |
| 736 | return "product_specific: true," |
| 737 | default: |
| 738 | panic("Invalid partition group name: " + partition) |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | type testConfigInfo struct { |
| 743 | libraryType string |
| 744 | fromPartition string |
| 745 | toPartition string |
| 746 | enforceVendorInterface bool |
| 747 | enforceProductInterface bool |
| 748 | enforceJavaSdkLibraryCheck bool |
| 749 | allowList []string |
| 750 | } |
| 751 | |
| 752 | createPreparer := func(info testConfigInfo) android.FixturePreparer { |
| 753 | bpFileTemplate := ` |
| 754 | java_library { |
| 755 | name: "foo", |
| 756 | srcs: ["foo.java"], |
| 757 | libs: ["bar"], |
| 758 | sdk_version: "current", |
| 759 | %s |
| 760 | } |
| 761 | |
| 762 | %s { |
| 763 | name: "bar", |
| 764 | srcs: ["bar.java"], |
| 765 | sdk_version: "current", |
| 766 | %s |
| 767 | } |
| 768 | ` |
| 769 | |
| 770 | bpFile := fmt.Sprintf(bpFileTemplate, |
| 771 | partitionToBpOption(info.fromPartition), |
| 772 | info.libraryType, |
| 773 | partitionToBpOption(info.toPartition)) |
| 774 | |
| 775 | return android.GroupFixturePreparers( |
| 776 | PrepareForTestWithJavaSdkLibraryFiles, |
| 777 | FixtureWithLastReleaseApis("bar"), |
| 778 | android.FixtureWithRootAndroidBp(bpFile), |
| 779 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 780 | variables.EnforceProductPartitionInterface = proptools.BoolPtr(info.enforceProductInterface) |
| 781 | if info.enforceVendorInterface { |
| 782 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 783 | } |
| 784 | variables.EnforceInterPartitionJavaSdkLibrary = proptools.BoolPtr(info.enforceJavaSdkLibraryCheck) |
| 785 | variables.InterPartitionJavaLibraryAllowList = info.allowList |
| 786 | }), |
| 787 | ) |
| 788 | } |
| 789 | |
| 790 | runTest := func(t *testing.T, info testConfigInfo, expectedErrorPattern string) { |
| 791 | t.Run(fmt.Sprintf("%v", info), func(t *testing.T) { |
| 792 | errorHandler := android.FixtureExpectsNoErrors |
| 793 | if expectedErrorPattern != "" { |
| 794 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorPattern) |
| 795 | } |
| 796 | android.GroupFixturePreparers( |
| 797 | prepareForJavaTest, |
| 798 | createPreparer(info), |
| 799 | ). |
| 800 | ExtendWithErrorHandler(errorHandler). |
| 801 | RunTest(t) |
| 802 | }) |
| 803 | } |
| 804 | |
| 805 | errorMessage := "is not allowed across the partitions" |
| 806 | |
| 807 | runTest(t, testConfigInfo{ |
| 808 | libraryType: "java_library", |
| 809 | fromPartition: "product", |
| 810 | toPartition: "system", |
| 811 | enforceVendorInterface: true, |
| 812 | enforceProductInterface: true, |
| 813 | enforceJavaSdkLibraryCheck: false, |
| 814 | }, "") |
| 815 | |
| 816 | runTest(t, testConfigInfo{ |
| 817 | libraryType: "java_library", |
| 818 | fromPartition: "product", |
| 819 | toPartition: "system", |
| 820 | enforceVendorInterface: true, |
| 821 | enforceProductInterface: false, |
| 822 | enforceJavaSdkLibraryCheck: true, |
| 823 | }, "") |
| 824 | |
| 825 | runTest(t, testConfigInfo{ |
| 826 | libraryType: "java_library", |
| 827 | fromPartition: "product", |
| 828 | toPartition: "system", |
| 829 | enforceVendorInterface: true, |
| 830 | enforceProductInterface: true, |
| 831 | enforceJavaSdkLibraryCheck: true, |
| 832 | }, errorMessage) |
| 833 | |
| 834 | runTest(t, testConfigInfo{ |
| 835 | libraryType: "java_library", |
| 836 | fromPartition: "vendor", |
| 837 | toPartition: "system", |
| 838 | enforceVendorInterface: true, |
| 839 | enforceProductInterface: true, |
| 840 | enforceJavaSdkLibraryCheck: true, |
| 841 | }, errorMessage) |
| 842 | |
| 843 | runTest(t, testConfigInfo{ |
| 844 | libraryType: "java_library", |
| 845 | fromPartition: "vendor", |
| 846 | toPartition: "system", |
| 847 | enforceVendorInterface: true, |
| 848 | enforceProductInterface: true, |
| 849 | enforceJavaSdkLibraryCheck: true, |
| 850 | allowList: []string{"bar"}, |
| 851 | }, "") |
| 852 | |
| 853 | runTest(t, testConfigInfo{ |
| 854 | libraryType: "java_library", |
| 855 | fromPartition: "vendor", |
| 856 | toPartition: "product", |
| 857 | enforceVendorInterface: true, |
| 858 | enforceProductInterface: true, |
| 859 | enforceJavaSdkLibraryCheck: true, |
| 860 | }, errorMessage) |
| 861 | |
| 862 | runTest(t, testConfigInfo{ |
| 863 | libraryType: "java_sdk_library", |
| 864 | fromPartition: "product", |
| 865 | toPartition: "system", |
| 866 | enforceVendorInterface: true, |
| 867 | enforceProductInterface: true, |
| 868 | enforceJavaSdkLibraryCheck: true, |
| 869 | }, "") |
| 870 | |
| 871 | runTest(t, testConfigInfo{ |
| 872 | libraryType: "java_sdk_library", |
| 873 | fromPartition: "vendor", |
| 874 | toPartition: "system", |
| 875 | enforceVendorInterface: true, |
| 876 | enforceProductInterface: true, |
| 877 | enforceJavaSdkLibraryCheck: true, |
| 878 | }, "") |
| 879 | |
| 880 | runTest(t, testConfigInfo{ |
| 881 | libraryType: "java_sdk_library", |
| 882 | fromPartition: "vendor", |
| 883 | toPartition: "product", |
| 884 | enforceVendorInterface: true, |
| 885 | enforceProductInterface: true, |
| 886 | enforceJavaSdkLibraryCheck: true, |
| 887 | }, "") |
| 888 | } |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 889 | |
| 890 | func TestJavaSdkLibraryDist(t *testing.T) { |
| 891 | result := android.GroupFixturePreparers( |
| 892 | PrepareForTestWithJavaBuildComponents, |
| 893 | PrepareForTestWithJavaDefaultModules, |
| 894 | PrepareForTestWithJavaSdkLibraryFiles, |
| Colin Cross | 7104aae | 2021-06-02 13:02:51 -0700 | [diff] [blame] | 895 | FixtureWithLastReleaseApis( |
| 896 | "sdklib_no_group", |
| 897 | "sdklib_group_foo", |
| 898 | "sdklib_owner_foo", |
| 899 | "foo"), |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 900 | ).RunTestWithBp(t, ` |
| 901 | java_sdk_library { |
| Colin Cross | 1072a71 | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 902 | name: "sdklib_no_group", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 903 | srcs: ["foo.java"], |
| 904 | } |
| 905 | |
| 906 | java_sdk_library { |
| Colin Cross | 0d3dd06 | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 907 | name: "sdklib_group_foo", |
| Colin Cross | 0d3dd06 | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 908 | srcs: ["foo.java"], |
| 909 | dist_group: "foo", |
| 910 | } |
| 911 | |
| 912 | java_sdk_library { |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 913 | name: "sdklib_owner_foo", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 914 | srcs: ["foo.java"], |
| 915 | owner: "foo", |
| 916 | } |
| 917 | |
| 918 | java_sdk_library { |
| 919 | name: "sdklib_stem_foo", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 920 | srcs: ["foo.java"], |
| 921 | dist_stem: "foo", |
| 922 | } |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 923 | `) |
| 924 | |
| 925 | type testCase struct { |
| 926 | module string |
| 927 | distDir string |
| 928 | distStem string |
| 929 | } |
| 930 | testCases := []testCase{ |
| 931 | { |
| Colin Cross | 1072a71 | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 932 | module: "sdklib_no_group", |
| Colin Cross | 0f9eeb7 | 2021-06-01 14:05:09 -0700 | [diff] [blame] | 933 | distDir: "apistubs/unknown/public", |
| Colin Cross | 1072a71 | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 934 | distStem: "sdklib_no_group.jar", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 935 | }, |
| 936 | { |
| Colin Cross | 0d3dd06 | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 937 | module: "sdklib_group_foo", |
| 938 | distDir: "apistubs/foo/public", |
| 939 | distStem: "sdklib_group_foo.jar", |
| 940 | }, |
| 941 | { |
| Colin Cross | 1072a71 | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 942 | // Owner doesn't affect distDir after b/186723288. |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 943 | module: "sdklib_owner_foo", |
| Colin Cross | 1072a71 | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 944 | distDir: "apistubs/unknown/public", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 945 | distStem: "sdklib_owner_foo.jar", |
| 946 | }, |
| 947 | { |
| 948 | module: "sdklib_stem_foo", |
| Colin Cross | 0f9eeb7 | 2021-06-01 14:05:09 -0700 | [diff] [blame] | 949 | distDir: "apistubs/unknown/public", |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 950 | distStem: "foo.jar", |
| 951 | }, |
| Colin Cross | 3b53808 | 2021-06-01 13:39:09 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | for _, tt := range testCases { |
| 955 | t.Run(tt.module, func(t *testing.T) { |
| 956 | m := result.ModuleForTests(tt.module+".stubs", "android_common").Module().(*Library) |
| 957 | dists := m.Dists() |
| 958 | if len(dists) != 1 { |
| 959 | t.Fatalf("expected exactly 1 dist entry, got %d", len(dists)) |
| 960 | } |
| 961 | if g, w := String(dists[0].Dir), tt.distDir; g != w { |
| 962 | t.Errorf("expected dist dir %q, got %q", w, g) |
| 963 | } |
| 964 | if g, w := String(dists[0].Dest), tt.distStem; g != w { |
| 965 | t.Errorf("expected dist stem %q, got %q", w, g) |
| 966 | } |
| 967 | }) |
| 968 | } |
| 969 | } |
| satayev | 531330e | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 970 | |
| 971 | func TestSdkLibrary_CheckMinSdkVersion(t *testing.T) { |
| 972 | preparer := android.GroupFixturePreparers( |
| 973 | PrepareForTestWithJavaBuildComponents, |
| 974 | PrepareForTestWithJavaDefaultModules, |
| 975 | PrepareForTestWithJavaSdkLibraryFiles, |
| 976 | ) |
| 977 | |
| 978 | preparer.RunTestWithBp(t, ` |
| 979 | java_sdk_library { |
| 980 | name: "sdklib", |
| 981 | srcs: ["a.java"], |
| 982 | static_libs: ["util"], |
| 983 | min_sdk_version: "30", |
| 984 | unsafe_ignore_missing_latest_api: true, |
| 985 | } |
| 986 | |
| 987 | java_library { |
| 988 | name: "util", |
| 989 | srcs: ["a.java"], |
| 990 | min_sdk_version: "30", |
| 991 | } |
| 992 | `) |
| 993 | |
| 994 | preparer. |
| 995 | RunTestWithBp(t, ` |
| 996 | java_sdk_library { |
| 997 | name: "sdklib", |
| 998 | srcs: ["a.java"], |
| 999 | libs: ["util"], |
| 1000 | impl_only_libs: ["util"], |
| 1001 | stub_only_libs: ["util"], |
| 1002 | stub_only_static_libs: ["util"], |
| 1003 | min_sdk_version: "30", |
| 1004 | unsafe_ignore_missing_latest_api: true, |
| 1005 | } |
| 1006 | |
| 1007 | java_library { |
| 1008 | name: "util", |
| 1009 | srcs: ["a.java"], |
| 1010 | } |
| 1011 | `) |
| 1012 | |
| 1013 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "util".*should support min_sdk_version\(30\)`)). |
| 1014 | RunTestWithBp(t, ` |
| 1015 | java_sdk_library { |
| 1016 | name: "sdklib", |
| 1017 | srcs: ["a.java"], |
| 1018 | static_libs: ["util"], |
| 1019 | min_sdk_version: "30", |
| 1020 | unsafe_ignore_missing_latest_api: true, |
| 1021 | } |
| 1022 | |
| 1023 | java_library { |
| 1024 | name: "util", |
| 1025 | srcs: ["a.java"], |
| 1026 | min_sdk_version: "31", |
| 1027 | } |
| 1028 | `) |
| 1029 | |
| 1030 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "another_util".*should support min_sdk_version\(30\)`)). |
| 1031 | RunTestWithBp(t, ` |
| 1032 | java_sdk_library { |
| 1033 | name: "sdklib", |
| 1034 | srcs: ["a.java"], |
| 1035 | static_libs: ["util"], |
| 1036 | min_sdk_version: "30", |
| 1037 | unsafe_ignore_missing_latest_api: true, |
| 1038 | } |
| 1039 | |
| 1040 | java_library { |
| 1041 | name: "util", |
| 1042 | srcs: ["a.java"], |
| 1043 | static_libs: ["another_util"], |
| 1044 | min_sdk_version: "30", |
| 1045 | } |
| 1046 | |
| 1047 | java_library { |
| 1048 | name: "another_util", |
| 1049 | srcs: ["a.java"], |
| 1050 | min_sdk_version: "31", |
| 1051 | } |
| 1052 | `) |
| 1053 | } |