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

Commit a889080a authored by Colin Cross's avatar Colin Cross Committed by Inseob Kim
Browse files

Remove global state on module suffixes from vendor and recovery snapshots

Propgate the Android.mk suffix from source modules into the snapshot so
that it can be used for the prebuilt modules.

Bug: 177098205
Test: vendor_snapshot_test.go
Change-Id: Iea151dc91395f714fbcad1df3a6fd0874e5455d9
parent e0edaf9d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -519,7 +519,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie
		entries.SubName += ".cfi"
	}

	entries.SubName += c.androidMkSuffix
	entries.SubName += c.baseProperties.Androidmk_suffix

	entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
		c.libraryDecorator.androidMkWriteExportedFlags(entries)
@@ -546,7 +546,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie

func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
	entries.Class = "EXECUTABLES"
	entries.SubName = c.androidMkSuffix
	entries.SubName = c.baseProperties.Androidmk_suffix

	entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
		entries.AddStrings("LOCAL_MODULE_SYMLINKS", c.Properties.Symlinks...)
@@ -555,7 +555,7 @@ func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries

func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
	entries.Class = "STATIC_LIBRARIES"
	entries.SubName = c.androidMkSuffix
	entries.SubName = c.baseProperties.Androidmk_suffix

	entries.ExtraFooters = append(entries.ExtraFooters,
		func(w io.Writer, name, prefix, moduleDir string) {
+3 −17
Original line number Diff line number Diff line
@@ -50,8 +50,6 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
		ctx.BottomUp("version", versionMutator).Parallel()
		ctx.BottomUp("begin", BeginMutator).Parallel()
		ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
		ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
		ctx.BottomUp("recovery_snapshot_source", RecoverySnapshotSourceMutator).Parallel()
	})

	ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
@@ -1235,7 +1233,7 @@ func (c *Module) nativeCoverage() bool {
}

