56866c5c6d
Partner worksapces contain two versions of mainline prebuilts - BigAndroid and Go. These two prebuilts export dexpreopt'd system server artifacts to be installed in system image. Since the install paths are same, we run into duplicate installation rules issue unless one of them is hidden. This hiding was previously done by creating a dependendency between source aosp apex to BA and Go google prebuilts. However, this implementaion had the unfortunate side effect on the packaging name of the Google mainline prebuilts - the name becomes the aosp apex name. Instead of creating the dependency to aosp apex, this CL hides all mainline apex_set(s) if it has not been flagged using RELEASE_APEX_CONTRIBUTIONS_*. Since there are some non mainline apex prebuilts, apex_name will be used to determine whether the prebuilt is a mainline module. Test: m nothing --no-skip-soong-tests Test: In partner workspaces, downloaded the CLs in b/355682304#comment7 Test: m out/target/product/generic/obj/PACKAGING/system_intermediates/file_list.txt verified that aosp apexes are not installed, but mainline prebuilts are installed Test: unset RELEASE_APEX_CONTRIBUTIONS_ADSERVICES to build from source Test: m out/target/product/generic/obj/PACKAGING/system_intermediates/file_list.txt verified that aosp adservices is installed, and adservices prebuilt is **not* installed. Bug: 355682304 (cherry picked from https://android-review.googlesource.com/q/commit:85bd4625edc95c6e030acf4b4289724ff39e1d6e) Merged-In: Idacb65313553bdea5c0593976694de478034229e Change-Id: Idacb65313553bdea5c0593976694de478034229e
197 lines
6.5 KiB
Go
197 lines
6.5 KiB
Go
// Copyright 2023 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package android
|
|
|
|
import (
|
|
"github.com/google/blueprint"
|
|
"github.com/google/blueprint/proptools"
|
|
)
|
|
|
|
func init() {
|
|
RegisterApexContributionsBuildComponents(InitRegistrationContext)
|
|
}
|
|
|
|
func RegisterApexContributionsBuildComponents(ctx RegistrationContext) {
|
|
ctx.RegisterModuleType("apex_contributions", apexContributionsFactory)
|
|
ctx.RegisterModuleType("apex_contributions_defaults", apexContributionsDefaultsFactory)
|
|
ctx.RegisterSingletonModuleType("all_apex_contributions", allApexContributionsFactory)
|
|
}
|
|
|
|
type apexContributions struct {
|
|
ModuleBase
|
|
DefaultableModuleBase
|
|
properties contributionProps
|
|
}
|
|
|
|
type contributionProps struct {
|
|
// Name of the mainline module
|
|
Api_domain *string
|
|
// A list of module names that should be used when this contribution
|
|
// is selected via product_config
|
|
// The name should be explicit (foo or prebuilt_foo)
|
|
Contents []string
|
|
}
|
|
|
|
func (m *apexContributions) ApiDomain() string {
|
|
return proptools.String(m.properties.Api_domain)
|
|
}
|
|
|
|
func (m *apexContributions) Contents() []string {
|
|
return m.properties.Contents
|
|
}
|
|
|
|
// apex_contributions contains a list of module names (source or
|
|
// prebuilt) belonging to the mainline module
|
|
// An apex can have multiple apex_contributions modules
|
|
// with different combinations of source or prebuilts, but only one can be
|
|
// selected via product_config.
|
|
func apexContributionsFactory() Module {
|
|
module := &apexContributions{}
|
|
module.AddProperties(&module.properties)
|
|
InitAndroidModule(module)
|
|
InitDefaultableModule(module)
|
|
return module
|
|
}
|
|
|
|
// This module type does not have any build actions.
|
|
// It provides metadata that is used in post-deps mutator phase for source vs
|
|
// prebuilts selection.
|
|
func (m *apexContributions) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|
}
|
|
|
|
type apexContributionsDefaults struct {
|
|
ModuleBase
|
|
DefaultsModuleBase
|
|
}
|
|
|
|
func apexContributionsDefaultsFactory() Module {
|
|
module := &apexContributionsDefaults{}
|
|
module.AddProperties(&contributionProps{})
|
|
InitDefaultsModule(module)
|
|
return module
|
|
}
|
|
|
|
// A container for apex_contributions.
|
|
// Based on product_config, it will create a dependency on the selected
|
|
// apex_contributions per mainline module
|
|
type allApexContributions struct {
|
|
SingletonModuleBase
|
|
}
|
|
|
|
func allApexContributionsFactory() SingletonModule {
|
|
module := &allApexContributions{}
|
|
InitAndroidModule(module)
|
|
return module
|
|
}
|
|
|
|
type apexContributionsDepTag struct {
|
|
blueprint.BaseDependencyTag
|
|
}
|
|
|
|
var (
|
|
AcDepTag = apexContributionsDepTag{}
|
|
)
|
|
|
|
// Creates a dep to each selected apex_contributions
|
|
func (a *allApexContributions) DepsMutator(ctx BottomUpMutatorContext) {
|
|
// Skip apex_contributions if BuildApexContributionContents is true
|
|
// This product config var allows some products in the same family to use mainline modules from source
|
|
// (e.g. shiba and shiba_fullmte)
|
|
// Eventually these product variants will have their own release config maps.
|
|
if !proptools.Bool(ctx.Config().BuildIgnoreApexContributionContents()) {
|
|
ctx.AddDependency(ctx.Module(), AcDepTag, ctx.Config().AllApexContributions()...)
|
|
}
|
|
}
|
|
|
|
// Set PrebuiltSelectionInfoProvider in post deps phase
|
|
func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BaseModuleContext) {
|
|
addContentsToProvider := func(p *PrebuiltSelectionInfoMap, m *apexContributions) {
|
|
for _, content := range m.Contents() {
|
|
// Verify that the module listed in contents exists in the tree
|
|
// Remove the prebuilt_ prefix to account for partner worksapces where the source module does not
|
|
// exist, and PrebuiltRenameMutator renames `prebuilt_foo` to `foo`
|
|
if !ctx.OtherModuleExists(content) && !ctx.OtherModuleExists(RemoveOptionalPrebuiltPrefix(content)) && !ctx.Config().AllowMissingDependencies() {
|
|
ctx.ModuleErrorf("%s listed in apex_contributions %s does not exist\n", content, m.Name())
|
|
}
|
|
pi := &PrebuiltSelectionInfo{
|
|
selectedModuleName: content,
|
|
metadataModuleName: m.Name(),
|
|
apiDomain: m.ApiDomain(),
|
|
}
|
|
p.Add(ctx, pi)
|
|
}
|
|
}
|
|
|
|
p := PrebuiltSelectionInfoMap{}
|
|
ctx.VisitDirectDepsWithTag(AcDepTag, func(child Module) {
|
|
if m, ok := child.(*apexContributions); ok {
|
|
addContentsToProvider(&p, m)
|
|
} else {
|
|
ctx.ModuleErrorf("%s is not an apex_contributions module\n", child.Name())
|
|
}
|
|
})
|
|
SetProvider(ctx, PrebuiltSelectionInfoProvider, p)
|
|
}
|
|
|
|
// A provider containing metadata about whether source or prebuilt should be used
|
|
// This provider will be used in prebuilt_select mutator to redirect deps
|
|
var PrebuiltSelectionInfoProvider = blueprint.NewMutatorProvider[PrebuiltSelectionInfoMap]("prebuilt_select")
|
|
|
|
// Map of selected module names to a metadata object
|
|
// The metadata contains information about the api_domain of the selected module
|
|
type PrebuiltSelectionInfoMap map[string]PrebuiltSelectionInfo
|
|
|
|
// Add a new entry to the map with some validations
|
|
func (pm *PrebuiltSelectionInfoMap) Add(ctx BaseModuleContext, p *PrebuiltSelectionInfo) {
|
|
if p == nil {
|
|
return
|
|
}
|
|
(*pm)[p.selectedModuleName] = *p
|
|
}
|
|
|
|
type PrebuiltSelectionInfo struct {
|
|
// e.g. (libc|prebuilt_libc)
|
|
selectedModuleName string
|
|
// Name of the apex_contributions module
|
|
metadataModuleName string
|
|
// e.g. com.android.runtime
|
|
apiDomain string
|
|
}
|
|
|
|
// Returns true if `name` is explicitly requested using one of the selected
|
|
// apex_contributions metadata modules.
|
|
func (p *PrebuiltSelectionInfoMap) IsSelected(name string) bool {
|
|
_, exists := (*p)[name]
|
|
return exists
|
|
}
|
|
|
|
// Return the list of soong modules selected for this api domain
|
|
// In the case of apexes, it is the canonical name of the apex on device (/apex/<apex_name>)
|
|
func (p *PrebuiltSelectionInfoMap) GetSelectedModulesForApiDomain(apiDomain string) []string {
|
|
selected := []string{}
|
|
for _, entry := range *p {
|
|
if entry.apiDomain == apiDomain {
|
|
selected = append(selected, entry.selectedModuleName)
|
|
}
|
|
}
|
|
return selected
|
|
}
|
|
|
|
// This module type does not have any build actions.
|
|
func (a *allApexContributions) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|
}
|
|
|
|
func (a *allApexContributions) GenerateSingletonBuildActions(ctx SingletonContext) {
|
|
}
|