Add the ability for a java_sdk_library to depend on another. am: e570ace2e4
am: b5429e879e
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2844082 Change-Id: Id586e97d13ab3602207873308e5b4ec483744da9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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`}, "")
|
||||
}
|
||||
|
@@ -1665,3 +1665,35 @@ func TestStaticDepStubLibrariesVisibility(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
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\"`)
|
||||
}
|
||||
|
Reference in New Issue
Block a user