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

Commit 9ce22217 authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Gerrit Code Review
Browse files

Merge "Collect paths to transitive SDK Java library dependencies."

parents 2d815963 31e444e1
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -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
+12 −7
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import (
	"strings"

	"android/soong/android"
	"android/soong/dexpreopt"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
@@ -99,7 +100,7 @@ type aapt struct {
	useEmbeddedNativeLibs   bool
	useEmbeddedDex          bool
	usesNonSdkApis          bool
	sdkLibraries            []string
	sdkLibraries            dexpreopt.LibraryPaths
	hasNoCode               bool
	LoggingParent           string
	resourceFiles           android.Paths
@@ -231,6 +232,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
	transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries :=
		aaptLibs(ctx, sdkContext)

	a.sdkLibraries = sdkLibraries

	// App manifest file
	manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
	manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
@@ -357,7 +360,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex

// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
	staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries []string) {
	staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries dexpreopt.LibraryPaths) {

	var sharedLibs android.Paths

@@ -366,6 +369,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
		sharedLibs = append(sharedLibs, sdkDep.jars...)
	}

	sdkLibraries = make(dexpreopt.LibraryPaths)

	ctx.VisitDirectDeps(func(module android.Module) {
		var exportPackage android.Path
		aarDep, _ := module.(AndroidLibraryDependency)
@@ -385,7 +390,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
			// (including the java_sdk_library) itself then append any implicit sdk library
			// names to the list of sdk libraries to be added to the manifest.
			if component, ok := module.(SdkLibraryComponentDependency); ok {
				sdkLibraries = append(sdkLibraries, component.OptionalImplicitSdkLibrary()...)
				sdkLibraries.AddLibraryPath(ctx, component.OptionalImplicitSdkLibrary(),
					component.DexJarBuildPath(), component.DexJarInstallPath())
			}

		case frameworkResTag:
@@ -397,7 +403,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
				transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
				transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
				transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
				sdkLibraries = append(sdkLibraries, aarDep.ExportedSdkLibs()...)
				sdkLibraries.AddLibraryPaths(aarDep.ExportedSdkLibs())
				if aarDep.ExportedAssets().Valid() {
					assets = append(assets, aarDep.ExportedAssets().Path())
				}
@@ -428,7 +434,6 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati

	transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
	transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
	sdkLibraries = android.FirstUniqueStrings(sdkLibraries)

	return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries
}
@@ -465,8 +470,8 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {

func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	a.aapt.isLibrary = true
	a.aapt.sdkLibraries = a.exportedSdkLibs
	a.aapt.buildActions(ctx, sdkContext(a))
	a.exportedSdkLibs = a.aapt.sdkLibraries

	ctx.CheckbuildFile(a.proguardOptionsFile)
	ctx.CheckbuildFile(a.exportPackage)
@@ -749,7 +754,7 @@ func (a *AARImport) AidlIncludeDirs() android.Paths {
	return nil
}

func (a *AARImport) ExportedSdkLibs() []string {
func (a *AARImport) ExportedSdkLibs() dexpreopt.LibraryPaths {
	return nil
}

+3 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"github.com/google/blueprint"

	"android/soong/android"
	"android/soong/dexpreopt"
)

var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
@@ -52,7 +53,7 @@ var optionalUsesLibs = []string{
}

// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries []string,
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries dexpreopt.LibraryPaths,
	isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path {

	var args []string
@@ -79,7 +80,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
		args = append(args, "--use-embedded-dex")
	}

	for _, usesLib := range sdkLibraries {
	for usesLib, _ := range sdkLibraries {
		if inList(usesLib, optionalUsesLibs) {
			args = append(args, "--optional-uses-library", usesLib)
		} else {
+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
						entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile)
					}

					entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs...)
					entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs.Names()...)

					if len(library.additionalCheckedModules) != 0 {
						entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
+1 −0
Original line number Diff line number Diff line
@@ -598,6 +598,7 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
	a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
	a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
	a.dexpreopter.manifestFile = a.mergedManifestFile
	a.exportedSdkLibs = make(dexpreopt.LibraryPaths)

	if ctx.ModuleName() != "framework-res" {
		a.Module.compile(ctx, a.aaptSrcJar)
Loading