Revert "Don't add uses_libs/optional_uses_libs to the manifest_fixer."

This reverts commit 0b1c70efbc.

The reverted commit was based on the idea that uses-libraries that are
explicitly specified in build files should not be implicitly added to
the manifest, as that would mean that anything added to the build files
will flow to the manifest.

Although this logic is correct, it prevents propagation of
uses-libraries from dependencies, which is wrong: if a library has an
explicit uses-library property in Android.bp, this property is expected
to be propagated to the library's dependencies. Failing to do so would
mean that every user of that library has to add uses-library property to
their build files, which doesn't scale (see b/214255490 for example).

Bug: 214255490
Test: lunch aosp_cf_x86_64_phone-userdebug && m && launch_cvd \
    && adb wait-for-device && adb root \
    && adb logcat | grep -E 'ClassLoaderContext [a-z ]+ mismatch'
    # empty output, no errors at boot
Change-Id: I6f420e76a89aa2f37be99f877711736640f2c361
This commit is contained in:
Ulya Trafimovich
2022-05-04 12:00:02 +01:00
parent 91f015e73e
commit f5d91bb3b4
10 changed files with 1651 additions and 120 deletions

View File

@@ -196,10 +196,6 @@ type ClassLoaderContext struct {
// If the library is optional or required.
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).
Host android.Path
@@ -290,9 +286,8 @@ const UnknownInstallLibraryPath = "error"
const AnySdkVersion int = android.FutureApiLevelInt
// 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, optional, implicit bool, hostPath, installPath android.Path,
nestedClcMap ClassLoaderContextMap) error {
func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathContext, sdkVer int, lib string,
optional bool, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) error {
// For prebuilts, library should have the same name as the source module.
lib = android.RemoveOptionalPrebuiltPrefix(lib)
@@ -341,7 +336,6 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{
Name: lib,
Optional: optional,
Implicit: implicit,
Host: hostPath,
Device: devicePath,
Subcontexts: subcontexts,
@@ -354,10 +348,9 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
// 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).
func (clcMap ClassLoaderContextMap) AddContext(ctx android.ModuleInstallPathContext, sdkVer int,
lib string, optional, implicit bool, hostPath, installPath android.Path,
nestedClcMap ClassLoaderContextMap) {
lib string, optional bool, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) {
err := clcMap.addContext(ctx, sdkVer, lib, optional, implicit, hostPath, installPath, nestedClcMap)
err := clcMap.addContext(ctx, sdkVer, lib, optional, hostPath, installPath, nestedClcMap)
if err != nil {
ctx.ModuleErrorf(err.Error())
}
@@ -401,15 +394,13 @@ func (clcMap ClassLoaderContextMap) AddContextMap(otherClcMap ClassLoaderContext
// 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.
// Required and optional libraries are in separate lists.
func (clcMap ClassLoaderContextMap) usesLibs(implicit bool) (required []string, optional []string) {
func (clcMap ClassLoaderContextMap) UsesLibs() (required []string, optional []string) {
if clcMap != nil {
clcs := clcMap[AnySdkVersion]
required = make([]string, 0, len(clcs))
optional = make([]string, 0, len(clcs))
for _, clc := range clcs {
if implicit && !clc.Implicit {
// Skip, this is an explicit library and we need only the implicit ones.
} else if clc.Optional {
if clc.Optional {
optional = append(optional, clc.Name)
} else {
required = append(required, clc.Name)
@@ -419,14 +410,6 @@ func (clcMap ClassLoaderContextMap) usesLibs(implicit bool) (required []string,
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 {
jsonCLC := toJsonClassLoaderContext(clcMap)
bytes, err := json.MarshalIndent(jsonCLC, "", " ")
@@ -631,7 +614,6 @@ func computeClassLoaderContextRec(clcs []*ClassLoaderContext) (string, string, a
type jsonClassLoaderContext struct {
Name string
Optional bool
Implicit bool
Host string
Device string
Subcontexts []*jsonClassLoaderContext
@@ -664,7 +646,6 @@ func fromJsonClassLoaderContextRec(ctx android.PathContext, jClcs []*jsonClassLo
clcs = append(clcs, &ClassLoaderContext{
Name: clc.Name,
Optional: clc.Optional,
Implicit: clc.Implicit,
Host: constructPath(ctx, clc.Host),
Device: clc.Device,
Subcontexts: fromJsonClassLoaderContextRec(ctx, clc.Subcontexts),
@@ -700,7 +681,6 @@ func toJsonClassLoaderContextRec(clcs []*ClassLoaderContext) []*jsonClassLoaderC
jClcs[i] = &jsonClassLoaderContext{
Name: clc.Name,
Optional: clc.Optional,
Implicit: clc.Implicit,
Host: host,
Device: clc.Device,
Subcontexts: toJsonClassLoaderContextRec(clc.Subcontexts),

View File

@@ -50,34 +50,33 @@ func TestCLC(t *testing.T) {
ctx := testContext()
optional := false
implicit := true
m := make(ClassLoaderContextMap)
m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, AnySdkVersion, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, AnySdkVersion, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
// Add some libraries with nested subcontexts.
m1 := make(ClassLoaderContextMap)
m1.AddContext(ctx, AnySdkVersion, "a1", optional, implicit, buildPath(ctx, "a1"), installPath(ctx, "a1"), nil)
m1.AddContext(ctx, AnySdkVersion, "b1", optional, implicit, buildPath(ctx, "b1"), installPath(ctx, "b1"), nil)
m1.AddContext(ctx, AnySdkVersion, "a1", optional, buildPath(ctx, "a1"), installPath(ctx, "a1"), nil)
m1.AddContext(ctx, AnySdkVersion, "b1", optional, buildPath(ctx, "b1"), installPath(ctx, "b1"), nil)
m2 := make(ClassLoaderContextMap)
m2.AddContext(ctx, AnySdkVersion, "a2", optional, implicit, buildPath(ctx, "a2"), installPath(ctx, "a2"), nil)
m2.AddContext(ctx, AnySdkVersion, "b2", optional, implicit, buildPath(ctx, "b2"), installPath(ctx, "b2"), nil)
m2.AddContext(ctx, AnySdkVersion, "c2", optional, implicit, buildPath(ctx, "c2"), installPath(ctx, "c2"), m1)
m2.AddContext(ctx, AnySdkVersion, "a2", optional, buildPath(ctx, "a2"), installPath(ctx, "a2"), nil)
m2.AddContext(ctx, AnySdkVersion, "b2", optional, buildPath(ctx, "b2"), installPath(ctx, "b2"), nil)
m2.AddContext(ctx, AnySdkVersion, "c2", optional, buildPath(ctx, "c2"), installPath(ctx, "c2"), m1)
m3 := make(ClassLoaderContextMap)
m3.AddContext(ctx, AnySdkVersion, "a3", optional, implicit, buildPath(ctx, "a3"), installPath(ctx, "a3"), nil)
m3.AddContext(ctx, AnySdkVersion, "b3", optional, implicit, buildPath(ctx, "b3"), installPath(ctx, "b3"), nil)
m3.AddContext(ctx, AnySdkVersion, "a3", optional, buildPath(ctx, "a3"), installPath(ctx, "a3"), nil)
m3.AddContext(ctx, AnySdkVersion, "b3", optional, buildPath(ctx, "b3"), installPath(ctx, "b3"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), m2)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), m2)
// When the same library is both in conditional and unconditional context, it should be removed
// from conditional context.
m.AddContext(ctx, 42, "f", optional, implicit, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
m.AddContext(ctx, AnySdkVersion, "f", optional, implicit, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
m.AddContext(ctx, 42, "f", optional, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
m.AddContext(ctx, AnySdkVersion, "f", optional, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
// Merge map with implicit root library that is among toplevel contexts => does nothing.
m.AddContextMap(m1, "c")
@@ -86,12 +85,12 @@ func TestCLC(t *testing.T) {
m.AddContextMap(m3, "m_g")
// Compatibility libraries with unknown install paths get default paths.
m.AddContext(ctx, 29, AndroidHidlManager, optional, implicit, buildPath(ctx, AndroidHidlManager), nil, nil)
m.AddContext(ctx, 29, AndroidHidlBase, optional, implicit, buildPath(ctx, AndroidHidlBase), nil, nil)
m.AddContext(ctx, 29, AndroidHidlManager, optional, buildPath(ctx, AndroidHidlManager), nil, nil)
m.AddContext(ctx, 29, AndroidHidlBase, optional, buildPath(ctx, AndroidHidlBase), nil, nil)
// 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.
m.AddContext(ctx, 30, AndroidTestMock, optional, implicit, buildPath(ctx, AndroidTestMock), nil, nil)
m.AddContext(ctx, 30, AndroidTestMock, optional, buildPath(ctx, AndroidTestMock), nil, nil)
valid, validationError := validateClassLoaderContext(m)
@@ -165,12 +164,11 @@ func TestCLC(t *testing.T) {
func TestCLCJson(t *testing.T) {
ctx := testContext()
optional := false
implicit := true
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
jsonCLC := toJsonClassLoaderContext(m)
restored := fromJsonClassLoaderContext(ctx, jsonCLC)
android.AssertIntEquals(t, "The size of the maps should be the same.", len(m), len(restored))
@@ -191,13 +189,12 @@ func TestCLCJson(t *testing.T) {
func testCLCUnknownPath(t *testing.T, whichPath string) {
ctx := testContext()
optional := false
implicit := true
m := make(ClassLoaderContextMap)
if whichPath == "build" {
m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, nil, nil, nil)
m.AddContext(ctx, AnySdkVersion, "a", optional, nil, nil, nil)
} else {
m.AddContext(ctx, AnySdkVersion, "a", optional, implicit, buildPath(ctx, "a"), nil, nil)
m.AddContext(ctx, AnySdkVersion, "a", optional, buildPath(ctx, "a"), nil, nil)
}
// The library should be added to <uses-library> tags by the manifest_fixer.
@@ -232,11 +229,10 @@ func TestCLCUnknownInstallPath(t *testing.T) {
func TestCLCNestedConditional(t *testing.T) {
ctx := testContext()
optional := false
implicit := true
m1 := make(ClassLoaderContextMap)
m1.AddContext(ctx, 42, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m1.AddContext(ctx, 42, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), m1)
err := m.addContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), m1)
checkError(t, err, "nested class loader context shouldn't have conditional part")
}
@@ -245,12 +241,11 @@ func TestCLCNestedConditional(t *testing.T) {
func TestCLCSdkVersionOrder(t *testing.T) {
ctx := testContext()
optional := false
implicit := true
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, implicit, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 29, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 30, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m.AddContext(ctx, AnySdkVersion, "d", optional, buildPath(ctx, "d"), installPath(ctx, "d"), nil)
valid, validationError := validateClassLoaderContext(m)
@@ -287,7 +282,6 @@ func TestCLCSdkVersionOrder(t *testing.T) {
func TestCLCMExcludeLibs(t *testing.T) {
ctx := testContext()
const optional = false
const implicit = true
excludeLibs := func(t *testing.T, m ClassLoaderContextMap, excluded_libs ...string) ClassLoaderContextMap {
// Dump the CLCM before creating a new copy that excludes a specific set of libraries.
@@ -305,7 +299,7 @@ func TestCLCMExcludeLibs(t *testing.T) {
t.Run("exclude nothing", func(t *testing.T) {
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
a := excludeLibs(t, m)
@@ -314,7 +308,6 @@ func TestCLCMExcludeLibs(t *testing.T) {
{
"Name": "a",
"Optional": false,
"Implicit": true,
"Host": "out/soong/a.jar",
"Device": "/system/a.jar",
"Subcontexts": []
@@ -325,8 +318,8 @@ func TestCLCMExcludeLibs(t *testing.T) {
t.Run("one item from list", func(t *testing.T) {
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 28, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 28, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
a := excludeLibs(t, m, "a")
@@ -335,7 +328,6 @@ func TestCLCMExcludeLibs(t *testing.T) {
{
"Name": "b",
"Optional": false,
"Implicit": true,
"Host": "out/soong/b.jar",
"Device": "/system/b.jar",
"Subcontexts": []
@@ -347,8 +339,8 @@ func TestCLCMExcludeLibs(t *testing.T) {
t.Run("all items from a list", func(t *testing.T) {
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 28, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, 28, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
a := excludeLibs(t, m, "a", "b")
@@ -357,11 +349,11 @@ func TestCLCMExcludeLibs(t *testing.T) {
t.Run("items from a subcontext", func(t *testing.T) {
s := make(ClassLoaderContextMap)
s.AddContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
s.AddContext(ctx, AnySdkVersion, "c", optional, implicit, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
s.AddContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
s.AddContext(ctx, AnySdkVersion, "c", optional, buildPath(ctx, "c"), installPath(ctx, "c"), nil)
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), s)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), s)
a := excludeLibs(t, m, "b")
@@ -370,14 +362,12 @@ func TestCLCMExcludeLibs(t *testing.T) {
{
"Name": "a",
"Optional": false,
"Implicit": true,
"Host": "out/soong/a.jar",
"Device": "/system/a.jar",
"Subcontexts": [
{
"Name": "c",
"Optional": false,
"Implicit": true,
"Host": "out/soong/c.jar",
"Device": "/system/c.jar",
"Subcontexts": []
@@ -393,16 +383,14 @@ func TestCLCMExcludeLibs(t *testing.T) {
func TestCLCtoJSON(t *testing.T) {
ctx := testContext()
optional := false
implicit := true
m := make(ClassLoaderContextMap)
m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
m.AddContext(ctx, 28, "a", optional, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m.AddContext(ctx, AnySdkVersion, "b", optional, buildPath(ctx, "b"), installPath(ctx, "b"), nil)
android.AssertStringEquals(t, "output CLCM ", `{
"28": [
{
"Name": "a",
"Optional": false,
"Implicit": true,
"Host": "out/soong/a.jar",
"Device": "/system/a.jar",
"Subcontexts": []
@@ -412,7 +400,6 @@ func TestCLCtoJSON(t *testing.T) {
{
"Name": "b",
"Optional": false,
"Implicit": true,
"Host": "out/soong/b.jar",
"Device": "/system/b.jar",
"Subcontexts": []