Propagate transitive SDK Java library dependencies to dexpreopt.

For some dependencies, like stubs, the SDK library may not be found at
build time (either because the implementation library is not among the
dependencies of the dexpreopted module, or because it's part of a
prebuilt, or because it's missing from the build altogether). In such
cases dexpreopt is useless, because dex2oat does not have access to the
full classpath (unless the &-classpath is used). Therefore do not
dexpreopt in such cases.

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Change-Id: If289088cfd103011ccb16165e95a97b30fd31b81
This commit is contained in:
Ulya Trafimovich
2020-08-19 16:32:54 +01:00
parent 03333d0e2f
commit fc24ad3d4e
6 changed files with 177 additions and 60 deletions

View File

@@ -111,12 +111,9 @@ type LibraryPath struct {
// LibraryPaths is a map from library name to on-host and on-device paths to its DEX jar.
type LibraryPaths map[string]*LibraryPath
// Add a new path to the map of library paths, unless a path for this library already exists.
func (libPaths LibraryPaths) AddLibraryPath(ctx android.PathContext, lib *string, hostPath, installPath android.Path) {
if lib == nil {
return
}
if _, present := libPaths[*lib]; !present {
// Add a new library path to the map, unless a path for this library already exists.
func (libPaths LibraryPaths) addLibraryPath(ctx android.PathContext, lib string, hostPath, installPath android.Path) {
if _, present := libPaths[lib]; !present {
var devicePath string
if installPath != nil {
devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath))
@@ -127,9 +124,30 @@ func (libPaths LibraryPaths) AddLibraryPath(ctx android.PathContext, lib *string
// but we cannot use if for dexpreopt.
devicePath = UnknownInstallLibraryPath
}
libPaths[*lib] = &LibraryPath{hostPath, devicePath}
libPaths[lib] = &LibraryPath{hostPath, devicePath}
}
}
// Add a new library path to the map. Ensure that the build path to the library exists.
func (libPaths LibraryPaths) AddLibraryPath(ctx android.PathContext, lib string, hostPath, installPath android.Path) {
if hostPath != nil {
// Add a library only if the build path to it is known.
libPaths.addLibraryPath(ctx, lib, hostPath, installPath)
} else if !ctx.Config().AllowMissingDependencies() {
// Error on libraries with unknown build paths, unless missing dependencies are allowed.
android.ReportPathErrorf(ctx, "unknown build path to <uses-library> '%s'", lib)
} else {
// Not adding a library to the map will likely result in disabling dexpreopt.
}
}
// Add a new library path to the map, if the library exists (name is not nil).
func (libPaths LibraryPaths) MaybeAddLibraryPath(ctx android.PathContext, lib *string, hostPath, installPath android.Path) {
if lib != nil {
// Don't check the build paths, add in any case. Some libraries may be missing from the
// build, but their names still need to be added to <uses-library> tags in the manifest.
libPaths.addLibraryPath(ctx, *lib, hostPath, installPath)
}
return
}
// Add library paths from the second map to the first map (do not override existing entries).