func (c *Module) isSnapshotPrebuilt() bool {
	if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
	if p, ok := c.linker.(snapshotInterface); ok {
		return p.isSnapshotPrebuilt()
	}
	return false
@@ -2887,8 +2885,6 @@ func baseLibName(depName string) string {
}

func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
	vendorSuffixModules := vendorSuffixModules(ctx.Config())
	recoverySuffixModules := recoverySuffixModules(ctx.Config())
	vendorPublicLibraries := vendorPublicLibraries(ctx.Config())

	libName := baseLibName(depName)
@@ -2899,20 +2895,10 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface,

	if c, ok := ccDep.(*Module); ok {
		// Use base module name for snapshots when exporting to Makefile.
		if c.isSnapshotPrebuilt() {
		if snapshotPrebuilt, ok := c.linker.(snapshotInterface); ok {
			baseName := c.BaseModuleName()

			if c.IsVndk() {
				return baseName + ".vendor"
			}

			if c.InVendor() && vendorSuffixModules[baseName] {
				return baseName + ".vendor"
			} else if c.InRecovery() && recoverySuffixModules[baseName] {
				return baseName + ".recovery"
			} else {
				return baseName
			}
			return baseName + snapshotPrebuilt.snapshotAndroidMkSuffix()
		}
	}

+1 −3
Original line number Diff line number Diff line
@@ -318,9 +318,7 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
	} else if m.isSnapshotPrebuilt() {
		// Make vendor variants only for the versions in BOARD_VNDK_VERSION and
		// PRODUCT_EXTRA_VNDK_VERSIONS.
		if snapshot, ok := m.linker.(interface {
			version() string
		}); ok {
		if snapshot, ok := m.linker.(snapshotInterface); ok {
			if m.InstallInRecovery() {
				recoveryVariantNeeded = true
			} else {
+12 −141
Original line number Diff line number Diff line
@@ -19,12 +19,10 @@ package cc

import (
	"strings"
	"sync"

	"android/soong/android"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

// Defines the specifics of different images to which the snapshot process is applicable, e.g.,
@@ -59,15 +57,6 @@ type snapshotImage interface {
	// exclude_from_recovery_snapshot properties.
	excludeFromSnapshot(m *Module) bool

	// Returns mutex used for mutual exclusion when updating the snapshot maps.
	getMutex() *sync.Mutex

	// For a given arch, a maps of which modules are included in this image.
	suffixModules(config android.Config) map[string]bool

	// Whether to add a given module to the suffix map.
	shouldBeAddedToSuffixModules(m *Module) bool

	// Returns true if the build is using a snapshot for this image.
	isUsingSnapshot(cfg android.DeviceConfig) bool

@@ -131,29 +120,6 @@ func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool {
	return m.ExcludeFromVendorSnapshot()
}

func (vendorSnapshotImage) getMutex() *sync.Mutex {
	return &vendorSnapshotsLock
}

func (vendorSnapshotImage) suffixModules(config android.Config) map[string]bool {
	return vendorSuffixModules(config)
}

func (vendorSnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool {
	// vendor suffix should be added to snapshots if the source module isn't vendor: true.
	if module.SocSpecific() {
		return false
	}

	// But we can't just check SocSpecific() since we already passed the image mutator.
	// Check ramdisk and recovery to see if we are real "vendor: true" module.
	ramdiskAvailable := module.InRamdisk() && !module.OnlyInRamdisk()
	vendorRamdiskAvailable := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk()
	recoveryAvailable := module.InRecovery() && !module.OnlyInRecovery()

	return !ramdiskAvailable && !recoveryAvailable && !vendorRamdiskAvailable
}

func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
	vndkVersion := cfg.VndkVersion()
	return vndkVersion != "current" && vndkVersion != ""
@@ -219,18 +185,6 @@ func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool {
	return m.ExcludeFromRecoverySnapshot()
}

func (recoverySnapshotImage) getMutex() *sync.Mutex {
	return &recoverySnapshotsLock
}

func (recoverySnapshotImage) suffixModules(config android.Config) map[string]bool {
	return recoverySuffixModules(config)
}

func (recoverySnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool {
	return proptools.BoolDefault(module.Properties.Recovery_available, false)
}

func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
	recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
	return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
@@ -269,16 +223,6 @@ const (
	snapshotObjectSuffix = "_object."
)

var (
	vendorSnapshotsLock    sync.Mutex
	vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules")
)

var (
	recoverySnapshotsLock    sync.Mutex
	recoverySuffixModulesKey = android.NewOnceKey("recoverySuffixModules")
)

type SnapshotProperties struct {
	Header_libs []string `android:"arch_variant"`
	Static_libs []string `android:"arch_variant"`
@@ -411,27 +355,6 @@ func snapshotFactory(image snapshotImage) android.Module {
	return snapshot
}

// vendorSuffixModules holds names of modules whose vendor variants should have the vendor suffix.
// This is determined by source modules, and then this will be used when exporting snapshot modules
// to Makefile.
//
// For example, if libbase has "vendor_available: true", the name of core variant will be "libbase"
// while the name of vendor variant will be "libbase.vendor". In such cases, the vendor snapshot of
// "libbase" should be exported with the name "libbase.vendor".
//
// Refer to VendorSnapshotSourceMutator and makeLibName which use this.
func vendorSuffixModules(config android.Config) map[string]bool {
	return config.Once(vendorSuffixModulesKey, func() interface{} {
		return make(map[string]bool)
	}).(map[string]bool)
}

func recoverySuffixModules(config android.Config) map[string]bool {
	return config.Once(recoverySuffixModulesKey, func() interface{} {
		return make(map[string]bool)
	}).(map[string]bool)
}

type baseSnapshotDecoratorProperties struct {
	// snapshot version.
	Version string
@@ -439,6 +362,9 @@ type baseSnapshotDecoratorProperties struct {
	// Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
	Target_arch string

	// Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
	Androidmk_suffix string

	// Suffix to be added to the module name, e.g., vendor_shared,
	// recovery_shared, etc.
	ModuleSuffix string `blueprint:"mutated"`
@@ -489,6 +415,10 @@ func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool {
	return true
}

func (p *baseSnapshotDecorator) snapshotAndroidMkSuffix() string {
	return p.baseProperties.Androidmk_suffix
}

// Call this with a module suffix after creating a snapshot module, such as
// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) {
@@ -552,7 +482,6 @@ type snapshotLibraryDecorator struct {
		// Library flags for cfi variant.
		Cfi snapshotLibraryProperties `android:"arch_variant"`
	}
	androidMkSuffix string
}

func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
@@ -575,14 +504,6 @@ func (p *snapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig
// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
// done by normal library decorator, e.g. exporting flags.
func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
	m := ctx.Module().(*Module)

	if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = vendorSuffix
	} else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = recoverySuffix
	}

	if p.header() {
		return p.libraryDecorator.link(ctx, flags, deps, objs)
	}
@@ -775,7 +696,6 @@ type snapshotBinaryDecorator struct {
	baseSnapshotDecorator
	*binaryDecorator
	properties snapshotBinaryProperties
	androidMkSuffix string
}

func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
@@ -799,14 +719,6 @@ func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps Path
	p.unstrippedOutputFile = in
	binName := in.Base()

	m := ctx.Module().(*Module)
	if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = vendorSuffix
	} else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = recoverySuffix

	}

	// use cpExecutable to make it executable
	outputFile := android.PathForModuleOut(ctx, binName)
	ctx.Build(pctx, android.BuildParams{
@@ -877,7 +789,6 @@ type snapshotObjectLinker struct {
	baseSnapshotDecorator
	objectLinker
	properties vendorSnapshotObjectProperties
	androidMkSuffix string
}

func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
@@ -897,14 +808,6 @@ func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDep
		return nil
	}

	m := ctx.Module().(*Module)

	if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = vendorSuffix
	} else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
		p.androidMkSuffix = recoverySuffix
	}

	return android.PathForModuleSrc(ctx, *p.properties.Src)
}

@@ -950,44 +853,12 @@ func RecoverySnapshotObjectFactory() android.Module {

type snapshotInterface interface {
	matchesWithDevice(config android.DeviceConfig) bool
	isSnapshotPrebuilt() bool
	version() string
	snapshotAndroidMkSuffix() string
}

var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotBinaryDecorator)(nil)
var _ snapshotInterface = (*snapshotObjectLinker)(nil)

//
// Mutators that helps vendor snapshot modules override source modules.
//

// VendorSnapshotSourceMutator disables source modules which have corresponding snapshots.
func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
	snapshotSourceMutator(ctx, vendorSnapshotImageSingleton)
}

func RecoverySnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
	snapshotSourceMutator(ctx, recoverySnapshotImageSingleton)
}

func snapshotSourceMutator(ctx android.BottomUpMutatorContext, image snapshotImage) {
	if !ctx.Device() {
		return
	}
	if !image.isUsingSnapshot(ctx.DeviceConfig()) {
		return
	}

	module, ok := ctx.Module().(*Module)
	if !ok {
		return
	}

	if image.shouldBeAddedToSuffixModules(module) {
		mutex := image.getMutex()
		mutex.Lock()
		defer mutex.Unlock()

		image.suffixModules(ctx.Config())[ctx.ModuleName()] = true
	}
}
+2 −0
Original line number Diff line number Diff line
@@ -291,6 +291,7 @@ func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool
type snapshotJsonFlags struct {
	ModuleName          string `json:",omitempty"`
	RelativeInstallPath string `json:",omitempty"`
	AndroidMkSuffix     string `json:",omitempty"`

	// library flags
	ExportedDirs       []string `json:",omitempty"`
@@ -403,6 +404,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
		} else {
			prop.RelativeInstallPath = m.RelativeInstallPath()
		}
		prop.AndroidMkSuffix = m.Properties.SubName
		prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
		prop.Required = m.RequiredModuleNames()
		for _, path := range m.InitRc() {
Loading