summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go129
1 files changed, 73 insertions, 56 deletions
diff --git a/java/java.go b/java/java.go
index d44719e99..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
@@ -1786,7 +1782,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.dexJarFile = dexOutputFile
// Dexpreopting
- dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
+ j.dexpreopt(ctx, dexOutputFile)
j.maybeStrippedDexJarFile = dexOutputFile
@@ -2021,10 +2017,12 @@ func (j *Module) hasCode(ctx android.ModuleContext) bool {
return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
}
+// Implements android.ApexModule
func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
return j.depIsInSameApex(ctx, dep)
}
+// Implements android.ApexModule
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
sdkSpec := j.minSdkVersion()
@@ -2070,6 +2068,8 @@ type Library struct {
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
}
+var _ android.ApexModule = (*Library)(nil)
+
// Provides access to the list of permitted packages from updatable boot jars.
type PermittedPackagesForUpdatableBootJars interface {
PermittedPackagesForUpdatableBootJars() []string
@@ -2133,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) {
@@ -2806,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) {
@@ -2821,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) {
@@ -2934,10 +2911,14 @@ func (j *Import) SrcJarArgs() ([]string, android.Paths) {
return nil, nil
}
+var _ android.ApexModule = (*Import)(nil)
+
+// Implements android.ApexModule
func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
return j.depIsInSameApex(ctx, dep)
}
+// Implements android.ApexModule
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
// Do not check for prebuilts against the min_sdk_version of enclosing APEX
@@ -3115,7 +3096,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexJarFile = dexOutputFile
- dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
+ j.dexpreopt(ctx, dexOutputFile)
j.maybeStrippedDexJarFile = dexOutputFile
@@ -3129,6 +3110,9 @@ func (j *DexImport) DexJarBuildPath() android.Path {
return j.dexJarFile
}
+var _ android.ApexModule = (*DexImport)(nil)
+
+// Implements android.ApexModule
func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
// we don't check prebuilt modules for sdk_version
@@ -3248,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)
}
}