Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ef493ff authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Gerrit Code Review
Browse files

Merge "Refactor library path representation in dexpreopt."

parents a5c94e14 d4bcea4e
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -100,6 +100,15 @@ type GlobalSoongConfig struct {
	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 {
	Name            string
	DexLocation     string // dex location on device
@@ -117,7 +126,7 @@ type ModuleConfig struct {
	EnforceUsesLibraries         bool
	PresentOptionalUsesLibraries []string
	UsesLibraries                []string
	LibraryPaths                 map[string]android.Path
	LibraryPaths                 LibraryPaths

	Archs                   []android.ArchType
	DexPreoptImages         []android.Path
@@ -165,14 +174,6 @@ func constructPaths(ctx android.PathContext, paths []string) android.Paths {
	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 {
	if path == "" {
		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
// stage.
func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) {
	type jsonLibraryPath struct {
		Host   string
		Device string
	}

	type jsonLibraryPaths map[string]jsonLibraryPath

	type ModuleJSONConfig struct {
		*ModuleConfig

@@ -273,12 +281,24 @@ func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, err
		DexPath                     string
		ManifestPath                string
		ProfileClassListing         string
		LibraryPaths                map[string]string
		LibraryPaths                jsonLibraryPaths
		DexPreoptImages             []string
		DexPreoptImageLocations     []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{}

	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.ManifestPath = constructPath(ctx, config.ManifestPath)
	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.DexPreoptImageLocations = config.DexPreoptImageLocations
	config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
+4 −3
Original line number Diff line number Diff line
@@ -229,8 +229,9 @@ func (m classLoaderContextMap) getValue(sdkVer int) *classLoaderContext {
func (m classLoaderContextMap) addLibs(sdkVer int, module *ModuleConfig, libs ...string) {
	clc := m.getValue(sdkVer)
	for _, lib := range libs {
		clc.Host = append(clc.Host, pathForLibrary(module, lib))
		clc.Target = append(clc.Target, filepath.Join("/system/framework", lib+".jar"))
		p := pathForLibrary(module, lib)
		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()))
}

func pathForLibrary(module *ModuleConfig, lib string) android.Path {
func pathForLibrary(module *ModuleConfig, lib string) *LibraryPath {
	path, ok := module.LibraryPaths[lib]
	if !ok {
		panic(fmt.Errorf("unknown library path for %q", lib))
+16 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import (

	"android/soong/android"
	"android/soong/cc"
	"android/soong/dexpreopt"
	"android/soong/tradefed"
)

@@ -1871,24 +1872,30 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s
	return optionalUsesLibs
}

// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars.
func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path {
	usesLibPaths := make(map[string]android.Path)
// usesLibraryPaths returns a map of module names of shared library dependencies to the paths
// to their dex jars on host and on device.
func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths {
	usesLibPaths := make(dexpreopt.LibraryPaths)

	if !ctx.Config().UnbundledBuild() {
		ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
			dep := ctx.OtherModuleName(m)
			if lib, ok := m.(Dependency); ok {
				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 {
					ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?",
						ctx.OtherModuleName(m))
					ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+
						" produce a dex jar, does it have installable: true?", dep)
				}
			} else if ctx.Config().AllowMissingDependencies() {
				ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)})
				ctx.AddMissingDependencies([]string{dep})
			} else {
				ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library",
					ctx.OtherModuleName(m))
				ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
					"a java library", dep)
			}
		})
	}
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ type dexpreopter struct {
	usesLibs         []string
	optionalUsesLibs []string
	enforceUsesLibs  bool
	libraryPaths     map[string]android.Path
	libraryPaths     dexpreopt.LibraryPaths

	builtInstalled string
}