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
This commit is contained in:
Colin Cross
2021-01-22 14:06:33 -08:00
committed by Inseob Kim
parent e0edaf9d49
commit a889080aba
7 changed files with 27 additions and 164 deletions

View File

@@ -519,7 +519,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie
entries.SubName += ".cfi" entries.SubName += ".cfi"
} }
entries.SubName += c.androidMkSuffix entries.SubName += c.baseProperties.Androidmk_suffix
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
c.libraryDecorator.androidMkWriteExportedFlags(entries) c.libraryDecorator.androidMkWriteExportedFlags(entries)
@@ -546,7 +546,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie
func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "EXECUTABLES" entries.Class = "EXECUTABLES"
entries.SubName = c.androidMkSuffix entries.SubName = c.baseProperties.Androidmk_suffix
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
entries.AddStrings("LOCAL_MODULE_SYMLINKS", c.Properties.Symlinks...) 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) { func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "STATIC_LIBRARIES" entries.Class = "STATIC_LIBRARIES"
entries.SubName = c.androidMkSuffix entries.SubName = c.baseProperties.Androidmk_suffix
entries.ExtraFooters = append(entries.ExtraFooters, entries.ExtraFooters = append(entries.ExtraFooters,
func(w io.Writer, name, prefix, moduleDir string) { func(w io.Writer, name, prefix, moduleDir string) {

View File

@@ -50,8 +50,6 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
ctx.BottomUp("version", versionMutator).Parallel() ctx.BottomUp("version", versionMutator).Parallel()
ctx.BottomUp("begin", BeginMutator).Parallel() ctx.BottomUp("begin", BeginMutator).Parallel()
ctx.BottomUp("sysprop_cc", SyspropMutator).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) { ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
@@ -1235,7 +1233,7 @@ func (c *Module) nativeCoverage() bool {
} }
func (c *Module) isSnapshotPrebuilt() 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 p.isSnapshotPrebuilt()
} }
return false return false
@@ -2887,8 +2885,6 @@ func baseLibName(depName string) string {
} }
func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, 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()) vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
libName := baseLibName(depName) libName := baseLibName(depName)
@@ -2899,20 +2895,10 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface,
if c, ok := ccDep.(*Module); ok { if c, ok := ccDep.(*Module); ok {
// Use base module name for snapshots when exporting to Makefile. // Use base module name for snapshots when exporting to Makefile.
if c.isSnapshotPrebuilt() { if snapshotPrebuilt, ok := c.linker.(snapshotInterface); ok {
baseName := c.BaseModuleName() baseName := c.BaseModuleName()
if c.IsVndk() { return baseName + snapshotPrebuilt.snapshotAndroidMkSuffix()
return baseName + ".vendor"
}
if c.InVendor() && vendorSuffixModules[baseName] {
return baseName + ".vendor"
} else if c.InRecovery() && recoverySuffixModules[baseName] {
return baseName + ".recovery"
} else {
return baseName
}
} }
} }

View File

