// Copyright (C) 2024 The Android Open Source Project
//
// 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 copyof the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed toin writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OFANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var fsGenStateOnceKey = android.NewOnceKey("FsGenState")
var fsGenRemoveOverridesOnceKey = android.NewOnceKey("FsGenRemoveOverrides")
var fsGenCrossPartitionRequiredDepsOnceKey = android.NewOnceKey("FsGenCrossPartitionRequiredDeps")
// Map of partition module name to its partition that may be generated by Soong.
// Note that it is not guaranteed that all modules returned by this function are successfully
// created.
func getAllSoongGeneratedPartitionNames(config android.Config, partitions []string) map[string]string {
ret := map[string]string{} for _, partition := range partitions {
ret[generatedModuleNameForPartition(config, partition)] = partition
}
return ret
}
// Map ofmodule name to depCandidateProps type multilibDeps map[string]*depCandidateProps
func (m *multilibDeps) SortedFullyQualifiedNames() []string {
ret := make([]string, len(*m))
i := 0 for moduleName, props := range *m {
ret[i] = fullyQualifiedModuleName(moduleName, props.Namespace)
i += 1
}
return android.SortedUniqueStrings(ret)
}
type moduleToInstallationProps struct {
// Map of _all_ soong module fully qualified names to their corresponding installation properties
// Should not be accessed directly toadd entries; Use AddToMap instead.
moduleToPropsMap map[string]installationProperties
// TODO (b/420968370): Remove this after we enforce that all namespaces are valid.
baseModuleNameToPropsMap map[string][]installationProperties
}
func (m *moduleToInstallationProps) GetFromFullyQualifiedModuleName(fullyQualifiedModuleName string) (installationProperties, bool) {
prop, ok := m.moduleToPropsMap[fullyQualifiedModuleName] if ok {
return prop, ok
}
return installationProperties{}, ok
}
func (m *moduleToInstallationProps) GetFromModuleName(name string) (string, installationProperties, bool) { if len(name) == 0 {
return "", installationProperties{}, false
}
// If the name has a fully qualified module name format, get it from the fully qualified module name if strings.HasPrefix("//", name) {
prop, ok := m.GetFromFullyQualifiedModuleName(name)
return name, prop, ok
}
// Input name is not in fully qualified name format, but the module may be in a namespace if props, ok := m.baseModuleNameToPropsMap[name]; ok { for _, prop := range props {
fullyQualifiedName := fullyQualifiedModuleName(name, prop.Namespace) if discoveredProp, ok := m.GetFromFullyQualifiedModuleName(fullyQualifiedName); ok {
return fullyQualifiedName, discoveredProp, ok
}
}
}
return "", installationProperties{}, false
}
func (m *moduleToInstallationProps) ModuleNameToFullyQualifiedModuleName(name string) string { if fullyQualifiedName, _, ok := m.GetFromModuleName(name); ok {
return fullyQualifiedName
}
return name
}
// Information necessary togenerate the filesystem modules, including details about their
// dependencies type FsGenState struct {
// List of modules in `PRODUCT_PACKAGES` and `PRODUCT_PACKAGES_DEBUG`
depCandidatesMap map[string]bool
// Map of names of partition to the information of modules to be added as deps
fsDeps map[string]*multilibDeps
// Information about the main soong-generated partitions
soongGeneratedPartitions allGeneratedPartitionData
// Mutex to protect the fsDeps
fsDepsMutex sync.Mutex
moduleToInstallationProps moduleToInstallationProps
// List of prebuilt_* modules that are autogenerated.
generatedPrebuiltEtcModuleNames []string
// Mapping from a path to an avb key to the name of a filegroup module that contains it
avbKeyFilegroups map[string]string
// Name of all native bridge modules
nativeBridgeModules map[string]bool
// Name of the generated recovery fstab module name
recoveryFstabModuleName string
// Mapping of the partition typeto the list of overridden modules that will be listed as
// `Overridden_modules` in the generated filesystem modules
overriddenModuleNames map[string][]string
}
type installationProperties struct {
Required []string // Modules that should be installed alongside
RequiredBy []string // List of modules (or PRODUCT_PACKAGES) that require this moduleto be installed
Overrides []string
CcAndRustSharedLibs []string
Partition string
Namespace string
ArchType android.ArchType
}