Collect paths to transitive SDK Java library dependencies.

Previously only the names were collected, and later used in the
manifest_fixer to add missing <uses-library> entries to the manifest.
Now we also need to collect build-time and on-device paths, to be used
in class loader context for dexpreopt. This commit only collects paths,
but does not pass them to dexpreopt yet.

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Change-Id: I34b229ee68f16ba215ba03770feadb4d890ec2bf
This commit is contained in:
Ulya Trafimovich
2020-08-14 17:32:16 +01:00
parent 52cefc00f7
commit 31e444e101
9 changed files with 117 additions and 55 deletions

View File

@@ -17,6 +17,7 @@ package dexpreopt
import (
"encoding/json"
"fmt"
"sort"
"strings"
"github.com/google/blueprint"
@@ -100,6 +101,8 @@ type GlobalSoongConfig struct {
ConstructContext android.Path
}
const UnknownInstallLibraryPath = "error"
// LibraryPath contains paths to the library DEX jar on host and on device.
type LibraryPath struct {
Host android.Path
@@ -109,6 +112,46 @@ 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 {
var devicePath string
if installPath != nil {
devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath))
} else {
// For some stub libraries the only known thing is the name of their implementation
// library, but the library itself is unavailable (missing or part of a prebuilt). In
// such cases we still need to add the library to <uses-library> tags in the manifest,
// but we cannot use if for dexpreopt.
devicePath = UnknownInstallLibraryPath
}
libPaths[*lib] = &LibraryPath{hostPath, devicePath}
}
return
}
// Add library paths from the second map to the first map (do not override existing entries).
func (libPaths LibraryPaths) AddLibraryPaths(otherPaths LibraryPaths) {
for lib, path := range otherPaths {
if _, present := libPaths[lib]; !present {
libPaths[lib] = path
}
}
}
// Return sorted names of the libraries in the map.
func (libPaths LibraryPaths) Names() []string {
keys := make([]string, 0, len(libPaths))
for k := range libPaths {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
type ModuleConfig struct {
Name string
DexLocation string // dex location on device