Merge changes Iebfbf2ff,Ibd974268

* changes:
  Rename fields and methods to reflect class loader context changes.
  Do not add dependencies of shared SDK libraries to manifest_fixer.
This commit is contained in:
Ulyana Trafimovich 2020-11-17 10:22:00 +00:00 committed by Gerrit Code Review
commit d8d8e726a5
10 changed files with 108 additions and 79 deletions

View file

@ -71,6 +71,10 @@ type ClassLoaderContext struct {
// Nested class loader subcontexts for dependencies. // Nested class loader subcontexts for dependencies.
Subcontexts []*ClassLoaderContext Subcontexts []*ClassLoaderContext
// If the library is a shared library. This affects which elements of class loader context are
// added as <uses-library> tags by the manifest_fixer (dependencies of shared libraries aren't).
IsSharedLibrary bool
} }
// ClassLoaderContextMap is a map from SDK version to a class loader context. // ClassLoaderContextMap is a map from SDK version to a class loader context.
@ -81,7 +85,7 @@ type ClassLoaderContextMap map[int][]*ClassLoaderContext
// 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, lib string,
hostPath, installPath android.Path, strict bool, nestedClcMap ClassLoaderContextMap) error { shared bool, hostPath, installPath android.Path, strict bool, nestedClcMap ClassLoaderContextMap) error {
// If missing dependencies are allowed, the build shouldn't fail when a <uses-library> is // If missing dependencies are allowed, the build shouldn't fail when a <uses-library> is
// not found. However, this is likely to result is disabling dexpreopt, as it won't be // not found. However, this is likely to result is disabling dexpreopt, as it won't be
@ -128,46 +132,46 @@ func (clcMap ClassLoaderContextMap) addContext(ctx android.ModuleInstallPathCont
} }
clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{ clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{
Name: lib, Name: lib,
Host: hostPath, Host: hostPath,
Device: devicePath, Device: devicePath,
Subcontexts: subcontexts, Subcontexts: subcontexts,
IsSharedLibrary: shared,
}) })
return nil return nil
} }
// Wrapper around addContext that reports errors. // Wrapper around addContext that reports errors.
func (clcMap ClassLoaderContextMap) addContextOrReportError(ctx android.ModuleInstallPathContext, sdkVer int, lib string, func (clcMap ClassLoaderContextMap) addContextOrReportError(ctx android.ModuleInstallPathContext, sdkVer int, lib string,
hostPath, installPath android.Path, strict bool, nestedClcMap ClassLoaderContextMap) { shared bool, hostPath, installPath android.Path, strict bool, nestedClcMap ClassLoaderContextMap) {
err := clcMap.addContext(ctx, sdkVer, lib, hostPath, installPath, strict, nestedClcMap) err := clcMap.addContext(ctx, sdkVer, lib, shared, hostPath, installPath, strict, nestedClcMap)
if err != nil { if err != nil {
ctx.ModuleErrorf(err.Error()) ctx.ModuleErrorf(err.Error())
android.ReportPathErrorf(ctx, err.Error())
} }
} }
// Add class loader context. Fail on unknown build/install paths. // Add class loader context. Fail on unknown build/install paths.
func (clcMap ClassLoaderContextMap) AddContext(ctx android.ModuleInstallPathContext, lib string, func (clcMap ClassLoaderContextMap) AddContext(ctx android.ModuleInstallPathContext, lib string,
hostPath, installPath android.Path) { shared bool, hostPath, installPath android.Path) {
clcMap.addContextOrReportError(ctx, AnySdkVersion, lib, hostPath, installPath, true, nil) clcMap.addContextOrReportError(ctx, AnySdkVersion, lib, shared, hostPath, installPath, true, nil)
} }
// Add class loader context if the library exists. Don't fail on unknown build/install paths. // Add class loader context if the library exists. Don't fail on unknown build/install paths.
func (clcMap ClassLoaderContextMap) MaybeAddContext(ctx android.ModuleInstallPathContext, lib *string, func (clcMap ClassLoaderContextMap) MaybeAddContext(ctx android.ModuleInstallPathContext, lib *string,
hostPath, installPath android.Path) { shared bool, hostPath, installPath android.Path) {
if lib != nil { if lib != nil {
clcMap.addContextOrReportError(ctx, AnySdkVersion, *lib, hostPath, installPath, false, nil) clcMap.addContextOrReportError(ctx, AnySdkVersion, *lib, shared, hostPath, installPath, false, nil)
} }
} }
// Add class loader context for the given SDK version. Fail on unknown build/install paths. // Add class loader context for the given SDK version. Fail on unknown build/install paths.
func (clcMap ClassLoaderContextMap) AddContextForSdk(ctx android.ModuleInstallPathContext, sdkVer int, func (clcMap ClassLoaderContextMap) AddContextForSdk(ctx android.ModuleInstallPathContext, sdkVer int,
lib string, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) { lib string, shared bool, hostPath, installPath android.Path, nestedClcMap ClassLoaderContextMap) {
clcMap.addContextOrReportError(ctx, sdkVer, lib, hostPath, installPath, true, nestedClcMap) clcMap.addContextOrReportError(ctx, sdkVer, lib, shared, hostPath, installPath, true, nestedClcMap)
} }
// Merge the other class loader context map into this one, do not override existing entries. // Merge the other class loader context map into this one, do not override existing entries.
@ -204,7 +208,9 @@ func (clcMap ClassLoaderContextMap) AddContextMap(otherClcMap ClassLoaderContext
} }
} }
// List of libraries in the unconditional class loader context, excluding dependencies of shared libraries. // List of libraries in the unconditional class loader context, excluding dependencies of shared
// libraries. These libraries should be in the <uses-library> tags in the manifest. Some of them may
// be present in the original manifest, others are added by the manifest_fixer.
func (clcMap ClassLoaderContextMap) UsesLibs() (ulibs []string) { func (clcMap ClassLoaderContextMap) UsesLibs() (ulibs []string) {
if clcMap != nil { if clcMap != nil {
// compatibility libraries (those in conditional context) are not added to <uses-library> tags // compatibility libraries (those in conditional context) are not added to <uses-library> tags
@ -217,7 +223,12 @@ func (clcMap ClassLoaderContextMap) UsesLibs() (ulibs []string) {
func usesLibsRec(clcs []*ClassLoaderContext) (ulibs []string) { func usesLibsRec(clcs []*ClassLoaderContext) (ulibs []string) {
for _, clc := range clcs { for _, clc := range clcs {
ulibs = append(ulibs, clc.Name) ulibs = append(ulibs, clc.Name)
ulibs = append(ulibs, usesLibsRec(clc.Subcontexts)...) // <uses-library> tags in the manifest should not include dependencies of shared libraries,
// because PackageManager already tracks all such dependencies and automatically adds their
// class loader contexts as subcontext of the shared library.
if !clc.IsSharedLibrary {
ulibs = append(ulibs, usesLibsRec(clc.Subcontexts)...)
}
} }
return ulibs return ulibs
} }

View file

@ -25,6 +25,11 @@ import (
"android/soong/android" "android/soong/android"
) )
const (
shared = true // dependencies are not added to uses libs
nonshared = false // dependencies are added to uses libs
)
func TestCLC(t *testing.T) { func TestCLC(t *testing.T) {
// Construct class loader context with the following structure: // Construct class loader context with the following structure:
// . // .
@ -50,36 +55,36 @@ func TestCLC(t *testing.T) {
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
m.AddContext(ctx, "a", buildPath(ctx, "a"), installPath(ctx, "a")) m.AddContext(ctx, "a", nonshared, buildPath(ctx, "a"), installPath(ctx, "a"))
m.AddContext(ctx, "b", buildPath(ctx, "b"), installPath(ctx, "b")) m.AddContext(ctx, "b", shared, buildPath(ctx, "b"), installPath(ctx, "b"))
// "Maybe" variant in the good case: add as usual. // "Maybe" variant in the good case: add as usual.
c := "c" c := "c"
m.MaybeAddContext(ctx, &c, buildPath(ctx, "c"), installPath(ctx, "c")) m.MaybeAddContext(ctx, &c, nonshared, buildPath(ctx, "c"), installPath(ctx, "c"))
// "Maybe" variant in the bad case: don't add library with unknown name, keep going. // "Maybe" variant in the bad case: don't add library with unknown name, keep going.
m.MaybeAddContext(ctx, nil, nil, nil) m.MaybeAddContext(ctx, nil, nonshared, nil, nil)
// Add some libraries with nested subcontexts. // Add some libraries with nested subcontexts.
m1 := make(ClassLoaderContextMap) m1 := make(ClassLoaderContextMap)
m1.AddContext(ctx, "a1", buildPath(ctx, "a1"), installPath(ctx, "a1")) m1.AddContext(ctx, "a1", nonshared, buildPath(ctx, "a1"), installPath(ctx, "a1"))
m1.AddContext(ctx, "b1", buildPath(ctx, "b1"), installPath(ctx, "b1")) m1.AddContext(ctx, "b1", shared, buildPath(ctx, "b1"), installPath(ctx, "b1"))
m2 := make(ClassLoaderContextMap) m2 := make(ClassLoaderContextMap)
m2.AddContext(ctx, "a2", buildPath(ctx, "a2"), installPath(ctx, "a2")) m2.AddContext(ctx, "a2", nonshared, buildPath(ctx, "a2"), installPath(ctx, "a2"))
m2.AddContext(ctx, "b2", buildPath(ctx, "b2"), installPath(ctx, "b2")) m2.AddContext(ctx, "b2", shared, buildPath(ctx, "b2"), installPath(ctx, "b2"))
m2.AddContextForSdk(ctx, AnySdkVersion, "c2", buildPath(ctx, "c2"), installPath(ctx, "c2"), m1) m2.AddContextForSdk(ctx, AnySdkVersion, "c2", shared, buildPath(ctx, "c2"), installPath(ctx, "c2"), m1)
m3 := make(ClassLoaderContextMap) m3 := make(ClassLoaderContextMap)
m3.AddContext(ctx, "a3", buildPath(ctx, "a3"), installPath(ctx, "a3")) m3.AddContext(ctx, "a3", nonshared, buildPath(ctx, "a3"), installPath(ctx, "a3"))
m3.AddContext(ctx, "b3", buildPath(ctx, "b3"), installPath(ctx, "b3")) m3.AddContext(ctx, "b3", shared, buildPath(ctx, "b3"), installPath(ctx, "b3"))
m.AddContextForSdk(ctx, AnySdkVersion, "d", buildPath(ctx, "d"), installPath(ctx, "d"), m2) m.AddContextForSdk(ctx, AnySdkVersion, "d", nonshared, 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.AddContextForSdk(ctx, 42, "f", buildPath(ctx, "f"), installPath(ctx, "f"), nil) m.AddContextForSdk(ctx, 42, "f", nonshared, buildPath(ctx, "f"), installPath(ctx, "f"), nil)
m.AddContextForSdk(ctx, AnySdkVersion, "f", buildPath(ctx, "f"), installPath(ctx, "f"), nil) m.AddContextForSdk(ctx, AnySdkVersion, "f", nonshared, 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")
@ -88,12 +93,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.AddContextForSdk(ctx, 29, AndroidHidlManager, buildPath(ctx, AndroidHidlManager), nil, nil) m.AddContextForSdk(ctx, 29, AndroidHidlManager, nonshared, buildPath(ctx, AndroidHidlManager), nil, nil)
m.AddContextForSdk(ctx, 29, AndroidHidlBase, buildPath(ctx, AndroidHidlBase), nil, nil) m.AddContextForSdk(ctx, 29, AndroidHidlBase, nonshared, 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.AddContextForSdk(ctx, 30, AndroidTestMock, buildPath(ctx, AndroidTestMock), nil, nil) m.AddContextForSdk(ctx, 30, AndroidTestMock, nonshared, buildPath(ctx, AndroidTestMock), nil, nil)
valid, validationError := validateClassLoaderContext(m) valid, validationError := validateClassLoaderContext(m)
@ -153,7 +158,7 @@ func TestCLC(t *testing.T) {
// Test for libraries that are added by the manifest_fixer. // Test for libraries that are added by the manifest_fixer.
t.Run("uses libs", func(t *testing.T) { t.Run("uses libs", func(t *testing.T) {
wantUsesLibs := []string{"a", "b", "c", "d", "a2", "b2", "c2", "a1", "b1", "f", "a3", "b3"} wantUsesLibs := []string{"a", "b", "c", "d", "a2", "b2", "c2", "f", "a3", "b3"}
if !reflect.DeepEqual(wantUsesLibs, haveUsesLibs) { if !reflect.DeepEqual(wantUsesLibs, haveUsesLibs) {
t.Errorf("\nwant uses libs: %s\nhave uses libs: %s", wantUsesLibs, haveUsesLibs) t.Errorf("\nwant uses libs: %s\nhave uses libs: %s", wantUsesLibs, haveUsesLibs)
} }
@ -164,7 +169,7 @@ func TestCLC(t *testing.T) {
func TestCLCUnknownBuildPath(t *testing.T) { func TestCLCUnknownBuildPath(t *testing.T) {
ctx := testContext() ctx := testContext()
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "a", nil, nil, true, nil) err := m.addContext(ctx, AnySdkVersion, "a", nonshared, nil, nil, true, nil)
checkError(t, err, "unknown build path to <uses-library> \"a\"") checkError(t, err, "unknown build path to <uses-library> \"a\"")
} }
@ -172,7 +177,7 @@ func TestCLCUnknownBuildPath(t *testing.T) {
func TestCLCUnknownInstallPath(t *testing.T) { func TestCLCUnknownInstallPath(t *testing.T) {
ctx := testContext() ctx := testContext()
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "a", buildPath(ctx, "a"), nil, true, nil) err := m.addContext(ctx, AnySdkVersion, "a", nonshared, buildPath(ctx, "a"), nil, true, nil)
checkError(t, err, "unknown install path to <uses-library> \"a\"") checkError(t, err, "unknown install path to <uses-library> \"a\"")
} }
@ -181,7 +186,7 @@ func TestCLCMaybeAdd(t *testing.T) {
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
a := "a" a := "a"
m.MaybeAddContext(ctx, &a, nil, nil) m.MaybeAddContext(ctx, &a, nonshared, 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.
t.Run("maybe add", func(t *testing.T) { t.Run("maybe add", func(t *testing.T) {
@ -203,9 +208,9 @@ func TestCLCMaybeAdd(t *testing.T) {
func TestCLCNestedConditional(t *testing.T) { func TestCLCNestedConditional(t *testing.T) {
ctx := testContext() ctx := testContext()
m1 := make(ClassLoaderContextMap) m1 := make(ClassLoaderContextMap)
m1.AddContextForSdk(ctx, 42, "a", buildPath(ctx, "a"), installPath(ctx, "a"), nil) m1.AddContextForSdk(ctx, 42, "a", nonshared, buildPath(ctx, "a"), installPath(ctx, "a"), nil)
m := make(ClassLoaderContextMap) m := make(ClassLoaderContextMap)
err := m.addContext(ctx, AnySdkVersion, "b", buildPath(ctx, "b"), installPath(ctx, "b"), true, m1) err := m.addContext(ctx, AnySdkVersion, "b", nonshared, buildPath(ctx, "b"), installPath(ctx, "b"), true, 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")
} }

View file

@ -259,16 +259,16 @@ var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
}) })
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext,
sdkLibraries dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) { classLoaderContexts dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) {
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags := transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags :=
aaptLibs(ctx, sdkContext, sdkLibraries) aaptLibs(ctx, sdkContext, classLoaderContexts)
// App manifest file // App manifest file
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries, manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, classLoaderContexts,
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode, a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode,
a.LoggingParent) a.LoggingParent)
@ -389,15 +389,15 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext,
} }
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dexpreopt.ClassLoaderContextMap) ( func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) { transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) {
var sharedLibs android.Paths var sharedLibs android.Paths
if sdkLibraries == nil { if classLoaderContexts == nil {
// Not all callers need to compute class loader context, those who don't just pass nil. // Not all callers need to compute class loader context, those who don't just pass nil.
// Create a temporary class loader context here (it will be computed, but not used). // Create a temporary class loader context here (it will be computed, but not used).
sdkLibraries = make(dexpreopt.ClassLoaderContextMap) classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
} }
sdkDep := decodeSdkDep(ctx, sdkContext) sdkDep := decodeSdkDep(ctx, sdkContext)
@ -426,7 +426,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dex
// (including the java_sdk_library) itself then append any implicit sdk library // (including the java_sdk_library) itself then append any implicit sdk library
// names to the list of sdk libraries to be added to the manifest. // names to the list of sdk libraries to be added to the manifest.
if component, ok := module.(SdkLibraryComponentDependency); ok { if component, ok := module.(SdkLibraryComponentDependency); ok {
sdkLibraries.MaybeAddContext(ctx, component.OptionalImplicitSdkLibrary(), classLoaderContexts.MaybeAddContext(ctx, component.OptionalImplicitSdkLibrary(), true,
component.DexJarBuildPath(), component.DexJarInstallPath()) component.DexJarBuildPath(), component.DexJarInstallPath())
} }
@ -439,7 +439,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dex
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...) transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
sdkLibraries.AddContextMap(aarDep.ExportedSdkLibs(), depName) classLoaderContexts.AddContextMap(aarDep.ClassLoaderContexts(), depName)
if aarDep.ExportedAssets().Valid() { if aarDep.ExportedAssets().Valid() {
assets = append(assets, aarDep.ExportedAssets().Path()) assets = append(assets, aarDep.ExportedAssets().Path())
} }
@ -461,7 +461,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dex
// Add nested dependencies after processing the direct dependency: if it is a <uses-library>, // Add nested dependencies after processing the direct dependency: if it is a <uses-library>,
// nested context is added as its subcontext, and should not be re-added at the top-level. // nested context is added as its subcontext, and should not be re-added at the top-level.
if dep, ok := module.(Dependency); ok { if dep, ok := module.(Dependency); ok {
sdkLibraries.AddContextMap(dep.ExportedSdkLibs(), depName) classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), depName)
} }
}) })
@ -514,8 +514,8 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.aapt.isLibrary = true a.aapt.isLibrary = true
a.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) a.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
a.aapt.buildActions(ctx, sdkContext(a), a.exportedSdkLibs) a.aapt.buildActions(ctx, sdkContext(a), a.classLoaderContexts)
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
@ -832,7 +832,7 @@ func (a *AARImport) AidlIncludeDirs() android.Paths {
return nil return nil
} }
func (a *AARImport) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
return nil return nil
} }

View file

@ -44,7 +44,7 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
sdkLibraries dexpreopt.ClassLoaderContextMap, isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, classLoaderContexts dexpreopt.ClassLoaderContextMap, isLibrary, useEmbeddedNativeLibs, usesNonSdkApis,
useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path { useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path {
var args []string var args []string
@ -71,7 +71,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
args = append(args, "--use-embedded-dex") args = append(args, "--use-embedded-dex")
} }
for _, usesLib := range sdkLibraries.UsesLibs() { for _, usesLib := range classLoaderContexts.UsesLibs() {
if inList(usesLib, dexpreopt.OptionalCompatUsesLibs) { if inList(usesLib, dexpreopt.OptionalCompatUsesLibs) {
args = append(args, "--optional-uses-library", usesLib) args = append(args, "--optional-uses-library", usesLib)
} else { } else {

View file

@ -115,7 +115,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile) entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile)
} }
entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs.UsesLibs()...) entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.classLoaderContexts.UsesLibs()...)
if len(library.additionalCheckedModules) != 0 { if len(library.additionalCheckedModules) != 0 {
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...) entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)

View file

@ -566,7 +566,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
a.aapt.splitNames = a.appProperties.Package_splits a.aapt.splitNames = a.appProperties.Package_splits
a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
a.aapt.buildActions(ctx, sdkContext(a), a.exportedSdkLibs, aaptLinkFlags...) a.aapt.buildActions(ctx, sdkContext(a), a.classLoaderContexts, aaptLinkFlags...)
// apps manifests are handled by aapt, don't let Module see them // apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil a.properties.Manifest = nil
@ -608,7 +608,7 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
} }
a.dexpreopter.uncompressedDex = *a.dexProperties.Uncompress_dex a.dexpreopter.uncompressedDex = *a.dexProperties.Uncompress_dex
a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
a.dexpreopter.classLoaderContexts = a.exportedSdkLibs a.dexpreopter.classLoaderContexts = a.classLoaderContexts
a.dexpreopter.manifestFile = a.mergedManifestFile a.dexpreopter.manifestFile = a.mergedManifestFile
if ctx.ModuleName() != "framework-res" { if ctx.ModuleName() != "framework-res" {
@ -779,7 +779,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput
} }
a.exportedSdkLibs = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
// Process all building blocks, from AAPT to certificates. // Process all building blocks, from AAPT to certificates.
a.aaptBuildActions(ctx) a.aaptBuildActions(ctx)
@ -788,7 +788,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.usesLibrary.freezeEnforceUsesLibraries() a.usesLibrary.freezeEnforceUsesLibraries()
// Add implicit SDK libraries to <uses-library> list. // Add implicit SDK libraries to <uses-library> list.
for _, usesLib := range a.exportedSdkLibs.UsesLibs() { for _, usesLib := range a.classLoaderContexts.UsesLibs() {
a.usesLibrary.addLib(usesLib, inList(usesLib, dexpreopt.OptionalCompatUsesLibs)) a.usesLibrary.addLib(usesLib, inList(usesLib, dexpreopt.OptionalCompatUsesLibs))
} }
@ -1981,8 +1981,8 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext
if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok {
dep := ctx.OtherModuleName(m) dep := ctx.OtherModuleName(m)
if lib, ok := m.(Dependency); ok { if lib, ok := m.(Dependency); ok {
clcMap.AddContextForSdk(ctx, tag.sdkVersion, dep, clcMap.AddContextForSdk(ctx, tag.sdkVersion, dep, isSharedSdkLibrary(m),
lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ExportedSdkLibs()) lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts())
} else if ctx.Config().AllowMissingDependencies() { } else if ctx.Config().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{dep}) ctx.AddMissingDependencies([]string{dep})
} else { } else {
@ -1995,6 +1995,11 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext
return clcMap return clcMap
} }
func isSharedSdkLibrary(m android.Module) bool {
lib, ok := m.(SdkLibraryDependency)
return ok && lib.IsSharedLibrary()
}
// enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs // enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs
// properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true // properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true
// unconditionally in the future. // unconditionally in the future.

