diff options
Diffstat (limited to 'android/apex.go')
| -rw-r--r-- | android/apex.go | 91 |
1 files changed, 57 insertions, 34 deletions
diff --git a/android/apex.go b/android/apex.go index 9195388bf..43a42df9b 100644 --- a/android/apex.go +++ b/android/apex.go @@ -19,6 +19,14 @@ import ( "sync" ) +type ApexInfo struct { + // Name of the apex variant that this module is mutated into + ApexName string + + // Whether this apex variant needs to target Android 10 + LegacyAndroid10Support bool +} + // ApexModule is the interface that a module type is expected to implement if // the module has to be built differently depending on whether the module // is destined for an apex or not (installed to one of the regular partitions). @@ -38,9 +46,12 @@ type ApexModule interface { Module apexModuleBase() *ApexModuleBase - // Marks that this module should be built for the APEX of the specified name. + // Marks that this module should be built for the specified APEXes. // Call this before apex.apexMutator is run. - BuildForApex(apexName string) + BuildForApexes(apexes []ApexInfo) + + // Returns the APEXes that this module will be built for + ApexVariations() []ApexInfo // Returns the name of APEX that this module will be built for. Empty string // is returned when 'IsForPlatform() == true'. Note that a module can be @@ -66,13 +77,9 @@ type ApexModule interface { IsInstallableToApex() bool // Mutate this module into one or more variants each of which is built - // for an APEX marked via BuildForApex(). + // for an APEX marked via BuildForApexes(). CreateApexVariations(mctx BottomUpMutatorContext) []Module - // Sets the name of the apex variant of this module. Called inside - // CreateApexVariations. - setApexName(apexName string) - // Tests if this module is available for the specified APEX or ":platform" AvailableFor(what string) bool @@ -88,12 +95,10 @@ type ApexProperties struct { // // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX. // "//apex_available:platform" refers to non-APEX partitions like "system.img". - // Default is ["//apex_available:platform", "//apex_available:anyapex"]. - // TODO(b/128708192) change the default to ["//apex_available:platform"] + // Default is ["//apex_available:platform"]. Apex_available []string - // Name of the apex variant that this module is mutated into - ApexName string `blueprint:"mutated"` + Info ApexInfo `blueprint:"mutated"` } // Provides default implementation for the ApexModule interface. APEX-aware @@ -104,31 +109,37 @@ type ApexModuleBase struct { canHaveApexVariants bool apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator - apexVariations []string + apexVariations []ApexInfo } func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase { return m } -func (m *ApexModuleBase) BuildForApex(apexName string) { +func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) { m.apexVariationsLock.Lock() defer m.apexVariationsLock.Unlock() - if !InList(apexName, m.apexVariations) { - m.apexVariations = append(m.apexVariations, apexName) +nextApex: + for _, apex := range apexes { + for _, v := range m.apexVariations { + if v.ApexName == apex.ApexName { + continue nextApex + } + } + m.apexVariations = append(m.apexVariations, apex) } } -func (m *ApexModuleBase) ApexName() string { - return m.ApexProperties.ApexName +func (m *ApexModuleBase) ApexVariations() []ApexInfo { + return m.apexVariations } -func (m *ApexModuleBase) IsForPlatform() bool { - return m.ApexProperties.ApexName == "" +func (m *ApexModuleBase) ApexName() string { + return m.ApexProperties.Info.ApexName } -func (m *ApexModuleBase) setApexName(apexName string) { - m.ApexProperties.ApexName = apexName +func (m *ApexModuleBase) IsForPlatform() bool { + return m.ApexProperties.Info.ApexName == "" } func (m *ApexModuleBase) CanHaveApexVariants() bool { @@ -177,25 +188,35 @@ func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) { } } +type byApexName []ApexInfo + +func (a byApexName) Len() int { return len(a) } +func (a byApexName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a byApexName) Less(i, j int) bool { return a[i].ApexName < a[j].ApexName } + func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module { if len(m.apexVariations) > 0 { m.checkApexAvailableProperty(mctx) - sort.Strings(m.apexVariations) + sort.Sort(byApexName(m.apexVariations)) variations := []string{} variations = append(variations, "") // Original variation for platform - variations = append(variations, m.apexVariations...) + for _, apex := range m.apexVariations { + variations = append(variations, apex.ApexName) + } defaultVariation := "" mctx.SetDefaultDependencyVariation(&defaultVariation) modules := mctx.CreateVariations(variations...) - for i, m := range modules { + for i, mod := range modules { platformVariation := i == 0 - if platformVariation && !mctx.Host() && !m.(ApexModule).AvailableFor(AvailableToPlatform) { - m.SkipInstall() + if platformVariation && !mctx.Host() && !mod.(ApexModule).AvailableFor(AvailableToPlatform) { + mod.SkipInstall() + } + if !platformVariation { + mod.(ApexModule).apexModuleBase().ApexProperties.Info = m.apexVariations[i-1] } - m.(ApexModule).setApexName(variations[i]) } return modules } @@ -219,18 +240,20 @@ func apexNamesMap() map[string]map[string]bool { } // Update the map to mark that a module named moduleName is directly or indirectly -// depended on by an APEX named apexName. Directly depending means that a module +// 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(apexName string, moduleName string, directDep bool) { +func UpdateApexDependency(apexes []ApexInfo, moduleName string, directDep bool) { apexNamesMapMutex.Lock() defer apexNamesMapMutex.Unlock() - apexNames, ok := apexNamesMap()[moduleName] - if !ok { - apexNames = make(map[string]bool) - apexNamesMap()[moduleName] = apexNames + for _, apex := range apexes { + apexesForModule, ok := apexNamesMap()[moduleName] + if !ok { + apexesForModule = make(map[string]bool) + apexNamesMap()[moduleName] = apexesForModule + } + apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep } - apexNames[apexName] = apexNames[apexName] || directDep } // TODO(b/146393795): remove this when b/146393795 is fixed |