Add the ability for a java_sdk_library to depend on another.

This simply exports all of the uses_libs: [] libraries into a
"dependency=''" statement in the generated XML file (with the <library>
stanza in it).

Test: `go test` in java/
Bug: 184396657

NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
 func formattedDependenciesAttribute(dependencies []string) string {
> +	if dependencies == nil {
> +		return ""
> +	}
> +	return fmt.Sprintf(`        dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
> +}
> +
> +	dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
> +		dependenciesAttr,
> --- java/sdk_library_test.go
> +++ java/sdk_library_test.go
> +
> +func TestSdkLibraryDependency(t *testing.T) {
> +	result := android.GroupFixturePreparers(
> +		prepareForJavaTest,
> +		PrepareForTestWithJavaSdkLibraryFiles,
> +		FixtureWithPrebuiltApis(map[string][]string{
> +			"30": {"bar", "foo"},
> +		}),
> +	).RunTestWithBp(t,
> +		`
> +		java_sdk_library {
> +			name: "foo",
> +			srcs: ["a.java", "b.java"],
> +			api_packages: ["foo"],
> +		}
> +		
> +		java_sdk_library {
> +			name: "bar",
> +			srcs: ["c.java", "b.java"],
> +			libs: [
> +				"foo",
> +			],
> +			uses_libs: [
> +				"foo",
> +			],
> +		}
> +`)
> +	
> +	barPermissions := result.ModuleForTests("bar.xml", "android_common").Rule("java_sdk_xml")
> +	
> +	android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`)
> +}

Original patch:
 diff --git a/java/sdk_library.go b/java/sdk_library.go
old mode 100644
new mode 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
 		Min_device_sdk            *string
 		Max_device_sdk            *string
 		Sdk_library_min_api_level *string
+		Uses_libs_dependencies    []string
 	}{
 		Name:                      proptools.StringPtr(module.xmlPermissionsModuleName()),
 		Lib_name:                  proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
 		Min_device_sdk:            module.commonSdkLibraryProperties.Min_device_sdk,
 		Max_device_sdk:            module.commonSdkLibraryProperties.Max_device_sdk,
 		Sdk_library_min_api_level: &moduleMinApiLevelStr,
+		Uses_libs_dependencies:    module.usesLibraryProperties.Uses_libs,
 	}
 
 	mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
 	//
 	// This value comes from the ApiLevel of the MinSdkVersion property.
 	Sdk_library_min_api_level *string
+
+	// Uses-libs dependencies that the shared libra
[[[Original patch trimmed due to size. Decoded string size: 3559. Decoded string SHA1: 67fbd040aa818732a686514c4556850c8c36dc8d.]]]

Result patch:
 diff --git a/java/sdk_library.go b/java/sdk_library.go
index fb27812..fbfe509 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1993,6 +1993,7 @@
 		Min_device_sdk            *string
 		Max_device_sdk            *string
 		Sdk_library_min_api_level *string
+		Uses_libs_dependencies    []string
 	}{
 		Name:                      proptools.StringPtr(module.xmlPermissionsModuleName()),
 		Lib_name:                  proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@
 		Min_device_sdk:            module.commonSdkLibraryProperties.Min_device_sdk,
 		Max_device_sdk:            module.commonSdkLibraryProperties.Max_device_sdk,
 		Sdk_library_min_api_level: &moduleMinApiLevelStr,
+		Uses_libs_dependencies:    module.usesLibraryProperties.Uses_libs,
 	}
 
 	mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@
 	//
 	// This value comes from the ApiLevel of the MinSdkVersion property.
 	Sdk_library_min_api_level *string
+
+	// Uses-libs dependencies that the shared library
[[[Result patch trimmed due to size. Decoded string size: 3614. Decoded string SHA1: b5730ecbeeaad420439ddb67eaaa9150ede94585.]]]

Change-Id: I73f69e2a4573e416492f68e083fe739f3f75b721
This commit is contained in:
Jamie Garside
2023-11-27 12:07:36 +00:00
parent 40b8b16042
commit e570ace2e4
2 changed files with 48 additions and 0 deletions

View File

@@ -1993,6 +1993,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Min_device_sdk *string
Max_device_sdk *string
Sdk_library_min_api_level *string
Uses_libs_dependencies []string
}{
Name: proptools.StringPtr(module.xmlPermissionsModuleName()),
Lib_name: proptools.StringPtr(module.BaseModuleName()),
@@ -2002,6 +2003,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk,
Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk,
Sdk_library_min_api_level: &moduleMinApiLevelStr,
Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs,
}
mctx.CreateModule(sdkLibraryXmlFactory, &props)
@@ -2968,6 +2970,11 @@ type sdkLibraryXmlProperties struct {
//
// This value comes from the ApiLevel of the MinSdkVersion property.
Sdk_library_min_api_level *string
// Uses-libs dependencies that the shared library requires to work correctly.
//
// This will add dependency="foo:bar" to the <library> section.
Uses_libs_dependencies []string
}
// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
@@ -3076,6 +3083,13 @@ func formattedOptionalAttribute(attrName string, value *string) string {
return fmt.Sprintf(` %s=\"%s\"\n`, attrName, *value)
}
func formattedDependenciesAttribute(dependencies []string) string {
if dependencies == nil {
return ""
}
return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":"))
}
func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) string {
libName := proptools.String(module.properties.Lib_name)
libNameAttr := formattedOptionalAttribute("name", &libName)
@@ -3085,6 +3099,7 @@ func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) stri
implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before)
minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk)
maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk)
dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies)
// <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that).
// similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T
var libraryTag string
@@ -3118,6 +3133,7 @@ func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) stri
implicitUntilAttr,
minSdkAttr,
maxSdkAttr,
dependenciesAttr,
` />\n`,
`</permissions>\n`}, "")
}