View file

@ -163,7 +163,7 @@ func (d *DeviceHostConverter) AidlIncludeDirs() android.Paths {
return nil return nil
} }
func (d *DeviceHostConverter) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { func (d *DeviceHostConverter) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
return nil return nil
} }

View file

@ -417,7 +417,7 @@ type Module struct {
overrideManifest android.OptionalPath overrideManifest android.OptionalPath
// map of SDK version to class loader context // map of SDK version to class loader context
exportedSdkLibs dexpreopt.ClassLoaderContextMap classLoaderContexts dexpreopt.ClassLoaderContextMap
// list of plugins that this java module is exporting // list of plugins that this java module is exporting
exportedPluginJars android.Paths exportedPluginJars android.Paths
@ -509,7 +509,7 @@ type Dependency interface {
ImplementationJars() android.Paths ImplementationJars() android.Paths
ResourceJars() android.Paths ResourceJars() android.Paths
AidlIncludeDirs() android.Paths AidlIncludeDirs() android.Paths
ExportedSdkLibs() dexpreopt.ClassLoaderContextMap ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
ExportedPlugins() (android.Paths, []string) ExportedPlugins() (android.Paths, []string)
SrcJarArgs() ([]string, android.Paths) SrcJarArgs() ([]string, android.Paths)
BaseModuleName() string BaseModuleName() string
@ -1027,7 +1027,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
case libTag: case libTag:
deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
// names of sdk libs that are directly depended are exported // names of sdk libs that are directly depended are exported
j.exportedSdkLibs.MaybeAddContext(ctx, dep.OptionalImplicitSdkLibrary(), j.classLoaderContexts.MaybeAddContext(ctx, dep.OptionalImplicitSdkLibrary(), true,
dep.DexJarBuildPath(), dep.DexJarInstallPath()) dep.DexJarBuildPath(), dep.DexJarInstallPath())
case staticLibTag: case staticLibTag:
ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
@ -1039,7 +1039,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
case libTag, instrumentationForTag: case libTag, instrumentationForTag:
deps.classpath = append(deps.classpath, dep.HeaderJars()...) deps.classpath = append(deps.classpath, dep.HeaderJars()...)
// sdk lib names from dependencies are re-exported // sdk lib names from dependencies are re-exported
j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
pluginJars, pluginClasses := dep.ExportedPlugins() pluginJars, pluginClasses := dep.ExportedPlugins()
addPlugins(&deps, pluginJars, pluginClasses...) addPlugins(&deps, pluginJars, pluginClasses...)
@ -1051,7 +1051,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...) deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
// sdk lib names from dependencies are re-exported // sdk lib names from dependencies are re-exported
j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
pluginJars, pluginClasses := dep.ExportedPlugins() pluginJars, pluginClasses := dep.ExportedPlugins()
addPlugins(&deps, pluginJars, pluginClasses...) addPlugins(&deps, pluginJars, pluginClasses...)
@ -1903,8 +1903,8 @@ func (j *Module) AidlIncludeDirs() android.Paths {
return j.exportAidlIncludeDirs return j.exportAidlIncludeDirs
} }
func (j *Module) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
return j.exportedSdkLibs return j.classLoaderContexts
} }
func (j *Module) ExportedPlugins() (android.Paths, []string) { func (j *Module) ExportedPlugins() (android.Paths, []string) {
@ -2042,7 +2042,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
} }
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
j.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
j.compile(ctx, nil) j.compile(ctx, nil)
// Collect the module directory for IDE info in java/jdeps.go. // Collect the module directory for IDE info in java/jdeps.go.
@ -2062,12 +2062,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// add the name of that java_sdk_library to the exported sdk libs to make sure // add the name of that java_sdk_library to the exported sdk libs to make sure
// that, if necessary, a <uses-library> element for that java_sdk_library is // that, if necessary, a <uses-library> element for that java_sdk_library is
// added to the Android manifest. // added to the Android manifest.
j.exportedSdkLibs.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), j.classLoaderContexts.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), true,
j.DexJarBuildPath(), j.DexJarInstallPath()) j.DexJarBuildPath(), j.DexJarInstallPath())
// A non-SDK library may provide a <uses-library> (the name may be different from the module name). // A non-SDK library may provide a <uses-library> (the name may be different from the module name).
if lib := proptools.String(j.usesLibraryProperties.Provides_uses_lib); lib != "" { if lib := proptools.String(j.usesLibraryProperties.Provides_uses_lib); lib != "" {
j.exportedSdkLibs.AddContext(ctx, lib, j.DexJarBuildPath(), j.DexJarInstallPath()) j.classLoaderContexts.AddContext(ctx, lib, true, j.DexJarBuildPath(), j.DexJarInstallPath())
} }
j.distFiles = j.GenerateTaggedDistFiles(ctx) j.distFiles = j.GenerateTaggedDistFiles(ctx)
@ -2646,7 +2646,7 @@ type Import struct {
dexJarFile android.Path dexJarFile android.Path
combinedClasspathFile android.Path combinedClasspathFile android.Path
exportedSdkLibs dexpreopt.ClassLoaderContextMap classLoaderContexts dexpreopt.ClassLoaderContextMap
exportAidlIncludeDirs android.Paths exportAidlIncludeDirs android.Paths
hideApexVariantFromMake bool hideApexVariantFromMake bool
@ -2721,7 +2721,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
TransformJetifier(ctx, outputFile, inputFile) TransformJetifier(ctx, outputFile, inputFile)
} }
j.combinedClasspathFile = outputFile j.combinedClasspathFile = outputFile
j.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
var flags javaBuilderFlags var flags javaBuilderFlags
@ -2735,7 +2735,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
case libTag, staticLibTag: case libTag, staticLibTag:
flags.classpath = append(flags.classpath, dep.HeaderJars()...) flags.classpath = append(flags.classpath, dep.HeaderJars()...)
// sdk lib names from dependencies are re-exported // sdk lib names from dependencies are re-exported
j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName)
case bootClasspathTag: case bootClasspathTag:
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars()...) flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars()...)
} }
@ -2744,7 +2744,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
case libTag: case libTag:
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
// names of sdk libs that are directly depended are exported // names of sdk libs that are directly depended are exported
j.exportedSdkLibs.AddContext(ctx, otherName, j.classLoaderContexts.AddContext(ctx, otherName, dep.IsSharedLibrary(),
dep.DexJarBuildPath(), dep.DexJarInstallPath()) dep.DexJarBuildPath(), dep.DexJarInstallPath())
} }
} }
@ -2760,7 +2760,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// add the name of that java_sdk_library to the exported sdk libs to make sure // add the name of that java_sdk_library to the exported sdk libs to make sure
// that, if necessary, a <uses-library> element for that java_sdk_library is // that, if necessary, a <uses-library> element for that java_sdk_library is
// added to the Android manifest. // added to the Android manifest.
j.exportedSdkLibs.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), j.classLoaderContexts.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), true,
outputFile, installFile) outputFile, installFile)
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
@ -2843,8 +2843,8 @@ func (j *Import) AidlIncludeDirs() android.Paths {
return j.exportAidlIncludeDirs return j.exportAidlIncludeDirs
} }
func (j *Import) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
return j.exportedSdkLibs return j.classLoaderContexts
} }
func (j *Import) ExportedPlugins() (android.Paths, []string) { func (j *Import) ExportedPlugins() (android.Paths, []string) {

View file

@ -1593,7 +1593,7 @@ func TestJavaSdkLibrary(t *testing.T) {
// test if baz has exported SDK lib names foo and bar to qux // test if baz has exported SDK lib names foo and bar to qux
qux := ctx.ModuleForTests("qux", "android_common") qux := ctx.ModuleForTests("qux", "android_common")
if quxLib, ok := qux.Module().(*Library); ok { if quxLib, ok := qux.Module().(*Library); ok {
sdkLibs := quxLib.ExportedSdkLibs().UsesLibs() sdkLibs := quxLib.ClassLoaderContexts().UsesLibs()
if w := []string{"foo", "bar", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) { if w := []string{"foo", "bar", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) {
t.Errorf("qux should export %q but exports %q", w, sdkLibs) t.Errorf("qux should export %q but exports %q", w, sdkLibs)
} }

View file

@ -673,6 +673,11 @@ func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName()) return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
} }
// If the SDK library is a shared library.
func (c *commonToSdkLibraryAndImport) IsSharedLibrary() bool {
return c.sharedLibrary()
}
// The component names for different outputs of the java_sdk_library. // The component names for different outputs of the java_sdk_library.
// //
// They are similar to the names used for the child modules it creates // They are similar to the names used for the child modules it creates
@ -918,6 +923,9 @@ type SdkLibraryDependency interface {
// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise // jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
// they are identical to the corresponding header jars. // they are identical to the corresponding header jars.
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
// If the SDK library is a shared library.
IsSharedLibrary() bool
} }
type SdkLibrary struct { type SdkLibrary struct {