@@ -318,9 +318,7 @@ func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
} else if m.isSnapshotPrebuilt() { } else if m.isSnapshotPrebuilt() {
// Make vendor variants only for the versions in BOARD_VNDK_VERSION and // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
// PRODUCT_EXTRA_VNDK_VERSIONS. // PRODUCT_EXTRA_VNDK_VERSIONS.
if snapshot, ok := m.linker.(interface { if snapshot, ok := m.linker.(snapshotInterface); ok {
version() string
}); ok {
if m.InstallInRecovery() { if m.InstallInRecovery() {
recoveryVariantNeeded = true recoveryVariantNeeded = true
} else { } else {

View File

@@ -19,12 +19,10 @@ package cc
import ( import (
"strings" "strings"
"sync"
"android/soong/android" "android/soong/android"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
) )
// Defines the specifics of different images to which the snapshot process is applicable, e.g., // 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. // exclude_from_recovery_snapshot properties.
excludeFromSnapshot(m *Module) bool 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. // Returns true if the build is using a snapshot for this image.
isUsingSnapshot(cfg android.DeviceConfig) bool isUsingSnapshot(cfg android.DeviceConfig) bool
@@ -131,29 +120,6 @@ func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool {
return m.ExcludeFromVendorSnapshot() 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 { func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
vndkVersion := cfg.VndkVersion() vndkVersion := cfg.VndkVersion()
return vndkVersion != "current" && vndkVersion != "" return vndkVersion != "current" && vndkVersion != ""
@@ -219,18 +185,6 @@ func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool {
return m.ExcludeFromRecoverySnapshot() 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 { func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
recoverySnapshotVersion := cfg.RecoverySnapshotVersion() recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
return recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
@@ -269,16 +223,6 @@ const (
snapshotObjectSuffix = "_object." snapshotObjectSuffix = "_object."
) )
var (
vendorSnapshotsLock sync.Mutex
vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules")
)
var (
recoverySnapshotsLock sync.Mutex
recoverySuffixModulesKey = android.NewOnceKey("recoverySuffixModules")
)
type SnapshotProperties struct { type SnapshotProperties struct {
Header_libs []string `android:"arch_variant"` Header_libs []string `android:"arch_variant"`
Static_libs []string `android:"arch_variant"` Static_libs []string `android:"arch_variant"`
@@ -411,27 +355,6 @@ func snapshotFactory(image snapshotImage) android.Module {
return snapshot 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 { type baseSnapshotDecoratorProperties struct {
// snapshot version. // snapshot version.
Version string Version string
@@ -439,6 +362,9 @@ type baseSnapshotDecoratorProperties struct {
// Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
Target_arch string 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, // Suffix to be added to the module name, e.g., vendor_shared,
// recovery_shared, etc. // recovery_shared, etc.
ModuleSuffix string `blueprint:"mutated"` ModuleSuffix string `blueprint:"mutated"`
@@ -489,6 +415,10 @@ func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool {
return true 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 // Call this with a module suffix after creating a snapshot module, such as
// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) { func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) {
@@ -552,7 +482,6 @@ type snapshotLibraryDecorator struct {
// Library flags for cfi variant. // Library flags for cfi variant.
Cfi snapshotLibraryProperties `android:"arch_variant"` Cfi snapshotLibraryProperties `android:"arch_variant"`
} }
androidMkSuffix string
} }
func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { 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 // As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
// done by normal library decorator, e.g. exporting flags. // done by normal library decorator, e.g. exporting flags.
func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { 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() { if p.header() {
return p.libraryDecorator.link(ctx, flags, deps, objs) return p.libraryDecorator.link(ctx, flags, deps, objs)
} }
@@ -774,8 +695,7 @@ type snapshotBinaryProperties struct {
type snapshotBinaryDecorator struct { type snapshotBinaryDecorator struct {
baseSnapshotDecorator baseSnapshotDecorator
*binaryDecorator *binaryDecorator
properties snapshotBinaryProperties properties snapshotBinaryProperties
androidMkSuffix string
} }
func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { 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 p.unstrippedOutputFile = in
binName := in.Base() 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 // use cpExecutable to make it executable
outputFile := android.PathForModuleOut(ctx, binName) outputFile := android.PathForModuleOut(ctx, binName)
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
@@ -876,8 +788,7 @@ type vendorSnapshotObjectProperties struct {
type snapshotObjectLinker struct { type snapshotObjectLinker struct {
baseSnapshotDecorator baseSnapshotDecorator
objectLinker objectLinker
properties vendorSnapshotObjectProperties properties vendorSnapshotObjectProperties
androidMkSuffix string
} }
func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
@@ -897,14 +808,6 @@ func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDep
return nil 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) return android.PathForModuleSrc(ctx, *p.properties.Src)
} }
@@ -950,44 +853,12 @@ func RecoverySnapshotObjectFactory() android.Module {
type snapshotInterface interface { type snapshotInterface interface {
matchesWithDevice(config android.DeviceConfig) bool matchesWithDevice(config android.DeviceConfig) bool
isSnapshotPrebuilt() bool
version() string
snapshotAndroidMkSuffix() string
} }
var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotLibraryDecorator)(nil) var _ snapshotInterface = (*snapshotLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotBinaryDecorator)(nil) var _ snapshotInterface = (*snapshotBinaryDecorator)(nil)
var _ snapshotInterface = (*snapshotObjectLinker)(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
}
}

View File

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

View File

@@ -447,6 +447,7 @@ func TestVendorSnapshotUse(t *testing.T) {
vendor_snapshot_shared { vendor_snapshot_shared {
name: "libvendor_available", name: "libvendor_available",
androidmk_suffix: ".vendor",
version: "BOARD", version: "BOARD",
target_arch: "arm64", target_arch: "arm64",
vendor: true, vendor: true,
@@ -460,6 +461,7 @@ func TestVendorSnapshotUse(t *testing.T) {
vendor_snapshot_static { vendor_snapshot_static {
name: "libvendor_available", name: "libvendor_available",
androidmk_suffix: ".vendor",
version: "BOARD", version: "BOARD",
target_arch: "arm64", target_arch: "arm64",
vendor: true, vendor: true,

View File

@@ -107,6 +107,10 @@ func (p *vndkPrebuiltLibraryDecorator) binderBit() string {
return "64" return "64"
} }
func (p *vndkPrebuiltLibraryDecorator) snapshotAndroidMkSuffix() string {
return ".vendor"
}
func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
return p.libraryDecorator.linkerFlags(ctx, flags) return p.libraryDecorator.linkerFlags(ctx, flags)