Merge "Don't add uses_libs/optional_uses_libs to the manifest_fixer." am: 81a1adb6db am: affc7d8116

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1803744

Change-Id: I8b76722fb92b2ae46987fc6f5d2a458fed755176
This commit is contained in:
Ulyana Trafimovich
2021-08-24 10:19:50 +00:00
committed by Automerger Merge Worker
7 changed files with 104 additions and 66 deletions

View File

@@ -196,6 +196,10 @@ type ClassLoaderContext struct {
// If the library is optional or required. // If the library is optional or required.
Optional bool Optional bool
// If the library is implicitly infered by Soong (as opposed to explicitly added via `uses_libs`
// or `optional_uses_libs`.
Implicit bool
// On-host build path to the library dex file (used in dex2oat argument --class-loader-context). // On-host build path to the library dex file (used in dex2oat argument --class-loader-context).
Host android.Path Host android.Path
@@ -258,8 +262,9 @@ const UnknownInstallLibraryPath = "error"
const AnySdkVersion int = android.FutureApiLevelInt const AnySdkVersion int = android.FutureApiLevelInt
// Add class loader context for the given library to the map entry for the given SDK version. // Add class loader context for the given library to the map entry for the given SDK version.
func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathContext, sdkVer int, lib string, func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathContext, sdkVer int,
optional bool, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) error { lib string, optional, implicit bool, hostPath, installPath android.Path,
nestedClcMap ClassLoaderContextMap) error {
// For prebuilts, library should have the same name as the source module. // For prebuilts, library should have the same name as the source module.
lib = android.RemoveOptionalPrebuiltPrefix(lib) lib = android.RemoveOptionalPrebuiltPrefix(lib)
@@ -308,6 +313,7 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{ clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{
Name: lib, Name: lib,
Optional: optional, Optional: optional,
Implicit: implicit,
Host: hostPath, Host: hostPath,
Device: devicePath, Device: devicePath,
Subcontexts: subcontexts, Subcontexts: subcontexts,
@@ -320,9 +326,10 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
// about paths). For the subset of libraries that are used in dexpreopt, their build/install paths // about paths). For the subset of libraries that are used in dexpreopt, their build/install paths
// are validated later before CLC is used (in validateClassLoaderContext). // are validated later before CLC is used (in validateClassLoaderContext).
func (clcMap ClassLoaderContextMap) AddContext(ctx android.ModuleInstallPathContext, sdkVer int, func (clcMap ClassLoaderContextMap) AddContext(ctx android.ModuleInstallPathContext, sdkVer int,
lib string, optional bool, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) { lib string, optional, implicit bool, hostPath, installPath android.Path,
nestedClcMap ClassLoaderContextMap) {
err := clcMap.addContext(ctx, sdkVer, lib, optional, hostPath, installPath, nestedClcMap) err := clcMap.addContext(ctx, sdkVer, lib, optional, implicit, hostPath, installPath, nestedClcMap)
if err != nil { if err != nil {
ctx.ModuleErrorf(err.Error()) ctx.ModuleErrorf(err.Error())
} }
@@ -366,13 +373,15 @@ func (clcMap ClassLoaderContextMap) AddContextMap(otherClcMap ClassLoaderContext
// included). This is the list of libraries that should be in the <uses-library> tags in the // included). This is the list of libraries that should be in the <uses-library> tags in the
// manifest. Some of them may be present in the source manifest, others are added by manifest_fixer. // manifest. Some of them may be present in the source manifest, others are added by manifest_fixer.
// Required and optional libraries are in separate lists. // Required and optional libraries are in separate lists.
func (clcMap ClassLoaderContextMap) UsesLibs() (required []string, optional []string) { func (clcMap ClassLoaderContextMap) usesLibs(implicit bool) (required []string, optional []string) {
if clcMap != nil { if clcMap != nil {
clcs := clcMap[AnySdkVersion] clcs := clcMap[AnySdkVersion]
required = make([]string, 0, len(clcs)) required = make([]string, 0, len(clcs))
optional = make([]string, 0, len(clcs)) optional = make([]string, 0, len(clcs))
for _, clc := range clcs { for _, clc := range clcs {
if clc.Optional { if implicit && !clc.Implicit {
// Skip, this is an explicit library and we need only the implicit ones.
} else if clc.Optional {
optional = append(optional, clc.Name) optional = append(optional, clc.Name)
} else { } else {
required = append(required, clc.Name) required = append(required, clc.Name)
@@ -382,6 +391,14 @@ func (clcMap ClassLoaderContextMap) UsesLibs() (required []string, optional []st
return required, optional return required, optional
} }
func (clcMap ClassLoaderContextMap) UsesLibs() ([]string, []string) {
return clcMap.usesLibs(false)
}
func (clcMap ClassLoaderContextMap) ImplicitUsesLibs() ([]string, []string) {
return clcMap.usesLibs(true)
}
func (clcMap ClassLoaderContextMap) Dump() string { func (clcMap ClassLoaderContextMap) Dump() string {
jsonCLC := toJsonClassLoaderContext(clcMap) jsonCLC := toJsonClassLoaderContext(clcMap)
bytes, err := json.MarshalIndent(jsonCLC, "", " ") bytes, err := json.MarshalIndent(jsonCLC, "", " ")
@@ -524,6 +541,8 @@ func computeClassLoaderContextRec(clcs []*ClassLoaderContext) (string, string, a
// the same as Soong representation except that SDK versions and paths are represented with strings. // the same as Soong representation except that SDK versions and paths are represented with strings.
type jsonClassLoaderContext struct { type jsonClassLoaderContext struct {
Name string Name string
Optional bool
Implicit bool
Host string Host string
Device string Device string
Subcontexts []*jsonClassLoaderContext Subcontexts []*jsonClassLoaderContext
@@ -555,6 +574,8 @@ func fromJsonClassLoaderContextRec(ctx android.PathContext, jClcs []*jsonClassLo
for _, clc := range jClcs { for _, clc := range jClcs {
clcs = append(clcs, &ClassLoaderContext{ clcs = append(clcs, &ClassLoaderContext{
Name: clc.Name, Name: clc.Name,
Optional: clc.Optional,
Implicit: clc.Implicit,
Host: constructPath(ctx, clc.Host), Host: constructPath(ctx, clc.Host),
Device: clc.Device, Device: clc.Device,
Subcontexts: fromJsonClassLoaderContextRec(ctx, clc.Subcontexts), Subcontexts: fromJsonClassLoaderContextRec(ctx, clc.Subcontexts),
@@ -579,6 +600,8 @@ func toJsonClassLoaderContextRec(clcs []*ClassLoaderContext) []*jsonClassLoaderC
for i, clc := range clcs { for i, clc := range clcs {
jClcs[i] = &jsonClassLoaderContext{ jClcs[i] = &jsonClassLoaderContext{
Name: clc.Name, Name: clc.Name,
Optional: clc.Optional,
Implicit: clc.Implicit,
Host: clc.Host.String(), Host: clc.Host.String(),
Device: clc.Device, Device: clc.Device,
Subcontexts: toJsonClassLoaderContextRec(clc.Subcontexts), Subcontexts: toJsonClassLoaderContextRec(clc.Subcontexts),

View File

@@ -50,33 +50,34 @@ func TestCLC(t *testing.T) {
ctx := testContext() ctx := testContext()
optional := false optional := false
implicit := true
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
m.AddContext(ctx, AnySdkVersion, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil) m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil) m.AddContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, AnySdkVersion, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil) m.AddContext(ctx, AnySdkVersion, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
// Add some libraries with nested subcontexts. // Add some libraries with nested subcontexts.
m1 := make(ClassLoaderContextMap) m1 := make(ClassLoaderContextMap)
m1.AddContext(ctx, AnySdkVersion, "a1", optional, buildPath(ctx, "a1"), installPath(ctx, "a1"), nil) m1.AddContext(ctx, AnySdkVersion, "a1", optional, implicit, buildPath(ctx, "a1"), installPath(ctx, "a1"), nil)
m1.AddContext(ctx, AnySdkVersion, "b1", optional, buildPath(ctx, "b1"), installPath(ctx, "b1"), nil) m1.AddContext(ctx, AnySdkVersion, "b1", optional, implicit, buildPath(ctx, "b1"), installPath(ctx, "b1"), nil)
m2 := make(ClassLoaderContextMap) m2 := make(ClassLoaderContextMap)
m2.AddContext(ctx, AnySdkVersion, "a2", optional, buildPath(ctx, "a2"), installPath(ctx, "a2"), nil) m2.AddContext(ctx, AnySdkVersion, "a2", optional, implicit, buildPath(ctx, "a2"), installPath(ctx, "a2"), nil)
m2.AddContext(ctx, AnySdkVersion, "b2", optional, buildPath(ctx, "b2"), installPath(ctx, "b2"), nil) m2.AddContext(ctx, AnySdkVersion, "b2", optional, implicit, buildPath(ctx, "b2"), installPath(ctx, "b2"), nil)
m2.AddContext(ctx, AnySdkVersion, "c2", optional, buildPath(ctx, "c2"), installPath(ctx, "c2"), m1) m2.AddContext(ctx, AnySdkVersion, "c2", optional, implicit, buildPath(ctx, "c2"), installPath(ctx, "c2"), m1)
m3 := make(ClassLoaderContextMap) m3 := make(ClassLoaderContextMap)
m3.AddContext(ctx, AnySdkVersion, "a3", optional, buildPath(ctx, "a3"), installPath(ctx, "a3"), nil) m3.AddContext(ctx, AnySdkVersion, "a3", optional, implicit, buildPath(ctx, "a3"), installPath(ctx, "a3"), nil)
m3.AddContext(ctx, AnySdkVersion, "b3", optional, buildPath(ctx, "b3"), installPath(ctx, "b3"), nil) m3.AddContext(ctx, AnySdkVersion, "b3", optional, implicit, buildPath(ctx, "b3"), installPath(ctx, "b3"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), m2) m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), m2)
// When the same library is both in conditional and unconditional context, it should be removed // When the same library is both in conditional and unconditional context, it should be removed
// from conditional context. // from conditional context.
m.AddContext(ctx, 42, "f", optional, buildPath(ctx, "f"), installPath(ctx, "f"), nil) m.AddContext(ctx, 42, "f", optional, implicit, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
m.AddContext(ctx, AnySdkVersion, "f", optional, buildPath(ctx, "f"), installPath(ctx, "f"), nil) m.AddContext(ctx, AnySdkVersion, "f", optional, implicit, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
// Merge map with implicit root library that is among toplevel contexts => does nothing. // Merge map with implicit root library that is among toplevel contexts => does nothing.
m.AddContextMap(m1, "c") m.AddContextMap(m1, "c")
@@ -85,12 +86,12 @@ func TestCLC(t *testing.T) {
m.AddContextMap(m3, "m_g") m.AddContextMap(m3, "m_g")
// Compatibility libraries with unknown install paths get default paths. // Compatibility libraries with unknown install paths get default paths.
m.AddContext(ctx, 29, AndroidHidlManager, optional, buildPath(ctx, AndroidHidlManager), nil, nil) m.AddContext(ctx, 29, AndroidHidlManager, optional, implicit, buildPath(ctx, AndroidHidlManager), nil, nil)
m.AddContext(ctx, 29, AndroidHidlBase, optional, buildPath(ctx, AndroidHidlBase), nil, nil) m.AddContext(ctx, 29, AndroidHidlBase, optional, implicit, buildPath(ctx, AndroidHidlBase), nil, nil)
// Add "android.test.mock" to conditional CLC, observe that is gets removed because it is only // Add "android.test.mock" to conditional CLC, observe that is gets removed because it is only
// needed as a compatibility library if "android.test.runner" is in CLC as well. // needed as a compatibility library if "android.test.runner" is in CLC as well.
m.AddContext(ctx, 30, AndroidTestMock, optional, buildPath(ctx, AndroidTestMock), nil, nil) m.AddContext(ctx, 30, AndroidTestMock, optional, implicit, buildPath(ctx, AndroidTestMock), nil, nil)
valid, validationError := validateClassLoaderContext(m) valid, validationError := validateClassLoaderContext(m)
@@ -164,11 +165,12 @@ func TestCLC(t *testing.T) {
func TestCLCJson(t *testing.T) { func TestCLCJson(t *testing.T) {
ctx := testContext() ctx := testContext()
optional := false optional := false
implicit := true
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil) m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil) m.AddContext(ctx, 29, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil) m.AddContext(ctx, 30, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), nil) m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
jsonCLC := toJsonClassLoaderContext(m) jsonCLC := toJsonClassLoaderContext(m)
restored := fromJsonClassLoaderContext(ctx, jsonCLC) restored := fromJsonClassLoaderContext(ctx, jsonCLC)
android.AssertIntEquals(t, "The size of the maps should be the same.", len(m), len(restored)) android.AssertIntEquals(t, "The size of the maps should be the same.", len(m), len(restored))
@@ -189,12 +191,13 @@ func TestCLCJson(t *testing.T) {
func testCLCUnknownPath(t *testing.T, whichPath string) { func testCLCUnknownPath(t *testing.T, whichPath string) {
ctx := testContext() ctx := testContext()
optional := false optional := false
implicit := true
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
if whichPath == "build" { if whichPath == "build" {
m.AddContext(ctx, AnySdkVersion, "a", optional, nil, nil, nil) m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, nil, nil, nil)
} else { } else {
m.AddContext(ctx, AnySdkVersion, "a", optional, buildPath(ctx, "a"), nil, nil) m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, buildPath(ctx, "a"), nil, nil)
} }
// The library should be added to <uses-library> tags by the manifest_fixer. // The library should be added to <uses-library> tags by the manifest_fixer.
@@ -229,10 +232,11 @@ func TestCLCUnknownInstallPath(t *testing.T) {
func TestCLCNestedConditional(t *testing.T) { func TestCLCNestedConditional(t *testing.T) {
ctx := testContext() ctx := testContext()
optional := false optional := false
implicit := true
m1 := make(ClassLoaderContextMap) m1 := make(ClassLoaderContextMap)
m1.AddContext(ctx, 42, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil) m1.AddContext(ctx, 42, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), m1) err := m.addContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), m1)
checkError(t, err, "nested class loader context shouldn't have conditional part") checkError(t, err, "nested class loader context shouldn't have conditional part")
} }
@@ -241,11 +245,12 @@ func TestCLCNestedConditional(t *testing.T) {
func TestCLCSdkVersionOrder(t *testing.T) { func TestCLCSdkVersionOrder(t *testing.T) {
ctx := testContext() ctx := testContext()
optional := false optional := false
implicit := true
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil) m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil) m.AddContext(ctx, 29, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil) m.AddContext(ctx, 30, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), nil) m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
valid, validationError := validateClassLoaderContext(m) valid, validationError := validateClassLoaderContext(m)

View File

@@ -71,7 +71,9 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
args = append(args, "--use-embedded-dex") args = append(args, "--use-embedded-dex")
} }
requiredUsesLibs, optionalUsesLibs := classLoaderContexts.UsesLibs() // manifest_fixer should add only the implicit SDK libraries inferred by Soong, not those added
// explicitly via `uses_libs`/`optional_uses_libs`.
requiredUsesLibs, optionalUsesLibs := classLoaderContexts.ImplicitUsesLibs()
for _, usesLib := range requiredUsesLibs { for _, usesLib := range requiredUsesLibs {
args = append(args, "--uses-library", usesLib) args = append(args, "--uses-library", usesLib)
} }

View File

@@ -1224,17 +1224,28 @@ func (u *usesLibrary) addLib(lib string, optional bool) {
func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) { func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) {
if !ctx.Config().UnbundledBuild() || ctx.Config().UnbundledBuildImage() { if !ctx.Config().UnbundledBuild() || ctx.Config().UnbundledBuildImage() {
ctx.AddVariationDependencies(nil, usesLibReqTag, u.usesLibraryProperties.Uses_libs...) reqTag := makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false, false)
ctx.AddVariationDependencies(nil, usesLibOptTag, u.presentOptionalUsesLibs(ctx)...) ctx.AddVariationDependencies(nil, reqTag, u.usesLibraryProperties.Uses_libs...)
optTag := makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true, false)
ctx.AddVariationDependencies(nil, optTag, u.presentOptionalUsesLibs(ctx)...)
// Only add these extra dependencies if the module depends on framework libs. This avoids // Only add these extra dependencies if the module depends on framework libs. This avoids
// creating a cyclic dependency: // creating a cyclic dependency:
// e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res. // e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
if hasFrameworkLibs { if hasFrameworkLibs {
// Dexpreopt needs paths to the dex jars of these libraries in order to construct // Add implicit <uses-library> dependencies on compatibility libraries. Some of them are
// class loader context for dex2oat. Add them as a dependency with a special tag. // optional, and some required --- this depends on the most common usage of the library
ctx.AddVariationDependencies(nil, usesLibCompat29ReqTag, dexpreopt.CompatUsesLibs29...) // and may be wrong for some apps (they need explicit `uses_libs`/`optional_uses_libs`).
ctx.AddVariationDependencies(nil, usesLibCompat28OptTag, dexpreopt.OptionalCompatUsesLibs28...)
ctx.AddVariationDependencies(nil, usesLibCompat30OptTag, dexpreopt.OptionalCompatUsesLibs30...) compat28OptTag := makeUsesLibraryDependencyTag(28, true, true)
ctx.AddVariationDependencies(nil, compat28OptTag, dexpreopt.OptionalCompatUsesLibs28...)
compat29ReqTag := makeUsesLibraryDependencyTag(29, false, true)
ctx.AddVariationDependencies(nil, compat29ReqTag, dexpreopt.CompatUsesLibs29...)
compat30OptTag := makeUsesLibraryDependencyTag(30, true, true)
ctx.AddVariationDependencies(nil, compat30OptTag, dexpreopt.OptionalCompatUsesLibs30...)
} }
} }
} }
@@ -1293,7 +1304,7 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext
replaceInList(u.usesLibraryProperties.Uses_libs, dep, libName) replaceInList(u.usesLibraryProperties.Uses_libs, dep, libName)
replaceInList(u.usesLibraryProperties.Optional_uses_libs, dep, libName) replaceInList(u.usesLibraryProperties.Optional_uses_libs, dep, libName)
} }
clcMap.AddContext(ctx, tag.sdkVersion, libName, tag.optional, clcMap.AddContext(ctx, tag.sdkVersion, libName, tag.optional, tag.implicit,
lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts()) lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts())
} else if ctx.Config().AllowMissingDependencies() { } else if ctx.Config().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{dep}) ctx.AddMissingDependencies([]string{dep})

View File

@@ -2398,14 +2398,7 @@ func TestUsesLibraries(t *testing.T) {
expectManifestFixerArgs := `--extract-native-libs=true ` + expectManifestFixerArgs := `--extract-native-libs=true ` +
`--uses-library qux ` + `--uses-library qux ` +
`--uses-library quuz ` + `--uses-library quuz ` +
`--uses-library foo ` + // TODO(b/132357300): "foo" should not be passed to manifest_fixer `--uses-library runtime-library`
`--uses-library com.non.sdk.lib ` + // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer
`--uses-library runtime-library ` +
`--uses-library runtime-required-x ` + // TODO(b/132357300): "runtime-required-x" should not be passed to manifest_fixer
`--uses-library runtime-required-y ` + // TODO(b/132357300): "runtime-required-y" should not be passed to manifest_fixer
`--optional-uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer
`--optional-uses-library runtime-optional-x ` + // TODO(b/132357300): "runtime-optional-x" should not be passed to manifest_fixer
`--optional-uses-library runtime-optional-y` // TODO(b/132357300): "runtime-optional-y" should not be passed to manifest_fixer
android.AssertStringEquals(t, "manifest_fixer args", expectManifestFixerArgs, actualManifestFixerArgs) android.AssertStringEquals(t, "manifest_fixer args", expectManifestFixerArgs, actualManifestFixerArgs)
// Test that all libraries are verified (library order matters). // Test that all libraries are verified (library order matters).

View File

@@ -606,10 +606,8 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
if component, ok := dep.(SdkLibraryComponentDependency); ok { if component, ok := dep.(SdkLibraryComponentDependency); ok {
if lib := component.OptionalSdkLibraryImplementation(); lib != nil { if lib := component.OptionalSdkLibraryImplementation(); lib != nil {
// Add library as optional if it's one of the optional compatibility libs. // Add library as optional if it's one of the optional compatibility libs.
tag := usesLibReqTag optional := android.InList(*lib, dexpreopt.OptionalCompatUsesLibs)
if android.InList(*lib, dexpreopt.OptionalCompatUsesLibs) { tag := makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, optional, true)
tag = usesLibOptTag
}
ctx.AddVariationDependencies(nil, tag, *lib) ctx.AddVariationDependencies(nil, tag, *lib)
} }
} }

View File

@@ -248,15 +248,24 @@ type installDependencyTag struct {
type usesLibraryDependencyTag struct { type usesLibraryDependencyTag struct {
dependencyTag dependencyTag
sdkVersion int // SDK version in which the library appared as a standalone library.
optional bool // If the dependency is optional or required. // SDK version in which the library appared as a standalone library.
sdkVersion int
// If the dependency is optional or required.
optional bool
// Whether this is an implicit dependency inferred by Soong, or an explicit one added via
// `uses_libs`/`optional_uses_libs` properties.
implicit bool
} }
func makeUsesLibraryDependencyTag(sdkVersion int, optional bool) usesLibraryDependencyTag { func makeUsesLibraryDependencyTag(sdkVersion int, optional bool, implicit bool) usesLibraryDependencyTag {
return usesLibraryDependencyTag{ return usesLibraryDependencyTag{
dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)}, dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)},
sdkVersion: sdkVersion, sdkVersion: sdkVersion,
optional: optional, optional: optional,
implicit: implicit,
} }
} }
@@ -285,11 +294,6 @@ var (
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
jniInstallTag = installDependencyTag{name: "jni install"} jniInstallTag = installDependencyTag{name: "jni install"}
binaryInstallTag = installDependencyTag{name: "binary install"} binaryInstallTag = installDependencyTag{name: "binary install"}
usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false)
usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true)
usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true)
usesLibCompat29ReqTag = makeUsesLibraryDependencyTag(29, false)
usesLibCompat30OptTag = makeUsesLibraryDependencyTag(30, true)
) )
func IsLibDepTag(depTag blueprint.DependencyTag) bool { func IsLibDepTag(depTag blueprint.DependencyTag) bool {
@@ -1813,8 +1817,10 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
depTag := ctx.OtherModuleDependencyTag(depModule) depTag := ctx.OtherModuleDependencyTag(depModule)
if depTag == libTag { if depTag == libTag {
// Ok, propagate <uses-library> through non-static library dependencies. // Ok, propagate <uses-library> through non-static library dependencies.
} else if tag, ok := depTag.(usesLibraryDependencyTag); ok && tag.sdkVersion == dexpreopt.AnySdkVersion { } else if tag, ok := depTag.(usesLibraryDependencyTag); ok &&
// Ok, propagate <uses-library> through non-compatibility <uses-library> dependencies. tag.sdkVersion == dexpreopt.AnySdkVersion && tag.implicit {
// Ok, propagate <uses-library> through non-compatibility implicit <uses-library>
// dependencies.
} else if depTag == staticLibTag { } else if depTag == staticLibTag {
// Propagate <uses-library> through static library dependencies, unless it is a component // Propagate <uses-library> through static library dependencies, unless it is a component
// library (such as stubs). Component libraries have a dependency on their SDK library, // library (such as stubs). Component libraries have a dependency on their SDK library,
@@ -1832,7 +1838,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
// <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies // <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies
// from its CLC should be added to the current CLC. // from its CLC should be added to the current CLC.
if sdkLib != nil { if sdkLib != nil {
clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false, clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false, true,
dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts()) dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
} else { } else {
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)