java_sdk_library_import: Copy all prebuilt properties to child modules
Previously, only the prefer property was copied from the
java_sdk_library_import module to its child modules which meant that if
the use_source_config_var property was used to control the prefer
property that the child modules would never be used. That can cause
build breakages when building against prebuilts as some parts of the
build will use prebuilt files from java_sdk_library_import and some
will use source files from the corresponding java_sdk_library.
This change copies the use_source_config_var property too.
It also adds tests to verify that dependencies on child modules of a
java_sdk_library use the prebuilt child modules of the corresponding
java_sdk_library_import. That revealed a bug with the handling of stub
sources where the prefer property was set after creating the module
which has also been fixed.
Bug: 249192297
Test: m nothing
# Cherry pick into branch broken by previous behavior and make
# sure that it fixes it.
Change-Id: I5719c257f8457bcb2238bc7965215512a20f1095
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 805bc22..ea7b2f7 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -875,11 +875,12 @@
})
}
-func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
+func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer android.FixturePreparer) {
result := android.GroupFixturePreparers(
prepareForJavaTest,
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("sdklib"),
+ preparer,
).RunTestWithBp(t, `
java_sdk_library {
name: "sdklib",
@@ -893,11 +894,37 @@
java_sdk_library_import {
name: "sdklib",
- prefer: true,
+ `+prefer+`
public: {
jars: ["a.jar"],
+ stub_srcs: ["a.java"],
+ current_api: "current.txt",
+ removed_api: "removed.txt",
+ annotations: "annotations.zip",
},
}
+
+ java_library {
+ name: "combined",
+ static_libs: [
+ "sdklib.stubs",
+ ],
+ java_resources: [
+ ":sdklib.stubs.source",
+ ":sdklib{.public.api.txt}",
+ ":sdklib{.public.removed-api.txt}",
+ ":sdklib{.public.annotations.zip}",
+ ],
+ sdk_version: "none",
+ system_modules: "none",
+ }
+
+ java_library {
+ name: "public",
+ srcs: ["a.java"],
+ libs: ["sdklib"],
+ sdk_version: "current",
+ }
`)
CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{
@@ -913,9 +940,48 @@
CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{
`dex2oatd`,
`prebuilt_sdklib.stubs`,
+ `prebuilt_sdklib.stubs.source`,
`sdklib.impl`,
`sdklib.xml`,
})
+
+ // Make sure that dependencies on child modules use the prebuilt when preferred.
+ CheckModuleDependencies(t, result.TestContext, "combined", "android_common", []string{
+ // Each use of :sdklib{...} adds a dependency onto prebuilt_sdklib.
+ `prebuilt_sdklib`,
+ `prebuilt_sdklib`,
+ `prebuilt_sdklib`,
+ `prebuilt_sdklib.stubs`,
+ `prebuilt_sdklib.stubs.source`,
+ })
+
+ // Make sure that dependencies on sdklib that resolve to one of the child libraries use the
+ // prebuilt library.
+ public := result.ModuleForTests("public", "android_common")
+ rule := public.Output("javac/public.jar")
+ inputs := rule.Implicits.Strings()
+ expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/combined/sdklib.stubs.jar"
+ if !android.InList(expected, inputs) {
+ t.Errorf("expected %q to contain %q", inputs, expected)
+ }
+}
+
+func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
+ t.Run("prefer", func(t *testing.T) {
+ testJavaSdkLibraryImport_Preferred(t, "prefer: true,", android.NullFixturePreparer)
+ })
+
+ t.Run("use_source_config_var", func(t *testing.T) {
+ testJavaSdkLibraryImport_Preferred(t,
+ "use_source_config_var: {config_namespace: \"acme\", var_name: \"use_source\"},",
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.VendorVars = map[string]map[string]string{
+ "acme": {
+ "use_source": "false",
+ },
+ }
+ }))
+ })
}
func TestJavaSdkLibraryEnforce(t *testing.T) {