Merge "Refactor library path representation in dexpreopt."
This commit is contained in:
commit
3ef493ff91
|
@ -100,6 +100,15 @@ type GlobalSoongConfig struct {
|
||||||
ConstructContext android.Path
|
ConstructContext android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LibraryPath contains paths to the library DEX jar on host and on device.
|
||||||
|
type LibraryPath struct {
|
||||||
|
Host android.Path
|
||||||
|
Device string
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryPaths is a map from library name to on-host and on-device paths to its DEX jar.
|
||||||
|
type LibraryPaths map[string]*LibraryPath
|
||||||
|
|
||||||
type ModuleConfig struct {
|
type ModuleConfig struct {
|
||||||
Name string
|
Name string
|
||||||
DexLocation string // dex location on device
|
DexLocation string // dex location on device
|
||||||
|
@ -117,7 +126,7 @@ type ModuleConfig struct {
|
||||||
EnforceUsesLibraries bool
|
EnforceUsesLibraries bool
|
||||||
PresentOptionalUsesLibraries []string
|
PresentOptionalUsesLibraries []string
|
||||||
UsesLibraries []string
|
UsesLibraries []string
|
||||||
LibraryPaths map[string]android.Path
|
LibraryPaths LibraryPaths
|
||||||
|
|
||||||
Archs []android.ArchType
|
Archs []android.ArchType
|
||||||
DexPreoptImages []android.Path
|
DexPreoptImages []android.Path
|
||||||
|
@ -165,14 +174,6 @@ func constructPaths(ctx android.PathContext, paths []string) android.Paths {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func constructPathMap(ctx android.PathContext, paths map[string]string) map[string]android.Path {
|
|
||||||
ret := map[string]android.Path{}
|
|
||||||
for key, path := range paths {
|
|
||||||
ret[key] = constructPath(ctx, path)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
|
func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -264,6 +265,13 @@ func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) {
|
||||||
// from Make to read the module dexpreopt.config written in the Make config
|
// from Make to read the module dexpreopt.config written in the Make config
|
||||||
// stage.
|
// stage.
|
||||||
func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) {
|
func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) {
|
||||||
|
type jsonLibraryPath struct {
|
||||||
|
Host string
|
||||||
|
Device string
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonLibraryPaths map[string]jsonLibraryPath
|
||||||
|
|
||||||
type ModuleJSONConfig struct {
|
type ModuleJSONConfig struct {
|
||||||
*ModuleConfig
|
*ModuleConfig
|
||||||
|
|
||||||
|
@ -273,12 +281,24 @@ func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, err
|
||||||
DexPath string
|
DexPath string
|
||||||
ManifestPath string
|
ManifestPath string
|
||||||
ProfileClassListing string
|
ProfileClassListing string
|
||||||
LibraryPaths map[string]string
|
LibraryPaths jsonLibraryPaths
|
||||||
DexPreoptImages []string
|
DexPreoptImages []string
|
||||||
DexPreoptImageLocations []string
|
DexPreoptImageLocations []string
|
||||||
PreoptBootClassPathDexFiles []string
|
PreoptBootClassPathDexFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert JSON map of library paths to LibraryPaths
|
||||||
|
constructLibraryPaths := func(ctx android.PathContext, paths jsonLibraryPaths) LibraryPaths {
|
||||||
|
m := LibraryPaths{}
|
||||||
|
for lib, path := range paths {
|
||||||
|
m[lib] = &LibraryPath{
|
||||||
|
constructPath(ctx, path.Host),
|
||||||
|
path.Device,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
config := ModuleJSONConfig{}
|
config := ModuleJSONConfig{}
|
||||||
|
|
||||||
err := json.Unmarshal(data, &config)
|
err := json.Unmarshal(data, &config)
|
||||||
|
@ -291,7 +311,7 @@ func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, err
|
||||||
config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
|
config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
|
||||||
config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath)
|
config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath)
|
||||||
config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
|
config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
|
||||||
config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths)
|
config.ModuleConfig.LibraryPaths = constructLibraryPaths(ctx, config.LibraryPaths)
|
||||||
config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
|
config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
|
||||||
config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations
|
config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations
|
||||||
config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
|
config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
|
||||||
|
|
|
@ -229,8 +229,9 @@ func (m classLoaderContextMap) getValue(sdkVer int) *classLoaderContext {
|
||||||
func (m classLoaderContextMap) addLibs(sdkVer int, module *ModuleConfig, libs ...string) {
|
func (m classLoaderContextMap) addLibs(sdkVer int, module *ModuleConfig, libs ...string) {
|
||||||
clc := m.getValue(sdkVer)
|
clc := m.getValue(sdkVer)
|
||||||
for _, lib := range libs {
|
for _, lib := range libs {
|
||||||
clc.Host = append(clc.Host, pathForLibrary(module, lib))
|
p := pathForLibrary(module, lib)
|
||||||
clc.Target = append(clc.Target, filepath.Join("/system/framework", lib+".jar"))
|
clc.Host = append(clc.Host, p.Host)
|
||||||
|
clc.Target = append(clc.Target, p.Device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,7 +558,7 @@ func PathToLocation(path android.Path, arch android.ArchType) string {
|
||||||
return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String()))
|
return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathForLibrary(module *ModuleConfig, lib string) android.Path {
|
func pathForLibrary(module *ModuleConfig, lib string) *LibraryPath {
|
||||||
path, ok := module.LibraryPaths[lib]
|
path, ok := module.LibraryPaths[lib]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Errorf("unknown library path for %q", lib))
|
panic(fmt.Errorf("unknown library path for %q", lib))
|
||||||
|
|
25
java/app.go
25
java/app.go
|
@ -28,6 +28,7 @@ import (
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
|
"android/soong/dexpreopt"
|
||||||
"android/soong/tradefed"
|
"android/soong/tradefed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1871,24 +1872,30 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s
|
||||||
return optionalUsesLibs
|
return optionalUsesLibs
|
||||||
}
|
}
|
||||||
|
|
||||||
// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars.
|
// usesLibraryPaths returns a map of module names of shared library dependencies to the paths
|
||||||
func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path {
|
// to their dex jars on host and on device.
|
||||||
usesLibPaths := make(map[string]android.Path)
|
func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths {
|
||||||
|
usesLibPaths := make(dexpreopt.LibraryPaths)
|
||||||
|
|
||||||
if !ctx.Config().UnbundledBuild() {
|
if !ctx.Config().UnbundledBuild() {
|
||||||
ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
|
ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
|
||||||
|
dep := ctx.OtherModuleName(m)
|
||||||
if lib, ok := m.(Dependency); ok {
|
if lib, ok := m.(Dependency); ok {
|
||||||
if dexJar := lib.DexJarBuildPath(); dexJar != nil {
|
if dexJar := lib.DexJarBuildPath(); dexJar != nil {
|
||||||
usesLibPaths[ctx.OtherModuleName(m)] = dexJar
|
usesLibPaths[dep] = &dexpreopt.LibraryPath{
|
||||||
|
dexJar,
|
||||||
|
// TODO(b/132357300): propagate actual install paths here.
|
||||||
|
filepath.Join("/system/framework", dep+".jar"),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?",
|
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+
|
||||||
ctx.OtherModuleName(m))
|
" produce a dex jar, does it have installable: true?", dep)
|
||||||
}
|
}
|
||||||
} else if ctx.Config().AllowMissingDependencies() {
|
} else if ctx.Config().AllowMissingDependencies() {
|
||||||
ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)})
|
ctx.AddMissingDependencies([]string{dep})
|
||||||
} else {
|
} else {
|
||||||
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library",
|
ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
|
||||||
ctx.OtherModuleName(m))
|
"a java library", dep)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ type dexpreopter struct {
|
||||||
usesLibs []string
|
usesLibs []string
|
||||||
optionalUsesLibs []string
|
optionalUsesLibs []string
|
||||||
enforceUsesLibs bool
|
enforceUsesLibs bool
|
||||||
libraryPaths map[string]android.Path
|
libraryPaths dexpreopt.LibraryPaths
|
||||||
|
|
||||||
builtInstalled string
|
builtInstalled string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue