Use tree representation for class loader context in Make.

Previously Make class loader contexts used a simplified one-level map.
Now they use the same tree representation as in Soong. The difference
between Make and Soong represenataions is insubstantial and caused only
by the language differences between JSON and Go.

Bug: 132357300
Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: Ia273afb7f026dbe3b25d4327d55143657b026b98
This commit is contained in:
Ulya Trafimovich 2020-12-08 17:52:34 +00:00
parent 4de3c42c73
commit 5ec688962c
1 changed files with 29 additions and 21 deletions

View File

@ -488,25 +488,26 @@ func computeClassLoaderContextRec(clcs []*ClassLoaderContext) (string, string, a
return clcHost, clcTarget, paths
}
// JSON representation of <uses-library> paths on host and on device.
type jsonLibraryPath struct {
Host string
Device string
// Class loader contexts that come from Make via JSON dexpreopt.config. JSON CLC representation is
// slightly different: it uses a map of library names to their CLC (instead of a list of structs
// that including the name, as in the Soong CLC representation). The difference is insubstantial, it
// is caused only by the language differerences between Go and JSON.
type jsonClassLoaderContext struct {
Host string
Device string
Subcontexts map[string]*jsonClassLoaderContext
}
// Class loader contexts that come from Make (via JSON dexpreopt.config) files have simpler
// structure than Soong class loader contexts: they are flat maps from a <uses-library> name to its
// on-host and on-device paths. There are no nested subcontexts. It is a limitation of the current
// Make implementation.
type jsonClassLoaderContext map[string]jsonLibraryPath
// A map of <uses-library> name to its on-host and on-device build paths and CLC.
type jsonClassLoaderContexts map[string]*jsonClassLoaderContext
// A map from SDK version (represented with a JSON string) to JSON class loader context.
type jsonClassLoaderContextMap map[string]jsonClassLoaderContext
// A map from SDK version (represented with a JSON string) to JSON CLCs.
type jsonClassLoaderContextMap map[string]map[string]*jsonClassLoaderContext
// Convert JSON class loader context map to ClassLoaderContextMap.
// Convert JSON CLC map to Soong represenation.
func fromJsonClassLoaderContext(ctx android.PathContext, jClcMap jsonClassLoaderContextMap) ClassLoaderContextMap {
clcMap := make(ClassLoaderContextMap)
for sdkVerStr, clc := range jClcMap {
for sdkVerStr, clcs := range jClcMap {
sdkVer, ok := strconv.Atoi(sdkVerStr)
if ok != nil {
if sdkVerStr == "any" {
@ -515,14 +516,21 @@ func fromJsonClassLoaderContext(ctx android.PathContext, jClcMap jsonClassLoader
android.ReportPathErrorf(ctx, "failed to parse SDK version in dexpreopt.config: '%s'", sdkVerStr)
}
}
for lib, path := range clc {
clcMap[sdkVer] = append(clcMap[sdkVer], &ClassLoaderContext{
Name: lib,
Host: constructPath(ctx, path.Host),
Device: path.Device,
Subcontexts: nil,
})
}
clcMap[sdkVer] = fromJsonClassLoaderContextRec(ctx, clcs)
}
return clcMap
}
// Recursive helper for fromJsonClassLoaderContext.
func fromJsonClassLoaderContextRec(ctx android.PathContext, jClcs map[string]*jsonClassLoaderContext) []*ClassLoaderContext {
clcs := make([]*ClassLoaderContext, 0, len(jClcs))
for lib, clc := range jClcs {
clcs = append(clcs, &ClassLoaderContext{
Name: lib,
Host: constructPath(ctx, clc.Host),
Device: clc.Device,
Subcontexts: fromJsonClassLoaderContextRec(ctx, clc.Subcontexts),
})
}
return clcs
}