Merge "Remove global state from apex modules" am: 43159bd1b7 am: 21bb1d491c am: 2c76247f51

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1428815

Change-Id: I931b01c9ec6905698fef4fbbbdee47224291186e
This commit is contained in:
Colin Cross 2020-10-07 19:51:03 +00:00 committed by Automerger Merge Worker
commit 393b394b85
23 changed files with 528 additions and 337 deletions

View File

@ -28,20 +28,29 @@ var (
SdkVersion_Android10 = uncheckedFinalApiLevel(29) SdkVersion_Android10 = uncheckedFinalApiLevel(29)
) )
// ApexInfo describes the metadata common to all modules in an apexBundle.
type ApexInfo struct { type ApexInfo struct {
// Name of the apex variation that this module is mutated into // Name of the apex variation that this module is mutated into, or "" for
// a platform variant. Note that a module can be included in multiple APEXes,
// in which case, the module is mutated into one or more variants, each of
// which is for one or more APEXes.
ApexVariationName string ApexVariationName string
// Serialized ApiLevel. Use via MinSdkVersion() method. Cannot be stored in // Serialized ApiLevel. Use via MinSdkVersion() method. Cannot be stored in
// its struct form because this is cloned into properties structs, and // its struct form because this is cloned into properties structs, and
// ApiLevel has private members. // ApiLevel has private members.
MinSdkVersionStr string MinSdkVersionStr string
// True if the module comes from an updatable APEX.
Updatable bool Updatable bool
RequiredSdks SdkRefs RequiredSdks SdkRefs
InApexes []string InApexes []string
ApexContents []*ApexContents
} }
var ApexInfoProvider = blueprint.NewMutatorProvider(ApexInfo{}, "apex")
func (i ApexInfo) mergedName(ctx PathContext) string { func (i ApexInfo) mergedName(ctx PathContext) string {
name := "apex" + strconv.Itoa(i.MinSdkVersion(ctx).FinalOrFutureInt()) name := "apex" + strconv.Itoa(i.MinSdkVersion(ctx).FinalOrFutureInt())
for _, sdk := range i.RequiredSdks { for _, sdk := range i.RequiredSdks {
@ -54,6 +63,18 @@ func (this *ApexInfo) MinSdkVersion(ctx PathContext) ApiLevel {
return ApiLevelOrPanic(ctx, this.MinSdkVersionStr) return ApiLevelOrPanic(ctx, this.MinSdkVersionStr)
} }
func (i ApexInfo) IsForPlatform() bool {
return i.ApexVariationName == ""
}
// ApexTestForInfo stores the contents of APEXes for which this module is a test and thus has
// access to APEX internals.
type ApexTestForInfo struct {
ApexContents []*ApexContents
}
var ApexTestForInfoProvider = blueprint.NewMutatorProvider(ApexTestForInfo{}, "apex_test_for")
// Extracted from ApexModule to make it easier to define custom subsets of the // Extracted from ApexModule to make it easier to define custom subsets of the
// ApexModule interface and improve code navigation within the IDE. // ApexModule interface and improve code navigation within the IDE.
type DepIsInSameApex interface { type DepIsInSameApex interface {
@ -87,23 +108,18 @@ type ApexModule interface {
// Call this before apex.apexMutator is run. // Call this before apex.apexMutator is run.
BuildForApex(apex ApexInfo) BuildForApex(apex ApexInfo)
// Returns the name of APEX variation that this module will be built for. // Returns true if this module is present in any APEXes
// Empty string is returned when 'IsForPlatform() == true'. Note that a // directly or indirectly.
// module can beincluded in multiple APEXes, in which case, the module
// is mutated into one or more variants, each of which is for one or
// more APEXes. This method returns the name of the APEX variation of
// the module.
// Call this after apex.apexMutator is run. // Call this after apex.apexMutator is run.
ApexVariationName() string InAnyApex() bool
// Returns the name of the APEX modules that this variant of this module // Returns true if this module is directly in any APEXes.
// is present in.
// Call this after apex.apexMutator is run. // Call this after apex.apexMutator is run.
InApexes() []string DirectlyInAnyApex() bool
// Tests whether this module will be built for the platform or not. // Returns true if any variant of this module is directly in any APEXes.
// This is a shortcut for ApexVariationName() == "" // Call this after apex.apexMutator is run.
IsForPlatform() bool AnyVariantDirectlyInAnyApex() bool
// Tests if this module could have APEX variants. APEX variants are // Tests if this module could have APEX variants. APEX variants are
// created only for the modules that returns true here. This is useful // created only for the modules that returns true here. This is useful
@ -116,10 +132,6 @@ type ApexModule interface {
// libs. // libs.
IsInstallableToApex() bool IsInstallableToApex() bool
// Mutate this module into one or more variants each of which is built
// for an APEX marked via BuildForApex().
CreateApexVariations(mctx BottomUpMutatorContext) []Module
// Tests if this module is available for the specified APEX or ":platform" // Tests if this module is available for the specified APEX or ":platform"
AvailableFor(what string) bool AvailableFor(what string) bool
@ -138,9 +150,6 @@ type ApexModule interface {
// it returns 9 as string // it returns 9 as string
ChooseSdkVersion(ctx BaseModuleContext, versionList []string, maxSdkVersion ApiLevel) (string, error) ChooseSdkVersion(ctx BaseModuleContext, versionList []string, maxSdkVersion ApiLevel) (string, error)
// Tests if the module comes from an updatable APEX.
Updatable() bool
// List of APEXes that this module tests. The module has access to // List of APEXes that this module tests. The module has access to
// the private part of the listed APEXes even when it is not included in the // the private part of the listed APEXes even when it is not included in the
// APEXes. // APEXes.
@ -153,11 +162,6 @@ type ApexModule interface {
// Returns true if this module needs a unique variation per apex, for example if // Returns true if this module needs a unique variation per apex, for example if
// use_apex_name_macro is set. // use_apex_name_macro is set.
UniqueApexVariations() bool UniqueApexVariations() bool
// UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies
// that are in the same APEX have unique APEX variations so that the module can link against
// the right variant.
UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext)
} }
type ApexProperties struct { type ApexProperties struct {
@ -171,7 +175,21 @@ type ApexProperties struct {
// Default is ["//apex_available:platform"]. // Default is ["//apex_available:platform"].
Apex_available []string Apex_available []string
Info ApexInfo `blueprint:"mutated"` // AnyVariantDirectlyInAnyApex is true in the primary variant of a module if _any_ variant
// of the module is directly in any apex. This includes host, arch, asan, etc. variants.
// It is unused in any variant that is not the primary variant.
// Ideally this wouldn't be used, as it incorrectly mixes arch variants if only one arch
// is in an apex, but a few places depend on it, for example when an ASAN variant is
// created before the apexMutator.
AnyVariantDirectlyInAnyApex bool `blueprint:"mutated"`
// DirectlyInAnyApex is true if any APEX variant (including the "" variant used for the
// platform) of this module is directly in any APEX.
DirectlyInAnyApex bool `blueprint:"mutated"`
// DirectlyInAnyApex is true if any APEX variant (including the "" variant used for the
// platform) of this module is directly or indirectly in any APEX.
InAnyApex bool `blueprint:"mutated"`
NotAvailableForPlatform bool `blueprint:"mutated"` NotAvailableForPlatform bool `blueprint:"mutated"`
@ -187,6 +205,15 @@ type ExcludeFromApexContentsTag interface {
ExcludeFromApexContents() ExcludeFromApexContents()
} }
// Marker interface that identifies dependencies that should inherit the DirectlyInAnyApex
// state from the parent to the child. For example, stubs libraries are marked as
// DirectlyInAnyApex if their implementation is in an apex.
type CopyDirectlyInAnyApexTag interface {
blueprint.DependencyTag
CopyDirectlyInAnyApex()
}
// Provides default implementation for the ApexModule interface. APEX-aware // Provides default implementation for the ApexModule interface. APEX-aware
// modules are expected to include this struct and call InitApexModule(). // modules are expected to include this struct and call InitApexModule().
type ApexModuleBase struct { type ApexModuleBase struct {
@ -215,43 +242,6 @@ func (m *ApexModuleBase) UniqueApexVariations() bool {
return false return false
} }
func (m *ApexModuleBase) UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext) {
// anyInSameApex returns true if the two ApexInfo lists contain any values in an InApexes list
// in common. It is used instead of DepIsInSameApex because it needs to determine if the dep
// is in the same APEX due to being directly included, not only if it is included _because_ it
// is a dependency.
anyInSameApex := func(a, b []ApexInfo) bool {
collectApexes := func(infos []ApexInfo) []string {
var ret []string
for _, info := range infos {
ret = append(ret, info.InApexes...)
}
return ret
}
aApexes := collectApexes(a)
bApexes := collectApexes(b)
sort.Strings(bApexes)
for _, aApex := range aApexes {
index := sort.SearchStrings(bApexes, aApex)
if index < len(bApexes) && bApexes[index] == aApex {
return true
}
}
return false
}
mctx.VisitDirectDeps(func(dep Module) {
if depApexModule, ok := dep.(ApexModule); ok {
if anyInSameApex(depApexModule.apexModuleBase().apexVariations, m.apexVariations) &&
(depApexModule.UniqueApexVariations() ||
depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
m.ApexProperties.UniqueApexVariationsForDeps = true
}
}
})
}
func (m *ApexModuleBase) BuildForApex(apex ApexInfo) { func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
m.apexVariationsLock.Lock() m.apexVariationsLock.Lock()
defer m.apexVariationsLock.Unlock() defer m.apexVariationsLock.Unlock()
@ -263,16 +253,16 @@ func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
m.apexVariations = append(m.apexVariations, apex) m.apexVariations = append(m.apexVariations, apex)
} }
func (m *ApexModuleBase) ApexVariationName() string { func (m *ApexModuleBase) DirectlyInAnyApex() bool {
return m.ApexProperties.Info.ApexVariationName return m.ApexProperties.DirectlyInAnyApex
} }
func (m *ApexModuleBase) InApexes() []string { func (m *ApexModuleBase) AnyVariantDirectlyInAnyApex() bool {
return m.ApexProperties.Info.InApexes return m.ApexProperties.AnyVariantDirectlyInAnyApex
} }
func (m *ApexModuleBase) IsForPlatform() bool { func (m *ApexModuleBase) InAnyApex() bool {
return m.ApexProperties.Info.ApexVariationName == "" return m.ApexProperties.InAnyApex
} }
func (m *ApexModuleBase) CanHaveApexVariants() bool { func (m *ApexModuleBase) CanHaveApexVariants() bool {
@ -345,10 +335,6 @@ func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
} }
} }
func (m *ApexModuleBase) Updatable() bool {
return m.ApexProperties.Info.Updatable
}
type byApexName []ApexInfo type byApexName []ApexInfo
func (a byApexName) Len() int { return len(a) } func (a byApexName) Len() int { return len(a) }
@ -366,11 +352,13 @@ func mergeApexVariations(ctx PathContext, apexVariations []ApexInfo) (merged []A
mergedName := apexInfo.mergedName(ctx) mergedName := apexInfo.mergedName(ctx)
if index, exists := seen[mergedName]; exists { if index, exists := seen[mergedName]; exists {
merged[index].InApexes = append(merged[index].InApexes, apexName) merged[index].InApexes = append(merged[index].InApexes, apexName)
merged[index].ApexContents = append(merged[index].ApexContents, apexInfo.ApexContents...)
merged[index].Updatable = merged[index].Updatable || apexInfo.Updatable merged[index].Updatable = merged[index].Updatable || apexInfo.Updatable
} else { } else {
seen[mergedName] = len(merged) seen[mergedName] = len(merged)
apexInfo.ApexVariationName = apexInfo.mergedName(ctx) apexInfo.ApexVariationName = apexInfo.mergedName(ctx)
apexInfo.InApexes = CopyOf(apexInfo.InApexes) apexInfo.InApexes = CopyOf(apexInfo.InApexes)
apexInfo.ApexContents = append([]*ApexContents(nil), apexInfo.ApexContents...)
merged = append(merged, apexInfo) merged = append(merged, apexInfo)
} }
aliases = append(aliases, [2]string{apexName, mergedName}) aliases = append(aliases, [2]string{apexName, mergedName})
@ -378,17 +366,23 @@ func mergeApexVariations(ctx PathContext, apexVariations []ApexInfo) (merged []A
return merged, aliases return merged, aliases
} }
func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module { func CreateApexVariations(mctx BottomUpMutatorContext, module ApexModule) []Module {
if len(m.apexVariations) > 0 { base := module.apexModuleBase()
m.checkApexAvailableProperty(mctx) if len(base.apexVariations) > 0 {
base.checkApexAvailableProperty(mctx)
var apexVariations []ApexInfo var apexVariations []ApexInfo
var aliases [][2]string var aliases [][2]string
if !mctx.Module().(ApexModule).UniqueApexVariations() && !m.ApexProperties.UniqueApexVariationsForDeps { if !mctx.Module().(ApexModule).UniqueApexVariations() && !base.ApexProperties.UniqueApexVariationsForDeps {
apexVariations, aliases = mergeApexVariations(mctx, m.apexVariations) apexVariations, aliases = mergeApexVariations(mctx, base.apexVariations)
} else { } else {
apexVariations = m.apexVariations apexVariations = base.apexVariations
} }
// base.apexVariations is only needed to propagate the list of apexes from
// apexDepsMutator to apexMutator. It is no longer accurate after
// mergeApexVariations, and won't be copied to all but the first created
// variant. Clear it so it doesn't accidentally get used later.
base.apexVariations = nil
sort.Sort(byApexName(apexVariations)) sort.Sort(byApexName(apexVariations))
variations := []string{} variations := []string{}
@ -400,6 +394,16 @@ func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Mod
defaultVariation := "" defaultVariation := ""
mctx.SetDefaultDependencyVariation(&defaultVariation) mctx.SetDefaultDependencyVariation(&defaultVariation)
var inApex ApexMembership
for _, a := range apexVariations {
for _, apexContents := range a.ApexContents {
inApex = inApex.merge(apexContents.contents[mctx.ModuleName()])
}
}
base.ApexProperties.InAnyApex = true
base.ApexProperties.DirectlyInAnyApex = inApex == directlyInApex
modules := mctx.CreateVariations(variations...) modules := mctx.CreateVariations(variations...)
for i, mod := range modules { for i, mod := range modules {
platformVariation := i == 0 platformVariation := i == 0
@ -410,7 +414,7 @@ func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Mod
mod.MakeUninstallable() mod.MakeUninstallable()
} }
if !platformVariation { if !platformVariation {
mod.(ApexModule).apexModuleBase().ApexProperties.Info = apexVariations[i-1] mctx.SetVariationProvider(mod, ApexInfoProvider, apexVariations[i-1])
} }
} }
@ -423,116 +427,139 @@ func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Mod
return nil return nil
} }
var apexData OncePer // UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies
var apexNamesMapMutex sync.Mutex // that are in the same APEX have unique APEX variations so that the module can link against
var apexNamesKey = NewOnceKey("apexNames") // the right variant.
func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) {
// This structure maintains the global mapping in between modules and APEXes. // anyInSameApex returns true if the two ApexInfo lists contain any values in an InApexes list
// Examples: // in common. It is used instead of DepIsInSameApex because it needs to determine if the dep
// // is in the same APEX due to being directly included, not only if it is included _because_ it
// apexNamesMap()["foo"]["bar"] == true: module foo is directly depended on by APEX bar // is a dependency.
// apexNamesMap()["foo"]["bar"] == false: module foo is indirectly depended on by APEX bar anyInSameApex := func(a, b []ApexInfo) bool {
// apexNamesMap()["foo"]["bar"] doesn't exist: foo is not built for APEX bar collectApexes := func(infos []ApexInfo) []string {
func apexNamesMap() map[string]map[string]bool { var ret []string
return apexData.Once(apexNamesKey, func() interface{} { for _, info := range infos {
return make(map[string]map[string]bool) ret = append(ret, info.InApexes...)
}).(map[string]map[string]bool)
}
// Update the map to mark that a module named moduleName is directly or indirectly
// depended on by the specified APEXes. Directly depending means that a module
// is explicitly listed in the build definition of the APEX via properties like
// native_shared_libs, java_libs, etc.
func UpdateApexDependency(apex ApexInfo, moduleName string, directDep bool) {
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
apexesForModule, ok := apexNamesMap()[moduleName]
if !ok {
apexesForModule = make(map[string]bool)
apexNamesMap()[moduleName] = apexesForModule
} }
apexesForModule[apex.ApexVariationName] = apexesForModule[apex.ApexVariationName] || directDep return ret
for _, apexName := range apex.InApexes {
apexesForModule[apexName] = apexesForModule[apex.ApexVariationName] || directDep
} }
}
// TODO(b/146393795): remove this when b/146393795 is fixed aApexes := collectApexes(a)
func ClearApexDependency() { bApexes := collectApexes(b)
m := apexNamesMap() sort.Strings(bApexes)
for k := range m { for _, aApex := range aApexes {
delete(m, k) index := sort.SearchStrings(bApexes, aApex)
if index < len(bApexes) && bApexes[index] == aApex {
return true
} }
}
// Tests whether a module named moduleName is directly depended on by an APEX
// named apexName.
func DirectlyInApex(apexName string, moduleName string) bool {
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
if apexNamesForModule, ok := apexNamesMap()[moduleName]; ok {
return apexNamesForModule[apexName]
} }
return false return false
}
mctx.VisitDirectDeps(func(dep Module) {
if depApexModule, ok := dep.(ApexModule); ok {
if anyInSameApex(depApexModule.apexModuleBase().apexVariations, am.apexModuleBase().apexVariations) &&
(depApexModule.UniqueApexVariations() ||
depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true
}
}
})
}
// UpdateDirectlyInAnyApex uses the final module to store if any variant of this
// module is directly in any APEX, and then copies the final value to all the modules.
// It also copies the DirectlyInAnyApex value to any direct dependencies with a
// CopyDirectlyInAnyApexTag dependency tag.
func UpdateDirectlyInAnyApex(mctx BottomUpMutatorContext, am ApexModule) {
base := am.apexModuleBase()
// Copy DirectlyInAnyApex and InAnyApex from any direct dependencies with a
// CopyDirectlyInAnyApexTag dependency tag.
mctx.VisitDirectDeps(func(dep Module) {
if _, ok := mctx.OtherModuleDependencyTag(dep).(CopyDirectlyInAnyApexTag); ok {
depBase := dep.(ApexModule).apexModuleBase()
base.ApexProperties.DirectlyInAnyApex = depBase.ApexProperties.DirectlyInAnyApex
base.ApexProperties.InAnyApex = depBase.ApexProperties.InAnyApex
}
})
if base.ApexProperties.DirectlyInAnyApex {
// Variants of a module are always visited sequentially in order, so it is safe to
// write to another variant of this module.
// For a BottomUpMutator the PrimaryModule() is visited first and FinalModule() is
// visited last.
mctx.FinalModule().(ApexModule).apexModuleBase().ApexProperties.AnyVariantDirectlyInAnyApex = true
}
// If this is the FinalModule (last visited module) copy AnyVariantDirectlyInAnyApex to
// all the other variants
if am == mctx.FinalModule().(ApexModule) {
mctx.VisitAllModuleVariants(func(variant Module) {
variant.(ApexModule).apexModuleBase().ApexProperties.AnyVariantDirectlyInAnyApex =
base.ApexProperties.AnyVariantDirectlyInAnyApex
})
}
}
type ApexMembership int
const (
notInApex ApexMembership = 0
indirectlyInApex = iota
directlyInApex
)
// Each apexBundle has an apexContents, and modules in that apex have a provider containing the
// apexContents of each apexBundle they are part of.
type ApexContents struct {
ApexName string
contents map[string]ApexMembership
}
func NewApexContents(name string, contents map[string]ApexMembership) *ApexContents {
return &ApexContents{
ApexName: name,
contents: contents,
}
}
func (i ApexMembership) Add(direct bool) ApexMembership {
if direct || i == directlyInApex {
return directlyInApex
}
return indirectlyInApex
}
func (i ApexMembership) merge(other ApexMembership) ApexMembership {
if other == directlyInApex || i == directlyInApex {
return directlyInApex
}
if other == indirectlyInApex || i == indirectlyInApex {
return indirectlyInApex
}
return notInApex
}
func (ac *ApexContents) DirectlyInApex(name string) bool {
return ac.contents[name] == directlyInApex
}
func (ac *ApexContents) InApex(name string) bool {
return ac.contents[name] != notInApex
} }
// Tests whether a module named moduleName is directly depended on by all APEXes // Tests whether a module named moduleName is directly depended on by all APEXes
// in a list of apexNames. // in an ApexInfo.
func DirectlyInAllApexes(apexNames []string, moduleName string) bool { func DirectlyInAllApexes(apexInfo ApexInfo, moduleName string) bool {
apexNamesMapMutex.Lock() for _, contents := range apexInfo.ApexContents {
defer apexNamesMapMutex.Unlock() if !contents.DirectlyInApex(moduleName) {
for _, apexName := range apexNames {
apexNamesForModule := apexNamesMap()[moduleName]
if !apexNamesForModule[apexName] {
return false return false
} }
} }
return true return true
} }
type hostContext interface {
Host() bool
}
// Tests whether a module named moduleName is directly depended on by any APEX.
func DirectlyInAnyApex(ctx hostContext, moduleName string) bool {
if ctx.Host() {
// Host has no APEX.
return false
}
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
if apexNames, ok := apexNamesMap()[moduleName]; ok {
for an := range apexNames {
if apexNames[an] {
return true
}
}
}
return false
}
// Tests whether a module named module is depended on (including both
// direct and indirect dependencies) by any APEX.
func InAnyApex(moduleName string) bool {
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
apexNames, ok := apexNamesMap()[moduleName]
return ok && len(apexNames) > 0
}
func GetApexesForModule(moduleName string) []string {
ret := []string{}
apexNamesMapMutex.Lock()
defer apexNamesMapMutex.Unlock()
if apexNames, ok := apexNamesMap()[moduleName]; ok {
for an := range apexNames {
ret = append(ret, an)
}
}
return ret
}
func InitApexModule(m ApexModule) { func InitApexModule(m ApexModule) {
base := m.apexModuleBase() base := m.apexModuleBase()
base.canHaveApexVariants = true base.canHaveApexVariants = true

View File

@ -29,10 +29,10 @@ func Test_mergeApexVariations(t *testing.T) {
{ {
name: "single", name: "single",
in: []ApexInfo{ in: []ApexInfo{
{"foo", "current", false, nil, []string{"foo"}}, {"foo", "current", false, nil, []string{"foo"}, nil},
}, },
wantMerged: []ApexInfo{ wantMerged: []ApexInfo{
{"apex10000", "current", false, nil, []string{"foo"}}, {"apex10000", "current", false, nil, []string{"foo"}, nil},
}, },
wantAliases: [][2]string{ wantAliases: [][2]string{
{"foo", "apex10000"}, {"foo", "apex10000"},
@ -41,12 +41,11 @@ func Test_mergeApexVariations(t *testing.T) {
{ {
name: "merge", name: "merge",
in: []ApexInfo{ in: []ApexInfo{
{"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
{"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}}, {"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}, nil},
}, },
wantMerged: []ApexInfo{ wantMerged: []ApexInfo{
{"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}}, {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, nil}},
},
wantAliases: [][2]string{ wantAliases: [][2]string{
{"bar", "apex10000_baz_1"}, {"bar", "apex10000_baz_1"},
{"foo", "apex10000_baz_1"}, {"foo", "apex10000_baz_1"},
@ -55,12 +54,12 @@ func Test_mergeApexVariations(t *testing.T) {
{ {
name: "don't merge version", name: "don't merge version",
in: []ApexInfo{ in: []ApexInfo{
{"foo", "current", false, nil, []string{"foo"}}, {"foo", "current", false, nil, []string{"foo"}, nil},
{"bar", "30", false, nil, []string{"bar"}}, {"bar", "30", false, nil, []string{"bar"}, nil},
}, },
wantMerged: []ApexInfo{ wantMerged: []ApexInfo{
{"apex30", "30", false, nil, []string{"bar"}}, {"apex30", "30", false, nil, []string{"bar"}, nil},
{"apex10000", "current", false, nil, []string{"foo"}}, {"apex10000", "current", false, nil, []string{"foo"}, nil},
}, },
wantAliases: [][2]string{ wantAliases: [][2]string{
{"bar", "apex30"}, {"bar", "apex30"},
@ -70,11 +69,11 @@ func Test_mergeApexVariations(t *testing.T) {
{ {
name: "merge updatable", name: "merge updatable",
in: []ApexInfo{ in: []ApexInfo{
{"foo", "current", false, nil, []string{"foo"}}, {"foo", "current", false, nil, []string{"foo"}, nil},
{"bar", "current", true, nil, []string{"bar"}}, {"bar", "current", true, nil, []string{"bar"}, nil},
}, },
wantMerged: []ApexInfo{ wantMerged: []ApexInfo{
{"apex10000", "current", true, nil, []string{"bar", "foo"}}, {"apex10000", "current", true, nil, []string{"bar", "foo"}, nil},
}, },
wantAliases: [][2]string{ wantAliases: [][2]string{
{"bar", "apex10000"}, {"bar", "apex10000"},
@ -84,12 +83,12 @@ func Test_mergeApexVariations(t *testing.T) {
{ {
name: "don't merge sdks", name: "don't merge sdks",
in: []ApexInfo{ in: []ApexInfo{
{"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
{"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}}, {"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
}, },
wantMerged: []ApexInfo{ wantMerged: []ApexInfo{
{"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}}, {"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}, nil},
{"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}}, {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}, nil},
}, },
wantAliases: [][2]string{ wantAliases: [][2]string{
{"bar", "apex10000_baz_2"}, {"bar", "apex10000_baz_2"},

View File

@ -1499,8 +1499,8 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
if !ctx.PrimaryArch() { if !ctx.PrimaryArch() {
suffix = append(suffix, ctx.Arch().ArchType.String()) suffix = append(suffix, ctx.Arch().ArchType.String())
} }
if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() { if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() {
suffix = append(suffix, apex.ApexVariationName()) suffix = append(suffix, apexInfo.ApexVariationName)
} }
ctx.Variable(pctx, "moduleDesc", desc) ctx.Variable(pctx, "moduleDesc", desc)

View File

@ -67,6 +67,7 @@ var (
androidAppTag = dependencyTag{name: "androidApp", payload: true} androidAppTag = dependencyTag{name: "androidApp", payload: true}
rroTag = dependencyTag{name: "rro", payload: true} rroTag = dependencyTag{name: "rro", payload: true}
bpfTag = dependencyTag{name: "bpf", payload: true} bpfTag = dependencyTag{name: "bpf", payload: true}
testForTag = dependencyTag{name: "test for"}
apexAvailBaseline = makeApexAvailableBaseline() apexAvailBaseline = makeApexAvailableBaseline()
@ -769,7 +770,10 @@ func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
ctx.TopDown("apex_deps", apexDepsMutator).Parallel() ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel() ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
ctx.BottomUp("apex", apexMutator).Parallel() ctx.BottomUp("apex", apexMutator).Parallel()
ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel() ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
@ -785,13 +789,6 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
if !ok || a.vndkApex { if !ok || a.vndkApex {
return return
} }
apexInfo := android.ApexInfo{
ApexVariationName: mctx.ModuleName(),
MinSdkVersionStr: a.minSdkVersion(mctx).String(),
RequiredSdks: a.RequiredSdks(),
Updatable: a.Updatable(),
InApexes: []string{mctx.ModuleName()},
}
useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface()) useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
@ -800,7 +797,9 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
return return
} }
mctx.WalkDeps(func(child, parent android.Module) bool { contents := make(map[string]android.ApexMembership)
continueApexDepsWalk := func(child, parent android.Module) bool {
am, ok := child.(android.ApexModule) am, ok := child.(android.ApexModule)
if !ok || !am.CanHaveApexVariants() { if !ok || !am.CanHaveApexVariants() {
return false return false
@ -813,12 +812,41 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
return false return false
} }
} }
return true
}
mctx.WalkDeps(func(child, parent android.Module) bool {
if !continueApexDepsWalk(child, parent) {
return false
}
depName := mctx.OtherModuleName(child) depName := mctx.OtherModuleName(child)
// If the parent is apexBundle, this child is directly depended. // If the parent is apexBundle, this child is directly depended.
_, directDep := parent.(*apexBundle) _, directDep := parent.(*apexBundle)
android.UpdateApexDependency(apexInfo, depName, directDep) contents[depName] = contents[depName].Add(directDep)
am.BuildForApex(apexInfo) return true
})
apexContents := android.NewApexContents(mctx.ModuleName(), contents)
mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
Contents: apexContents,
})
apexInfo := android.ApexInfo{
ApexVariationName: mctx.ModuleName(),
MinSdkVersionStr: a.minSdkVersion(mctx).String(),
RequiredSdks: a.RequiredSdks(),
Updatable: a.Updatable(),
InApexes: []string{mctx.ModuleName()},
ApexContents: []*android.ApexContents{apexContents},
}
mctx.WalkDeps(func(child, parent android.Module) bool {
if !continueApexDepsWalk(child, parent) {
return false
}
child.(android.ApexModule).BuildForApex(apexInfo)
return true return true
}) })
} }
@ -830,7 +858,40 @@ func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
if am, ok := mctx.Module().(android.ApexModule); ok { if am, ok := mctx.Module().(android.ApexModule); ok {
// Check if any dependencies use unique apex variations. If so, use unique apex variations // Check if any dependencies use unique apex variations. If so, use unique apex variations
// for this module. // for this module.
am.UpdateUniqueApexVariationsForDeps(mctx) android.UpdateUniqueApexVariationsForDeps(mctx, am)
}
}
func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
if !mctx.Module().Enabled() {
return
}
// Check if this module is a test for an apex. If so, add a dependency on the apex
// in order to retrieve its contents later.
if am, ok := mctx.Module().(android.ApexModule); ok {
if testFor := am.TestFor(); len(testFor) > 0 {
mctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "os", Variation: am.Target().OsVariation()},
{"arch", "common"},
}, testForTag, testFor...)
}
}
}
func apexTestForMutator(mctx android.BottomUpMutatorContext) {
if !mctx.Module().Enabled() {
return
}
if _, ok := mctx.Module().(android.ApexModule); ok {
var contents []*android.ApexContents
for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
contents = append(contents, abInfo.Contents)
}
mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
ApexContents: contents,
})
} }
} }
@ -891,8 +952,9 @@ func apexMutator(mctx android.BottomUpMutatorContext) {
if !mctx.Module().Enabled() { if !mctx.Module().Enabled() {
return return
} }
if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
am.CreateApexVariations(mctx) android.CreateApexVariations(mctx, am)
} else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex { } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
// apex bundle itself is mutated so that it and its modules have same // apex bundle itself is mutated so that it and its modules have same
// apex variant. // apex variant.
@ -909,6 +971,15 @@ func apexMutator(mctx android.BottomUpMutatorContext) {
} }
func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
if !mctx.Module().Enabled() {
return
}
if am, ok := mctx.Module().(android.ApexModule); ok {
android.UpdateDirectlyInAnyApex(mctx, am)
}
}
func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
if !mctx.Module().Enabled() { if !mctx.Module().Enabled() {
return return
@ -1118,6 +1189,12 @@ type apexBundleProperties struct {
Payload_fs_type *string Payload_fs_type *string
} }
type ApexBundleInfo struct {
Contents *android.ApexContents
}
var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
type apexTargetBundleProperties struct { type apexTargetBundleProperties struct {
Target struct { Target struct {
// Multilib properties only for android. // Multilib properties only for android.
@ -1908,6 +1985,8 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo
return false return false
} }
childApexInfo := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
dt := ctx.OtherModuleDependencyTag(child) dt := ctx.OtherModuleDependencyTag(child)
if _, ok := dt.(android.ExcludeFromApexContentsTag); ok { if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
@ -1924,7 +2003,7 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo
} }
// Check for the indirect dependencies if it is considered as part of the APEX // Check for the indirect dependencies if it is considered as part of the APEX
if android.InList(ctx.ModuleName(), am.InApexes()) { if android.InList(ctx.ModuleName(), childApexInfo.InApexes) {
return do(ctx, parent, am, false /* externalDep */) return do(ctx, parent, am, false /* externalDep */)
} }
@ -2032,6 +2111,8 @@ func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext
return return
} }
abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
if ccm, ok := to.(*cc.Module); ok { if ccm, ok := to.(*cc.Module); ok {
apexName := ctx.ModuleName() apexName := ctx.ModuleName()
@ -2052,7 +2133,7 @@ func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext
return false return false
} }
isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName) isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
if isStubLibraryFromOtherApex && !externalDep { if isStubLibraryFromOtherApex && !externalDep {
ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+ ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
"It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false)) "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
@ -2291,7 +2372,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs) af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
af.transitiveDep = true af.transitiveDep = true
if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) { abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
// If the dependency is a stubs lib, don't include it in this APEX, // If the dependency is a stubs lib, don't include it in this APEX,
// but make sure that the lib is installed on the device. // but make sure that the lib is installed on the device.
// In case no APEX is having the lib, the lib is installed to the system // In case no APEX is having the lib, the lib is installed to the system
@ -2299,7 +2381,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// //
// Always include if we are a host-apex however since those won't have any // Always include if we are a host-apex however since those won't have any
// system libraries. // system libraries.
if !android.DirectlyInAnyApex(ctx, depName) { if !am.DirectlyInAnyApex() {
// we need a module name for Make // we need a module name for Make
name := cc.BaseModuleName() + cc.Properties.SubName name := cc.BaseModuleName() + cc.Properties.SubName
if proptools.Bool(a.properties.Use_vendor) { if proptools.Bool(a.properties.Use_vendor) {
@ -2338,6 +2420,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
} }
} else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
// nothing
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() { } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName) ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
} }

View File

@ -72,10 +72,13 @@ func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContex
updatableFlatLists := android.Paths{} updatableFlatLists := android.Paths{}
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok { if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok {
if path := binaryInfo.FlatListPath(); path != nil && binaryInfo.Updatable() { apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
if path := binaryInfo.FlatListPath(); path != nil {
if binaryInfo.Updatable() || apexInfo.Updatable {
updatableFlatLists = append(updatableFlatLists, path) updatableFlatLists = append(updatableFlatLists, path)
} }
} }
}
}) })
allowedDeps := android.ExistentPathForSource(ctx, "build/soong/apex/allowed_deps.txt").Path() allowedDeps := android.ExistentPathForSource(ctx, "build/soong/apex/allowed_deps.txt").Path()

View File

@ -125,8 +125,6 @@ func withUnbundledBuild(_ map[string][]byte, config android.Config) {
} }
func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
android.ClearApexDependency()
bp = bp + ` bp = bp + `
filegroup { filegroup {
name: "myapex-file_contexts", name: "myapex-file_contexts",
@ -1607,10 +1605,12 @@ func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
`) `)
expectLink := func(from, from_variant, to, to_variant string) { expectLink := func(from, from_variant, to, to_variant string) {
t.Helper()
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
} }
expectNoLink := func(from, from_variant, to, to_variant string) { expectNoLink := func(from, from_variant, to, to_variant string) {
t.Helper()
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
} }
@ -3643,16 +3643,13 @@ func TestNonTestApex(t *testing.T) {
// Ensure that the platform variant ends with _shared // Ensure that the platform variant ends with _shared
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
if !android.InAnyApex("mylib_common") { if !ctx.ModuleForTests("mylib_common", "android_arm64_armv8-a_shared_apex10000").Module().(*cc.Module).InAnyApex() {
t.Log("Found mylib_common not in any apex!") t.Log("Found mylib_common not in any apex!")
t.Fail() t.Fail()
} }
} }
func TestTestApex(t *testing.T) { func TestTestApex(t *testing.T) {
if android.InAnyApex("mylib_common_test") {
t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
}
ctx, _ := testApex(t, ` ctx, _ := testApex(t, `
apex_test { apex_test {
name: "myapex", name: "myapex",
@ -5845,7 +5842,6 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) {
t.Helper() t.Helper()
android.ClearApexDependency()
bp += ` bp += `
apex_key { apex_key {
name: "myapex.key", name: "myapex.key",

View File

@ -33,7 +33,6 @@ var (
) )
type AndroidMkContext interface { type AndroidMkContext interface {
BaseModuleName() string
Target() android.Target Target() android.Target
subAndroidMk(*android.AndroidMkEntries, interface{}) subAndroidMk(*android.AndroidMkEntries, interface{})
Arch() android.Arch Arch() android.Arch
@ -44,6 +43,7 @@ type AndroidMkContext interface {
static() bool static() bool
InRamdisk() bool InRamdisk() bool
InRecovery() bool InRecovery() bool
AnyVariantDirectlyInAnyApex() bool
} }
type subAndroidMkProvider interface { type subAndroidMkProvider interface {
@ -63,7 +63,7 @@ func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}
} }
func (c *Module) AndroidMkEntries() []android.AndroidMkEntries { func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
if c.Properties.HideFromMake || !c.IsForPlatform() { if c.hideApexVariantFromMake || c.Properties.HideFromMake {
return []android.AndroidMkEntries{{ return []android.AndroidMkEntries{{
Disabled: true, Disabled: true,
}} }}
@ -277,9 +277,8 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries
} }
}) })
} }
if len(library.Properties.Stubs.Versions) > 0 && if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.AnyVariantDirectlyInAnyApex() &&
android.DirectlyInAnyApex(ctx, ctx.BaseModuleName()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() {
!ctx.static() {
if library.buildStubs() && library.isLatestStubVersion() { if library.buildStubs() && library.isLatestStubVersion() {
// reference the latest version via its name without suffix when it is provided by apex // reference the latest version via its name without suffix when it is provided by apex
entries.SubName = "" entries.SubName = ""

View File

@ -445,7 +445,9 @@ func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
// The original path becomes a symlink to the corresponding file in the // The original path becomes a symlink to the corresponding file in the
// runtime APEX. // runtime APEX.
translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexVariationName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() { if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !ctx.Host() && ctx.directlyInAnyApex() &&
!translatedArch && ctx.apexVariationName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() {
if ctx.Device() && isBionic(ctx.baseModuleName()) { if ctx.Device() && isBionic(ctx.baseModuleName()) {
binary.installSymlinkToRuntimeApex(ctx, file) binary.installSymlinkToRuntimeApex(ctx, file)
} }

View File

@ -366,6 +366,7 @@ type ModuleContextIntf interface {
bootstrap() bool bootstrap() bool
mustUseVendorVariant() bool mustUseVendorVariant() bool
nativeCoverage() bool nativeCoverage() bool
directlyInAnyApex() bool
} }
type ModuleContext interface { type ModuleContext interface {
@ -545,8 +546,17 @@ var (
dataLibDepTag = dependencyTag{name: "data lib"} dataLibDepTag = dependencyTag{name: "data lib"}
runtimeDepTag = dependencyTag{name: "runtime lib"} runtimeDepTag = dependencyTag{name: "runtime lib"}
testPerSrcDepTag = dependencyTag{name: "test_per_src"} testPerSrcDepTag = dependencyTag{name: "test_per_src"}
testForDepTag = dependencyTag{name: "test for apex"}
stubImplDepTag = copyDirectlyInAnyApexDependencyTag{name: "stub_impl"}
) )
type copyDirectlyInAnyApexDependencyTag dependencyTag
func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
func IsSharedDepTag(depTag blueprint.DependencyTag) bool { func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
ccLibDepTag, ok := depTag.(libraryDependencyTag) ccLibDepTag, ok := depTag.(libraryDependencyTag)
return ok && ccLibDepTag.shared() return ok && ccLibDepTag.shared()
@ -622,6 +632,8 @@ type Module struct {
// For apex variants, this is set as apex.min_sdk_version // For apex variants, this is set as apex.min_sdk_version
apexSdkVersion android.ApiLevel apexSdkVersion android.ApiLevel
hideApexVariantFromMake bool
} }
func (c *Module) Toc() android.OptionalPath { func (c *Module) Toc() android.OptionalPath {
@ -1363,11 +1375,11 @@ func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
} }
func (ctx *moduleContextImpl) isForPlatform() bool { func (ctx *moduleContextImpl) isForPlatform() bool {
return ctx.mod.IsForPlatform() return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
} }
func (ctx *moduleContextImpl) apexVariationName() string { func (ctx *moduleContextImpl) apexVariationName() string {
return ctx.mod.ApexVariationName() return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
} }
func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel { func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
@ -1390,6 +1402,10 @@ func (ctx *moduleContextImpl) nativeCoverage() bool {
return ctx.mod.nativeCoverage() return ctx.mod.nativeCoverage()
} }
func (ctx *moduleContextImpl) directlyInAnyApex() bool {
return ctx.mod.DirectlyInAnyApex()
}
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{ return &Module{
hod: hod, hod: hod,
@ -1545,6 +1561,11 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
return return
} }
apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
c.hideApexVariantFromMake = true
}
c.makeLinkType = c.getMakeLinkType(actx) c.makeLinkType = c.getMakeLinkType(actx)
c.Properties.SubName = "" c.Properties.SubName = ""
@ -1676,8 +1697,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
// force anything in the make world to link against the stubs library. // force anything in the make world to link against the stubs library.
// (unless it is explicitly referenced via .bootstrap suffix or the // (unless it is explicitly referenced via .bootstrap suffix or the
// module is marked with 'bootstrap: true'). // module is marked with 'bootstrap: true').
if c.HasStubsVariants() && if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
!c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() && !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
c.IsStubs() { c.IsStubs() {
c.Properties.HideFromMake = false // unhide c.Properties.HideFromMake = false // unhide
@ -1686,13 +1706,13 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
// glob exported headers for snapshot, if BOARD_VNDK_VERSION is current. // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" { if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
if isSnapshotAware(ctx, c) { if isSnapshotAware(ctx, c, apexInfo) {
i.collectHeadersForSnapshot(ctx) i.collectHeadersForSnapshot(ctx)
} }
} }
} }
if c.installable() { if c.installable(apexInfo) {
c.installer.install(ctx, c.outputFile.Path()) c.installer.install(ctx, c.outputFile.Path())
if ctx.Failed() { if ctx.Failed() {
return return
@ -2381,8 +2401,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// For the dependency from platform to apex, use the latest stubs // For the dependency from platform to apex, use the latest stubs
c.apexSdkVersion = android.FutureApiLevel c.apexSdkVersion = android.FutureApiLevel
if !c.IsForPlatform() { apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx) if !apexInfo.IsForPlatform() {
c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
} }
if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
@ -2493,8 +2514,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if ccDep.CcLibrary() && !libDepTag.static() { if ccDep.CcLibrary() && !libDepTag.static() {
depIsStubs := ccDep.BuildStubs() depIsStubs := ccDep.BuildStubs()
depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants() depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants()
depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName) depInSameApexes := android.DirectlyInAllApexes(apexInfo, depName)
depInPlatform := !android.DirectlyInAnyApex(ctx, depName) depInPlatform := !dep.(android.ApexModule).AnyVariantDirectlyInAnyApex()
var useThisDep bool var useThisDep bool
if depIsStubs && libDepTag.explicitlyVersioned { if depIsStubs && libDepTag.explicitlyVersioned {
@ -2504,7 +2525,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// Use non-stub variant if that is the only choice // Use non-stub variant if that is the only choice
// (i.e. depending on a lib without stubs.version property) // (i.e. depending on a lib without stubs.version property)
useThisDep = true useThisDep = true
} else if c.IsForPlatform() { } else if apexInfo.IsForPlatform() {
// If not building for APEX, use stubs only when it is from // If not building for APEX, use stubs only when it is from
// an APEX (and not from platform) // an APEX (and not from platform)
useThisDep = (depInPlatform != depIsStubs) useThisDep = (depInPlatform != depIsStubs)
@ -2513,11 +2534,12 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// always link to non-stub variant // always link to non-stub variant
useThisDep = !depIsStubs useThisDep = !depIsStubs
} }
for _, testFor := range c.TestFor() {
// Another exception: if this module is bundled with an APEX, then // Another exception: if this module is bundled with an APEX, then
// it is linked with the non-stub variant of a module in the APEX // it is linked with the non-stub variant of a module in the APEX
// as if this is part of the APEX. // as if this is part of the APEX.
if android.DirectlyInApex(testFor, depName) { testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
for _, apexContents := range testFor.ApexContents {
if apexContents.DirectlyInApex(depName) {
useThisDep = !depIsStubs useThisDep = !depIsStubs
break break
} }
@ -2549,7 +2571,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// by default, use current version of LLNDK // by default, use current version of LLNDK
versionToUse := "" versionToUse := ""
versions := m.AllStubsVersions() versions := m.AllStubsVersions()
if c.ApexVariationName() != "" && len(versions) > 0 { if apexInfo.ApexVariationName != "" && len(versions) > 0 {
// if this is for use_vendor apex && dep has stubsVersions // if this is for use_vendor apex && dep has stubsVersions
// apply the same rule of apex sdk enforcement to choose right version // apply the same rule of apex sdk enforcement to choose right version
var err error var err error
@ -2711,10 +2733,11 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
c.Properties.AndroidMkHeaderLibs, makeLibName) c.Properties.AndroidMkHeaderLibs, makeLibName)
case libDepTag.shared(): case libDepTag.shared():
if ccDep.CcLibrary() { if ccDep.CcLibrary() {
if ccDep.BuildStubs() && android.InAnyApex(depName) { if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
// Add the dependency to the APEX(es) providing the library so that // Add the dependency to the APEX(es) providing the library so that
// m <module> can trigger building the APEXes as well. // m <module> can trigger building the APEXes as well.
for _, an := range android.GetApexesForModule(depName) { depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
for _, an := range depApexInfo.InApexes {
c.Properties.ApexesProvidingSharedLibs = append( c.Properties.ApexesProvidingSharedLibs = append(
c.Properties.ApexesProvidingSharedLibs, an) c.Properties.ApexesProvidingSharedLibs, an)
} }
@ -3018,7 +3041,7 @@ func (c *Module) EverInstallable() bool {
c.installer.everInstallable() c.installer.everInstallable()
} }
func (c *Module) installable() bool { func (c *Module) installable(apexInfo android.ApexInfo) bool {
ret := c.EverInstallable() && ret := c.EverInstallable() &&
// Check to see whether the module has been configured to not be installed. // Check to see whether the module has been configured to not be installed.
proptools.BoolDefault(c.Properties.Installable, true) && proptools.BoolDefault(c.Properties.Installable, true) &&
@ -3027,7 +3050,7 @@ func (c *Module) installable() bool {
// The platform variant doesn't need further condition. Apex variants however might not // The platform variant doesn't need further condition. Apex variants however might not
// be installable because it will likely to be included in the APEX and won't appear // be installable because it will likely to be included in the APEX and won't appear
// in the system partition. // in the system partition.
if c.IsForPlatform() { if apexInfo.IsForPlatform() {
return ret return ret
} }

View File

@ -1231,18 +1231,19 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
library.baseInstaller.subDir += "-" + vndkVersion library.baseInstaller.subDir += "-" + vndkVersion
} }
} }
} else if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { } else if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.directlyInAnyApex() {
// Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory. // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory.
// The original path becomes a symlink to the corresponding file in the // The original path becomes a symlink to the corresponding file in the
// runtime APEX. // runtime APEX.
translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && !translatedArch && !ctx.inRamdisk() && !ctx.inRecovery() { if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() &&
!translatedArch && !ctx.inRamdisk() && !ctx.inRecovery() {
if ctx.Device() { if ctx.Device() {
library.installSymlinkToRuntimeApex(ctx, file) library.installSymlinkToRuntimeApex(ctx, file)
} }
library.baseInstaller.subDir = "bootstrap" library.baseInstaller.subDir = "bootstrap"
} }
} else if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && ctx.isLlndk(ctx.Config()) && !isBionic(ctx.baseModuleName()) { } else if ctx.directlyInAnyApex() && ctx.isLlndk(ctx.Config()) && !isBionic(ctx.baseModuleName()) {
// Skip installing LLNDK (non-bionic) libraries moved to APEX. // Skip installing LLNDK (non-bionic) libraries moved to APEX.
ctx.Module().SkipInstall() ctx.Module().SkipInstall()
} }
@ -1531,6 +1532,8 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str
if variants[i] != "" { if variants[i] != "" {
m.(LinkableInterface).SetBuildStubs() m.(LinkableInterface).SetBuildStubs()
m.(LinkableInterface).SetStubsVersion(variants[i]) m.(LinkableInterface).SetStubsVersion(variants[i])
// The stubs depend on the implementation
mctx.AddInterVariantDependency(stubImplDepTag, modules[i], modules[0])
} }
} }
mctx.AliasVariation("") mctx.AliasVariation("")

View File

@ -74,6 +74,8 @@ type llndkStubDecorator struct {
exportHeadersTimestamp android.OptionalPath exportHeadersTimestamp android.OptionalPath
versionScriptPath android.ModuleGenPath versionScriptPath android.ModuleGenPath
movedToApex bool
} }
func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
@ -135,6 +137,11 @@ func (stub *llndkStubDecorator) processHeaders(ctx ModuleContext, srcHeaderDir s
func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
objs Objects) android.Path { objs Objects) android.Path {
impl := ctx.GetDirectDepWithTag(ctx.baseModuleName(), llndkImplDep)
if implApexModule, ok := impl.(android.ApexModule); ok {
stub.movedToApex = implApexModule.DirectlyInAnyApex()
}
if !Bool(stub.Properties.Unversioned) { if !Bool(stub.Properties.Unversioned) {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)

View File

@ -58,10 +58,10 @@ func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string,
return snapshot, found return snapshot, found
} }
func isSnapshotAware(ctx android.ModuleContext, m *Module) bool { func isSnapshotAware(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool {
if _, _, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m); ok { if _, _, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m, apexInfo); ok {
return ctx.Config().VndkSnapshotBuildArtifacts() return ctx.Config().VndkSnapshotBuildArtifacts()
} else if isVendorSnapshotModule(m, isVendorProprietaryPath(ctx.ModuleDir())) { } else if isVendorSnapshotModule(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) {
return true return true
} }
return false return false

View File

@ -537,7 +537,7 @@ func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {
// AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might // AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might
// depend on newer VNDK) So they are captured as vendor snapshot To build older vendor // depend on newer VNDK) So they are captured as vendor snapshot To build older vendor
// image and newer system image altogether. // image and newer system image altogether.
func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool) bool { func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool, apexInfo android.ApexInfo) bool {
if !m.Enabled() || m.Properties.HideFromMake { if !m.Enabled() || m.Properties.HideFromMake {
return false return false
} }
@ -562,7 +562,7 @@ func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool) bool {
return false return false
} }
// the module must be installed in /vendor // the module must be installed in /vendor
if !m.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() { if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() {
return false return false
} }
// skip kernel_headers which always depend on vendor // skip kernel_headers which always depend on vendor
@ -825,6 +825,7 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
moduleDir := ctx.ModuleDir(module) moduleDir := ctx.ModuleDir(module)
inVendorProprietaryPath := isVendorProprietaryPath(moduleDir) inVendorProprietaryPath := isVendorProprietaryPath(moduleDir)
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
if m.ExcludeFromVendorSnapshot() { if m.ExcludeFromVendorSnapshot() {
if inVendorProprietaryPath { if inVendorProprietaryPath {
@ -842,7 +843,7 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
} }
} }
if !isVendorSnapshotModule(m, inVendorProprietaryPath) { if !isVendorSnapshotModule(m, inVendorProprietaryPath, apexInfo) {
return return
} }

View File

@ -300,6 +300,7 @@ func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
if !Bool(lib.Properties.Vendor_available) { if !Bool(lib.Properties.Vendor_available) {
vndkPrivateLibraries(mctx.Config())[name] = filename vndkPrivateLibraries(mctx.Config())[name] = filename
} }
if mctx.OtherModuleExists(name) { if mctx.OtherModuleExists(name) {
mctx.AddFarVariationDependencies(m.Target().Variations(), llndkImplDep, name) mctx.AddFarVariationDependencies(m.Target().Variations(), llndkImplDep, name)
} }
@ -533,11 +534,13 @@ type vndkSnapshotSingleton struct {
vndkSnapshotZipFile android.OptionalPath vndkSnapshotZipFile android.OptionalPath
} }
func isVndkSnapshotLibrary(config android.DeviceConfig, m *Module) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) { func isVndkSnapshotLibrary(config android.DeviceConfig, m *Module,
apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
if m.Target().NativeBridge == android.NativeBridgeEnabled { if m.Target().NativeBridge == android.NativeBridgeEnabled {
return nil, "", false return nil, "", false
} }
if !m.inVendor() || !m.installable() || m.isSnapshotPrebuilt() { if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() {
return nil, "", false return nil, "", false
} }
l, ok := m.linker.(snapshotLibraryInterface) l, ok := m.linker.(snapshotLibraryInterface)
@ -659,7 +662,9 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
return return
} }
l, vndkType, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m) apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
l, vndkType, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m, apexInfo)
if !ok { if !ok {
return return
} }
@ -823,14 +828,21 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton
func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
// Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
// they been moved to an apex. // they been moved to an apex.
movedToApexLlndkLibraries := []string{} movedToApexLlndkLibraries := make(map[string]bool)
for lib := range llndkLibraries(ctx.Config()) { ctx.VisitAllModules(func(module android.Module) {
if m, ok := module.(*Module); ok {
if llndk, ok := m.linker.(*llndkStubDecorator); ok {
// Skip bionic libs, they are handled in different manner // Skip bionic libs, they are handled in different manner
if android.DirectlyInAnyApex(&notOnHostContext{}, lib) && !isBionic(lib) { name := m.BaseModuleName()
movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib) if llndk.movedToApex && !isBionic(m.BaseModuleName()) {
movedToApexLlndkLibraries[name] = true
} }
} }
ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " ")) }
})
ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
// Make uses LLNDK_LIBRARIES to determine which libraries to install. // Make uses LLNDK_LIBRARIES to determine which libraries to install.
// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN. // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.

View File

@ -477,6 +477,8 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
a.aapt.buildActions(ctx, sdkContext(a)) a.aapt.buildActions(ctx, sdkContext(a))
a.exportedSdkLibs = a.aapt.sdkLibraries a.exportedSdkLibs = a.aapt.sdkLibraries
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
ctx.CheckbuildFile(a.proguardOptionsFile) ctx.CheckbuildFile(a.proguardOptionsFile)
ctx.CheckbuildFile(a.exportPackage) ctx.CheckbuildFile(a.exportPackage)
ctx.CheckbuildFile(a.aaptSrcJar) ctx.CheckbuildFile(a.aaptSrcJar)
@ -569,6 +571,8 @@ type AARImport struct {
manifest android.WritablePath manifest android.WritablePath
exportedStaticPackages android.Paths exportedStaticPackages android.Paths
hideApexVariantFromMake bool
} }
func (a *AARImport) sdkVersion() sdkSpec { func (a *AARImport) sdkVersion() sdkSpec {
@ -662,6 +666,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return return
} }
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
aarName := ctx.ModuleName() + ".aar" aarName := ctx.ModuleName() + ".aar"
var aar android.Path var aar android.Path
aar = android.PathForModuleSrc(ctx, a.properties.Aars[0]) aar = android.PathForModuleSrc(ctx, a.properties.Aars[0])

View File

@ -23,8 +23,7 @@ import (
func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries { func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host() hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host()
if !library.IsForPlatform() { if library.hideApexVariantFromMake {
// Don't emit hostdex modules from the APEX variants
hostDexNeeded = false hostDexNeeded = false
} }
@ -61,22 +60,15 @@ func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
var entriesList []android.AndroidMkEntries var entriesList []android.AndroidMkEntries
mainEntries := android.AndroidMkEntries{Disabled: true} if library.hideApexVariantFromMake {
// For a java library built for an APEX we don't need Make module
// For a java library built for an APEX, we don't need Make module entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
hideFromMake := !library.IsForPlatform() } else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
// If not available for platform, don't emit to make. // Platform variant. If not available for the platform, we don't need Make module.
if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) { // May still need to add some additional dependencies.
hideFromMake = true
}
if hideFromMake {
// May still need to add some additional dependencies. This will be called
// once for the platform variant (even if it is not being used) and once each
// for the APEX specific variants. In order to avoid adding the dependency
// multiple times only add it for the platform variant.
checkedModulePaths := library.additionalCheckedModules checkedModulePaths := library.additionalCheckedModules
if library.IsForPlatform() && len(checkedModulePaths) != 0 { if len(checkedModulePaths) != 0 {
mainEntries = android.AndroidMkEntries{ entriesList = append(entriesList, android.AndroidMkEntries{
Class: "FAKE", Class: "FAKE",
// Need at least one output file in order for this to take effect. // Need at least one output file in order for this to take effect.
OutputFile: android.OptionalPathForPath(checkedModulePaths[0]), OutputFile: android.OptionalPathForPath(checkedModulePaths[0]),
@ -86,10 +78,12 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", checkedModulePaths.Strings()...) entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", checkedModulePaths.Strings()...)
}, },
}, },
} })
} else {
entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
} }
} else { } else {
mainEntries = android.AndroidMkEntries{ entriesList = append(entriesList, android.AndroidMkEntries{
Class: "JAVA_LIBRARIES", Class: "JAVA_LIBRARIES",
DistFiles: library.distFiles, DistFiles: library.distFiles,
OutputFile: android.OptionalPathForPath(library.outputFile), OutputFile: android.OptionalPathForPath(library.outputFile),
@ -134,12 +128,11 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports) entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
}, },
}, },
} })
} }
hostDexEntries := library.AndroidMkEntriesHostDex() entriesList = append(entriesList, library.AndroidMkEntriesHostDex())
entriesList = append(entriesList, mainEntries, hostDexEntries)
return entriesList return entriesList
} }
@ -189,7 +182,7 @@ func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries { func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().Unversioned() { if prebuilt.hideApexVariantFromMake || !prebuilt.ContainingSdk().Unversioned() {
return []android.AndroidMkEntries{android.AndroidMkEntries{ return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true, Disabled: true,
}} }}
@ -211,7 +204,7 @@ func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries { func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
if !prebuilt.IsForPlatform() { if prebuilt.hideApexVariantFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{ return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true, Disabled: true,
}} }}
@ -239,7 +232,7 @@ func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries { func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
if !prebuilt.IsForPlatform() { if prebuilt.hideApexVariantFromMake {
return []android.AndroidMkEntries{{ return []android.AndroidMkEntries{{
Disabled: true, Disabled: true,
}} }}
@ -309,7 +302,7 @@ func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
if !app.IsForPlatform() || app.appProperties.HideFromMake { if app.hideApexVariantFromMake || app.appProperties.HideFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{ return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true, Disabled: true,
}} }}
@ -458,7 +451,7 @@ func (a *AndroidTestHelperApp) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries { func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries {
if !a.IsForPlatform() { if a.hideApexVariantFromMake {
return []android.AndroidMkEntries{{ return []android.AndroidMkEntries{{
Disabled: true, Disabled: true,
}} }}
@ -638,7 +631,7 @@ func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries {
} }
func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries { func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries {
if !a.IsForPlatform() { if a.hideApexVariantFromMake {
// The non-platform variant is placed inside APEX. No reason to // The non-platform variant is placed inside APEX. No reason to
// make it available to Make. // make it available to Make.
return nil return nil

View File

@ -480,8 +480,9 @@ func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err) ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
} }
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) || return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
!a.IsForPlatform() !apexInfo.IsForPlatform()
} }
// Returns whether this module should have the dex file stored uncompressed in the APK. // Returns whether this module should have the dex file stored uncompressed in the APK.
@ -504,8 +505,9 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
} }
func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) || return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
!a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs !apexInfo.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
} }
func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string { func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string {
@ -756,6 +758,10 @@ func (a *AndroidApp) InstallApkName() string {
func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
var apkDeps android.Paths var apkDeps android.Paths
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
a.hideApexVariantFromMake = true
}
a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx) a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex) a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
@ -850,8 +856,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile) BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
a.bundleFile = bundleFile a.bundleFile = bundleFile
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
// Install the app package. // Install the app package.
if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() { if (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() {
ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile) ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
for _, extra := range a.extraOutputFiles { for _, extra := range a.extraOutputFiles {
ctx.InstallFile(a.installDir, extra.Base(), extra) ctx.InstallFile(a.installDir, extra.Base(), extra)
@ -979,7 +987,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
} }
func (a *AndroidApp) Updatable() bool { func (a *AndroidApp) Updatable() bool {
return Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable() return Bool(a.appProperties.Updatable)
} }
func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string { func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string {
@ -1335,6 +1343,8 @@ type AndroidAppImport struct {
preprocessed bool preprocessed bool
installPath android.InstallPath installPath android.InstallPath
hideApexVariantFromMake bool
} }
type AndroidAppImportProperties struct { type AndroidAppImportProperties struct {
@ -1481,6 +1491,11 @@ func (a *AndroidAppImport) InstallApkName() string {
} }
func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) { func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
a.hideApexVariantFromMake = true
}
numCertPropsSet := 0 numCertPropsSet := 0
if String(a.properties.Certificate) != "" { if String(a.properties.Certificate) != "" {
numCertPropsSet++ numCertPropsSet++
@ -1569,7 +1584,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
// TODO: Optionally compress the output apk. // TODO: Optionally compress the output apk.
if a.IsForPlatform() { if apexInfo.IsForPlatform() {
a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile) a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
} }

View File

@ -94,7 +94,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
} }
// Don't preopt APEX variant module // Don't preopt APEX variant module
if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() { if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
return true return true
} }

View File

@ -266,12 +266,13 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
} }
// Check that this module satisfies constraints for a particular boot image. // Check that this module satisfies constraints for a particular boot image.
apex, isApexModule := module.(android.ApexModule) _, isApexModule := module.(android.ApexModule)
fromUpdatableApex := isApexModule && apex.Updatable() apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
fromUpdatableApex := isApexModule && apexInfo.Updatable
if image.name == artBootImageName { if image.name == artBootImageName {
if isApexModule && len(apex.InApexes()) > 0 && allHavePrefix(apex.InApexes(), "com.android.art.") { if isApexModule && len(apexInfo.InApexes) > 0 && allHavePrefix(apexInfo.InApexes, "com.android.art.") {
// ok: found the jar in the ART apex // ok: found the jar in the ART apex
} else if isApexModule && apex.IsForPlatform() && isHostdex(module) { } else if isApexModule && apexInfo.IsForPlatform() && isHostdex(module) {
// exception (skip and continue): special "hostdex" platform variant // exception (skip and continue): special "hostdex" platform variant
return -1, nil return -1, nil
} else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { } else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@ -279,7 +280,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
return -1, nil return -1, nil
} else if fromUpdatableApex { } else if fromUpdatableApex {
// error: this jar is part of an updatable apex other than ART // error: this jar is part of an updatable apex other than ART
ctx.Errorf("module %q from updatable apexes %q is not allowed in the ART boot image", name, apex.InApexes()) ctx.Errorf("module %q from updatable apexes %q is not allowed in the ART boot image", name, apexInfo.InApexes)
} else { } else {
// error: this jar is part of the platform or a non-updatable apex // error: this jar is part of the platform or a non-updatable apex
ctx.Errorf("module %q is not allowed in the ART boot image", name) ctx.Errorf("module %q is not allowed in the ART boot image", name)
@ -289,7 +290,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
// ok: this jar is part of the platform or a non-updatable apex // ok: this jar is part of the platform or a non-updatable apex
} else { } else {
// error: this jar is part of an updatable apex // error: this jar is part of an updatable apex
ctx.Errorf("module %q from updatable apexes %q is not allowed in the framework boot image", name, apex.InApexes()) ctx.Errorf("module %q from updatable apexes %q is not allowed in the framework boot image", name, apexInfo.InApexes)
} }
} else { } else {
panic("unknown boot image: " + image.name) panic("unknown boot image: " + image.name)

View File

@ -161,11 +161,10 @@ func stubFlagsRule(ctx android.SingletonContext) {
// For a java lib included in an APEX, only take the one built for // For a java lib included in an APEX, only take the one built for
// the platform variant, and skip the variants for APEXes. // the platform variant, and skip the variants for APEXes.
// Otherwise, the hiddenapi tool will complain about duplicated classes // Otherwise, the hiddenapi tool will complain about duplicated classes
if a, ok := module.(android.ApexModule); ok { apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
if android.InAnyApex(module.Name()) && !a.IsForPlatform() { if !apexInfo.IsForPlatform() {
return return
} }
}
bootDexJars = append(bootDexJars, jar) bootDexJars = append(bootDexJars, jar)
} }

