diff options
| author | 2020-12-22 10:14:41 +0000 | |
|---|---|---|
| committer | 2020-12-22 10:14:41 +0000 | |
| commit | b630c37d61c5308c1309ff4433c08ef701116170 (patch) | |
| tree | 34dc6fc986cd23ad0172397e9aa6241c8f8575fb /java | |
| parent | d8065c606cf35226d9f766db7f0d383935e09ee8 (diff) | |
| parent | 88bb6f63425e9686b6cb45e0fd3e7b2be52e4d40 (diff) | |
Merge changes I6a512209,I56437f26
* changes:
Unify addition of class loader subcontext from dependencies.
Move ClassLoaderContexts() method to UsesLibraryDependency interface.
Diffstat (limited to 'java')
| -rw-r--r-- | java/aar.go | 13 | ||||
| -rwxr-xr-x | java/app.go | 2 | ||||
| -rw-r--r-- | java/java.go | 114 | ||||
| -rw-r--r-- | java/sdk_library.go | 10 |
4 files changed, 70 insertions, 69 deletions
diff --git a/java/aar.go b/java/aar.go index dfcd95698..e3ad252fd 100644 --- a/java/aar.go +++ b/java/aar.go @@ -416,7 +416,6 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderConte } ctx.VisitDirectDeps(func(module android.Module) { - depName := ctx.OtherModuleName(module) depTag := ctx.OtherModuleDependencyTag(module) var exportPackage android.Path @@ -432,15 +431,6 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderConte if exportPackage != nil { sharedLibs = append(sharedLibs, exportPackage) } - - // If the module is (or possibly could be) a component of a java_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. - if component, ok := module.(SdkLibraryComponentDependency); ok { - classLoaderContexts.MaybeAddContext(ctx, component.OptionalImplicitSdkLibrary(), - component.DexJarBuildPath(), component.DexJarInstallPath()) - } - case frameworkResTag: if exportPackage != nil { sharedLibs = append(sharedLibs, exportPackage) @@ -468,8 +458,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderConte } } - // Merge dep's CLC after processing the dep itself (which may add its own <uses-library>). - maybeAddCLCFromDep(module, depTag, depName, classLoaderContexts) + addCLCFromDep(ctx, module, classLoaderContexts) }) deps = append(deps, sharedLibs...) diff --git a/java/app.go b/java/app.go index bcb610cdb..272d83643 100755 --- a/java/app.go +++ b/java/app.go @@ -1990,7 +1990,7 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext ctx.VisitDirectDeps(func(m android.Module) { if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { dep := ctx.OtherModuleName(m) - if lib, ok := m.(Dependency); ok { + if lib, ok := m.(UsesLibraryDependency); ok { clcMap.AddContextForSdk(ctx, tag.sdkVersion, dep, lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts()) } else if ctx.Config().AllowMissingDependencies() { diff --git a/java/java.go b/java/java.go index 9e47b2f20..719915ef9 100644 --- a/java/java.go +++ b/java/java.go @@ -510,6 +510,7 @@ type ApexDependency interface { type UsesLibraryDependency interface { DexJarBuildPath() android.Path DexJarInstallPath() android.Path + ClassLoaderContexts() dexpreopt.ClassLoaderContextMap } type Dependency interface { @@ -518,7 +519,6 @@ type Dependency interface { ImplementationJars() android.Paths ResourceJars() android.Paths AidlIncludeDirs() android.Paths - ClassLoaderContexts() dexpreopt.ClassLoaderContextMap ExportedPlugins() (android.Paths, []string, bool) SrcJarArgs() ([]string, android.Paths) BaseModuleName() string @@ -1081,8 +1081,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { switch tag { case libTag: deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) - j.classLoaderContexts.MaybeAddContext(ctx, dep.OptionalImplicitSdkLibrary(), - dep.DexJarBuildPath(), dep.DexJarInstallPath()) case staticLibTag: ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) } @@ -1092,7 +1090,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) case libTag, instrumentationForTag: deps.classpath = append(deps.classpath, dep.HeaderJars()...) - j.classLoaderContexts.AddContextMap(dep.ClassLoaderContexts(), otherName) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) pluginJars, pluginClasses, disableTurbine := dep.ExportedPlugins() addPlugins(&deps, pluginJars, pluginClasses...) @@ -1179,8 +1176,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } } - // Merge dep's CLC after processing the dep itself (which may add its own <uses-library>). - maybeAddCLCFromDep(module, tag, otherName, j.classLoaderContexts) + addCLCFromDep(ctx, module, j.classLoaderContexts) }) return deps @@ -2137,18 +2133,6 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), j.Stem()+".jar", j.outputFile, extraInstallDeps...) } - - // If this is a component library (stubs, etc.) for a java_sdk_library then - // 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 - // added to the Android manifest. - j.classLoaderContexts.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), - j.DexJarBuildPath(), j.DexJarInstallPath()) - - // 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 != "" { - j.classLoaderContexts.AddContext(ctx, lib, j.DexJarBuildPath(), j.DexJarInstallPath()) - } } func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { @@ -2810,7 +2794,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { var flags javaBuilderFlags ctx.VisitDirectDeps(func(module android.Module) { - otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) switch dep := module.(type) { @@ -2825,27 +2808,17 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { switch tag { case libTag: flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) - j.classLoaderContexts.AddContext(ctx, otherName, dep.DexJarBuildPath(), dep.DexJarInstallPath()) } } - // Merge dep's CLC after processing the dep itself (which may add its own <uses-library>). - maybeAddCLCFromDep(module, tag, otherName, j.classLoaderContexts) + addCLCFromDep(ctx, module, j.classLoaderContexts) }) - var installFile android.Path if Bool(j.properties.Installable) { - installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), + ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), jarName, outputFile) } - // If this is a component library (impl, stubs, etc.) for a java_sdk_library then - // 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 - // added to the Android manifest. - j.classLoaderContexts.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), - outputFile, installFile) - j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) if ctx.Device() && Bool(j.dexProperties.Compile_dex) { @@ -3259,30 +3232,63 @@ var BoolDefault = proptools.BoolDefault var String = proptools.String var inList = android.InList -// Add class loader context of a given dependency to the given class loader context, provided that -// all the necessary conditions are met. -func maybeAddCLCFromDep(depModule android.Module, depTag blueprint.DependencyTag, - depName string, clcMap dexpreopt.ClassLoaderContextMap) { - - if dep, ok := depModule.(Dependency); ok { - if depTag == libTag { - // Ok, propagate <uses-library> through non-static library dependencies. - } else if depTag == staticLibTag { - // 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, which should not be pulled just because of a static component library. - if comp, isComp := depModule.(SdkLibraryComponentDependency); isComp { - if compName := comp.OptionalImplicitSdkLibrary(); compName != nil { - dep = nil - } - } - } else { - // Don't propagate <uses-library> for other dependency tags. - dep = nil - } +// TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with +// this interface. +type ProvidesUsesLib interface { + ProvidesUsesLib() *string +} - if dep != nil { - clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) +func (j *Module) ProvidesUsesLib() *string { + return j.usesLibraryProperties.Provides_uses_lib +} + +// Add class loader context (CLC) of a given dependency to the current CLC. +func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, + clcMap dexpreopt.ClassLoaderContextMap) { + + dep, ok := depModule.(UsesLibraryDependency) + if !ok { + return + } + + // Find out if the dependency is either an SDK library or an ordinary library that is disguised + // as an SDK library by the means of `provides_uses_lib` property. If yes, the library is itself + // a <uses-library> and should be added as a node in the CLC tree, and its CLC should be added + // as subtree of that node. Otherwise the library is not a <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. + var implicitSdkLib *string + comp, isComp := depModule.(SdkLibraryComponentDependency) + if isComp { + implicitSdkLib = comp.OptionalImplicitSdkLibrary() + // OptionalImplicitSdkLibrary() may be nil so need to fall through to ProvidesUsesLib(). + } + if implicitSdkLib == nil { + if ulib, ok := depModule.(ProvidesUsesLib); ok { + implicitSdkLib = ulib.ProvidesUsesLib() + } + } + + depTag := ctx.OtherModuleDependencyTag(depModule) + if depTag == libTag || depTag == usesLibTag { + // Ok, propagate <uses-library> through non-static library dependencies. + } else if depTag == staticLibTag { + // 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, + // which should not be pulled just because of a static component library. + if implicitSdkLib != nil { + return } + } else { + // Don't propagate <uses-library> for other dependency tags. + return + } + + if implicitSdkLib != nil { + clcMap.AddContextForSdk(ctx, dexpreopt.AnySdkVersion, *implicitSdkLib, + dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts()) + } else { + depName := ctx.OtherModuleName(depModule) + clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) } } diff --git a/java/sdk_library.go b/java/sdk_library.go index 2e10f9c71..92b554bd9 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -28,6 +28,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/dexpreopt" ) const ( @@ -2020,7 +2021,7 @@ func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleCont return module.sdkJars(ctx, sdkVersion, false) } -// to satisfy SdkLibraryDependency interface +// to satisfy UsesLibraryDependency interface func (module *SdkLibraryImport) DexJarBuildPath() android.Path { if module.implLibraryModule == nil { return nil @@ -2029,7 +2030,7 @@ func (module *SdkLibraryImport) DexJarBuildPath() android.Path { } } -// to satisfy SdkLibraryDependency interface +// to satisfy UsesLibraryDependency interface func (module *SdkLibraryImport) DexJarInstallPath() android.Path { if module.implLibraryModule == nil { return nil @@ -2038,6 +2039,11 @@ func (module *SdkLibraryImport) DexJarInstallPath() android.Path { } } +// to satisfy UsesLibraryDependency interface +func (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { + return nil +} + // to satisfy apex.javaDependency interface func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { if module.implLibraryModule == nil { |