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

Commit 53c88448 authored by Anton Hansson's avatar Anton Hansson
Browse files

Separate device and product overlays

This change adds book-keeping of whether an overlay came from
DEVICE_PACKAGE_OVERLAYS or PRODUCT_PACKAGE_OVERLAYS. This is
later used when writing the output to soong_app_prebuilt.mk, to
use either LOCAL_SOONG_[DEVICE|PRODUCT]_RRO_PACKAGES depending
on the original source.

This change is intended to be a noop on its own, but allows a
follow-up make change to customize the location of the auto-generated
RRO packages.

Bug: 127758779
Test: verify noop on presubmit targets
Change-Id: Ib24fe1d05be132c360dd6966f7c83968c9939f77
parent 21c81326
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -475,8 +475,12 @@ func (c *config) DeviceName() string {
	return *c.productVariables.DeviceName
}

func (c *config) ResourceOverlays() []string {
	return c.productVariables.ResourceOverlays
func (c *config) DeviceResourceOverlays() []string {
	return c.productVariables.DeviceResourceOverlays
}

func (c *config) ProductResourceOverlays() []string {
	return c.productVariables.ProductResourceOverlays
}

func (c *config) PlatformVersionName() string {
+2 −1
Original line number Diff line number Diff line
@@ -165,7 +165,8 @@ type productVariables struct {
	CrossHostArch          *string `json:",omitempty"`
	CrossHostSecondaryArch *string `json:",omitempty"`

	ResourceOverlays           []string `json:",omitempty"`
	DeviceResourceOverlays     []string `json:",omitempty"`
	ProductResourceOverlays    []string `json:",omitempty"`
	EnforceRROTargets          []string `json:",omitempty"`
	EnforceRROExcludedOverlays []string `json:",omitempty"`

+17 −9
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ type AndroidLibraryDependency interface {
	Dependency
	ExportPackage() android.Path
	ExportedProguardFlagFiles() android.Paths
	ExportedRRODirs() android.Paths
	ExportedRRODirs() []rroDir
	ExportedStaticPackages() android.Paths
	ExportedManifest() android.Path
}
@@ -75,7 +75,7 @@ type aapt struct {
	exportPackage         android.Path
	manifestPath          android.Path
	proguardOptionsFile   android.Path
	rroDirs               android.Paths
	rroDirs               []rroDir
	rTxt                  android.Path
	extraAaptPackagesFile android.Path
	isLibrary             bool
@@ -99,7 +99,7 @@ func (a *aapt) ExportPackage() android.Path {
	return a.exportPackage
}

func (a *aapt) ExportedRRODirs() android.Paths {
func (a *aapt) ExportedRRODirs() []rroDir {
	return a.rroDirs
}

@@ -108,7 +108,7 @@ func (a *aapt) ExportedManifest() android.Path {
}

func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
	deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs, resZips android.Paths) {
	deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {

	hasVersionCode := false
	hasVersionName := false
@@ -286,8 +286,8 @@ 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, staticLibManifests,
	staticRRODirs, deps android.Paths, flags []string) {
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, staticLibManifests android.Paths,
	staticRRODirs []rroDir, deps android.Paths, flags []string) {

	var sharedLibs android.Paths

@@ -315,7 +315,16 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
				transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
				transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
				staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
				staticRRODirs = append(staticRRODirs, aarDep.ExportedRRODirs()...)

			outer:
				for _, d := range aarDep.ExportedRRODirs() {
					for _, e := range staticRRODirs {
						if d.path == e.path {
							continue outer
						}
					}
					staticRRODirs = append(staticRRODirs, d)
				}
			}
		}
	})
@@ -332,7 +341,6 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
	}

	transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
	staticRRODirs = android.FirstUniquePaths(staticRRODirs)

	return transitiveStaticLibs, staticLibManifests, staticRRODirs, deps, flags
}
@@ -482,7 +490,7 @@ func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
	return android.Paths{a.proguardFlags}
}

func (a *AARImport) ExportedRRODirs() android.Paths {
func (a *AARImport) ExportedRRODirs() []rroDir {
	return nil
}

+41 −23
Original line number Diff line number Diff line
@@ -41,9 +41,22 @@ func androidResourceGlob(ctx android.ModuleContext, dir android.Path) android.Pa
	return ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), androidResourceIgnoreFilenames)
}

type overlayType int

const (
	device overlayType = iota + 1
	product
)

type rroDir struct {
	path        android.Path
	overlayType overlayType
}

type overlayGlobResult struct {
	dir         string
	paths       android.DirectorySortedPaths
	overlayType overlayType
}

var overlayDataKey = android.NewOnceKey("overlayDataKey")
@@ -54,7 +67,7 @@ type globbedResourceDir struct {
}

func overlayResourceGlob(ctx android.ModuleContext, dir android.Path) (res []globbedResourceDir,
	rroDirs android.Paths) {
	rroDirs []rroDir) {

	overlayData := ctx.Config().Get(overlayDataKey).([]overlayGlobResult)

@@ -70,7 +83,7 @@ func overlayResourceGlob(ctx android.ModuleContext, dir android.Path) (res []glo
			// exclusion list, ignore the overlay.  The list of ignored overlays will be
			// passed to Make to be turned into an RRO package.
			if rroEnabled && !ctx.Config().EnforceRROExcludedOverlay(overlayModuleDir.String()) {
				rroDirs = append(rroDirs, overlayModuleDir)
				rroDirs = append(rroDirs, rroDir{overlayModuleDir, data.overlayType})
			} else {
				res = append(res, globbedResourceDir{
					dir:   overlayModuleDir,
@@ -91,13 +104,15 @@ type overlaySingleton struct{}

func (overlaySingleton) GenerateBuildActions(ctx android.SingletonContext) {
	var overlayData []overlayGlobResult
	overlayDirs := ctx.Config().ResourceOverlays()

	appendOverlayData := func(overlayDirs []string, t overlayType) {
		for i := range overlayDirs {
			// Iterate backwards through the list of overlay directories so that the later, lower-priority
			// directories in the list show up earlier in the command line to aapt2.
			overlay := overlayDirs[len(overlayDirs)-1-i]
			var result overlayGlobResult
			result.dir = overlay
			result.overlayType = t

			files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), androidResourceIgnoreFilenames)
			if err != nil {
@@ -113,7 +128,10 @@ func (overlaySingleton) GenerateBuildActions(ctx android.SingletonContext) {
			result.paths = android.PathsToDirectorySortedPaths(paths)
			overlayData = append(overlayData, result)
		}
	}

	appendOverlayData(ctx.Config().DeviceResourceOverlays(), device)
	appendOverlayData(ctx.Config().ProductResourceOverlays(), product)
	ctx.Config().Once(overlayDataKey, func() interface{} {
		return overlayData
	})
+16 −2
Original line number Diff line number Diff line
@@ -257,10 +257,24 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
					fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
				}

				if len(app.rroDirs) > 0 {
				filterRRO := func(filter overlayType) android.Paths {
					var paths android.Paths
					for _, d := range app.rroDirs {
						if d.overlayType == filter {
							paths = append(paths, d.path)
						}
					}
					// Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
					// expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
					fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(android.ReversePaths(app.rroDirs).Strings(), " "))
					return android.ReversePaths(paths)
				}
				deviceRRODirs := filterRRO(device)
				if len(deviceRRODirs) > 0 {
					fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
				}
				productRRODirs := filterRRO(product)
				if len(productRRODirs) > 0 {
					fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
				}

				if Bool(app.appProperties.Export_package_resources) {
Loading