View File

@ -451,6 +451,8 @@ type Module struct {
// Collect the module directory for IDE info in java/jdeps.go. // Collect the module directory for IDE info in java/jdeps.go.
modulePaths []string modulePaths []string
hideApexVariantFromMake bool
} }
func (j *Module) addHostProperties() { func (j *Module) addHostProperties() {
@ -638,8 +640,9 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
// Force enable the instrumentation for java code that is built for APEXes ... // Force enable the instrumentation for java code that is built for APEXes ...
// except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
// doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true. // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
isJacocoAgent := ctx.ModuleName() == "jacocoagent" isJacocoAgent := ctx.ModuleName() == "jacocoagent"
if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() { if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
return true return true
} else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@ -1602,7 +1605,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.implementationAndResourcesJar = implementationAndResourcesJar j.implementationAndResourcesJar = implementationAndResourcesJar
// Enable dex compilation for the APEX variants, unless it is disabled explicitly // Enable dex compilation for the APEX variants, unless it is disabled explicitly
if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() { apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
if j.dexProperties.Compile_dex == nil { if j.dexProperties.Compile_dex == nil {
j.dexProperties.Compile_dex = proptools.BoolPtr(true) j.dexProperties.Compile_dex = proptools.BoolPtr(true)
} }
@ -1684,7 +1688,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion()) j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
j.linter.javaLanguageLevel = flags.javaVersion.String() j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3" j.linter.kotlinLanguageLevel = "1.3"
if j.ApexVariationName() != "" && ctx.Config().UnbundledBuildApps() { if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
j.linter.buildModuleReportZip = true j.linter.buildModuleReportZip = true
} }
j.linter.lint(ctx) j.linter.lint(ctx)
@ -1946,7 +1950,7 @@ func (j *Library) PermittedPackagesForUpdatableBootJars() []string {
func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
// Store uncompressed (and aligned) any dex files from jars in APEXes. // Store uncompressed (and aligned) any dex files from jars in APEXes.
if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() { if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
return true return true
} }
@ -1968,6 +1972,11 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo
} }
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
j.hideApexVariantFromMake = true
}
j.checkSdkVersions(ctx) j.checkSdkVersions(ctx)
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
@ -1982,7 +1991,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Collect the module directory for IDE info in java/jdeps.go. // Collect the module directory for IDE info in java/jdeps.go.
j.modulePaths = append(j.modulePaths, ctx.ModuleDir()) j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform() exclusivelyForApex := !apexInfo.IsForPlatform()
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
var extraInstallDeps android.Paths var extraInstallDeps android.Paths
if j.InstallMixin != nil { if j.InstallMixin != nil {
@ -2574,6 +2583,8 @@ type Import struct {
combinedClasspathFile android.Path combinedClasspathFile android.Path
exportedSdkLibs dexpreopt.LibraryPaths exportedSdkLibs dexpreopt.LibraryPaths
exportAidlIncludeDirs android.Paths exportAidlIncludeDirs android.Paths
hideApexVariantFromMake bool
} }
func (j *Import) sdkVersion() sdkSpec { func (j *Import) sdkVersion() sdkSpec {
@ -2629,6 +2640,10 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
j.hideApexVariantFromMake = true
}
jars := android.PathsForModuleSrc(ctx, j.properties.Jars) jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
jarName := j.Stem() + ".jar" jarName := j.Stem() + ".jar"
@ -2872,6 +2887,8 @@ type DexImport struct {
maybeStrippedDexJarFile android.Path maybeStrippedDexJarFile android.Path
dexpreopter dexpreopter
hideApexVariantFromMake bool
} }
func (j *DexImport) Prebuilt() *android.Prebuilt { func (j *DexImport) Prebuilt() *android.Prebuilt {
@ -2907,6 +2924,11 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.PropertyErrorf("jars", "exactly one jar must be provided") ctx.PropertyErrorf("jars", "exactly one jar must be provided")
} }
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
j.hideApexVariantFromMake = true
}
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
@ -2951,7 +2973,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.maybeStrippedDexJarFile = dexOutputFile j.maybeStrippedDexJarFile = dexOutputFile
if j.IsForPlatform() { if apexInfo.IsForPlatform() {
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
j.Stem()+".jar", dexOutputFile) j.Stem()+".jar", dexOutputFile)
} }

View File

@ -451,11 +451,14 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
return return
} }
if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() && apex.IsForPlatform() { if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() {
apexInfo := ctx.ModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
if apexInfo.IsForPlatform() {
// There are stray platform variants of modules in apexes that are not available for // There are stray platform variants of modules in apexes that are not available for
// the platform, and they sometimes can't be built. Don't depend on them. // the platform, and they sometimes can't be built. Don't depend on them.
return return
} }
}
if l, ok := m.(lintOutputsIntf); ok { if l, ok := m.(lintOutputsIntf); ok {
outputs = append(outputs, l.lintOutputs()) outputs = append(outputs, l.lintOutputs())

View File

@ -1419,22 +1419,14 @@ func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) and
return android.Paths{jarPath.Path()} return android.Paths{jarPath.Path()}
} }
// Get the apex names for module, nil if it is for platform.
func getApexNamesForModule(module android.Module) []string {
if apex, ok := module.(android.ApexModule); ok {
return apex.InApexes()
}
return nil
}
// Check to see if the other module is within the same set of named APEXes as this module. // Check to see if the other module is within the same set of named APEXes as this module.
// //
// If either this or the other module are on the platform then this will return // If either this or the other module are on the platform then this will return
// false. // false.
func withinSameApexesAs(module android.ApexModule, other android.Module) bool { func withinSameApexesAs(ctx android.BaseModuleContext, other android.Module) bool {
names := module.InApexes() apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return len(names) > 0 && reflect.DeepEqual(names, getApexNamesForModule(other)) otherApexInfo := ctx.OtherModuleProvider(other, android.ApexInfoProvider).(android.ApexInfo)
return len(otherApexInfo.InApexes) > 0 && reflect.DeepEqual(apexInfo.InApexes, otherApexInfo.InApexes)
} }
func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
@ -1453,7 +1445,7 @@ func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkS
// Only allow access to the implementation library in the following condition: // Only allow access to the implementation library in the following condition:
// * No sdk_version specified on the referencing module. // * No sdk_version specified on the referencing module.
// * The referencing module is in the same apex as this. // * The referencing module is in the same apex as this.
if sdkVersion.kind == sdkPrivate || withinSameApexesAs(module, ctx.Module()) { if sdkVersion.kind == sdkPrivate || withinSameApexesAs(ctx, module) {
if headerJars { if headerJars {
return module.HeaderJars() return module.HeaderJars()
} else { } else {
@ -1970,7 +1962,7 @@ func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersio
// For consistency with SdkLibrary make the implementation jar available to libraries that // For consistency with SdkLibrary make the implementation jar available to libraries that
// are within the same APEX. // are within the same APEX.
implLibraryModule := module.implLibraryModule implLibraryModule := module.implLibraryModule
if implLibraryModule != nil && withinSameApexesAs(module, ctx.Module()) { if implLibraryModule != nil && withinSameApexesAs(ctx, module) {
if headerJars { if headerJars {
return implLibraryModule.HeaderJars() return implLibraryModule.HeaderJars()
} else { } else {
@ -2066,6 +2058,8 @@ type sdkLibraryXml struct {
outputFilePath android.OutputPath outputFilePath android.OutputPath
installDirPath android.InstallPath installDirPath android.InstallPath
hideApexVariantFromMake bool
} }
type sdkLibraryXmlProperties struct { type sdkLibraryXmlProperties struct {
@ -2123,13 +2117,13 @@ func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleConte
} }
// File path to the runtime implementation library // File path to the runtime implementation library
func (module *sdkLibraryXml) implPath() string { func (module *sdkLibraryXml) implPath(ctx android.ModuleContext) string {
implName := proptools.String(module.properties.Lib_name) implName := proptools.String(module.properties.Lib_name)
if apexName := module.ApexVariationName(); apexName != "" { if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
// TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name. // TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name.
// In most cases, this works fine. But when apex_name is set or override_apex is used // In most cases, this works fine. But when apex_name is set or override_apex is used
// this can be wrong. // this can be wrong.
return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName) return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexInfo.ApexVariationName, implName)
} }
partition := "system" partition := "system"
if module.SocSpecific() { if module.SocSpecific() {
@ -2145,8 +2139,10 @@ func (module *sdkLibraryXml) implPath() string {
} }
func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
module.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
libName := proptools.String(module.properties.Lib_name) libName := proptools.String(module.properties.Lib_name)
xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath()) xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath(ctx))
module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
rule := android.NewRuleBuilder() rule := android.NewRuleBuilder()
@ -2160,7 +2156,7 @@ func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleConte
} }
func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
if !module.IsForPlatform() { if module.hideApexVariantFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{ return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true, Disabled: true,
}} }}