Merge "release_config: various cleanup" into main am: 000fe5ac5d am: 4c8f885b84

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

Change-Id: I6fa7afca689c54c2f95e8c65c026da78633a5591
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2024-06-14 01:59:09 +00:00 committed by Automerger Merge Worker
commit 8806166b1d
5 changed files with 88 additions and 90 deletions

View file

@ -88,7 +88,7 @@ func main() {
return
}
// Write the makefile where release_config.mk is going to look for it.
err = configs.WriteMakefile(makefilePath, targetRelease)
err = config.WriteMakefile(makefilePath, targetRelease, configs)
if err != nil {
panic(err)
}
@ -97,7 +97,7 @@ func main() {
for _, c := range configs.GetSortedReleaseConfigs() {
if c.Name != targetRelease {
makefilePath = filepath.Join(outputDir, fmt.Sprintf("release_config-%s-%s.varmk", product, c.Name))
err = configs.WriteMakefile(makefilePath, c.Name)
err = config.WriteMakefile(makefilePath, c.Name, configs)
if err != nil {
panic(err)
}

View file

@ -82,6 +82,15 @@ func FlagArtifactsFactory(artifactsPath string) *FlagArtifacts {
return &ret
}
func (fas *FlagArtifacts) SortedFlagNames() []string {
var names []string
for k, _ := range *fas {
names = append(names, k)
}
slices.Sort(names)
return names
}
func (fa *FlagArtifact) GenerateFlagDeclarationArtifact() *rc_proto.FlagDeclarationArtifact {
ret := &rc_proto.FlagDeclarationArtifact{
Name: fa.FlagDeclaration.Name,

View file

@ -17,6 +17,7 @@ package release_config_lib
import (
"cmp"
"fmt"
"os"
"path/filepath"
"regexp"
"slices"
@ -169,8 +170,12 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro
if err != nil {
return err
}
iConfig.GenerateReleaseConfig(configs)
if err := config.InheritConfig(iConfig); err != nil {
err = iConfig.GenerateReleaseConfig(configs)
if err != nil {
return err
}
err = config.InheritConfig(iConfig)
if err != nil {
return err
}
}
@ -310,6 +315,74 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro
return nil
}
// Write the makefile for this targetRelease.
func (config *ReleaseConfig) WriteMakefile(outFile, targetRelease string, configs *ReleaseConfigs) error {
makeVars := make(map[string]string)
myFlagArtifacts := config.FlagArtifacts.Clone()
// Sort the flags by name first.
names := myFlagArtifacts.SortedFlagNames()
partitions := make(map[string][]string)
vNames := []string{}
addVar := func(name, suffix, value string) {
fullName := fmt.Sprintf("_ALL_RELEASE_FLAGS.%s.%s", name, suffix)
vNames = append(vNames, fullName)
makeVars[fullName] = value
}
for _, name := range names {
flag := myFlagArtifacts[name]
decl := flag.FlagDeclaration
for _, container := range decl.Containers {
partitions[container] = append(partitions[container], name)
}
value := MarshalValue(flag.Value)
makeVars[name] = value
addVar(name, "TYPE", ValueType(flag.Value))
addVar(name, "PARTITIONS", strings.Join(decl.Containers, " "))
addVar(name, "DEFAULT", MarshalValue(decl.Value))
addVar(name, "VALUE", value)
addVar(name, "DECLARED_IN", *flag.Traces[0].Source)
addVar(name, "SET_IN", *flag.Traces[len(flag.Traces)-1].Source)
addVar(name, "NAMESPACE", *decl.Namespace)
}
pNames := []string{}
for k := range partitions {
pNames = append(pNames, k)
}
slices.Sort(pNames)
// Now sort the make variables, and output them.
slices.Sort(vNames)
// Write the flags as:
// _ALL_RELELASE_FLAGS
// _ALL_RELEASE_FLAGS.PARTITIONS.*
// all _ALL_RELEASE_FLAGS.*, sorted by name
// Final flag values, sorted by name.
data := fmt.Sprintf("# TARGET_RELEASE=%s\n", config.Name)
if targetRelease != config.Name {
data += fmt.Sprintf("# User specified TARGET_RELEASE=%s\n", targetRelease)
}
// As it stands this list is not per-product, but conceptually it is, and will be.
data += fmt.Sprintf("ALL_RELEASE_CONFIGS_FOR_PRODUCT :=$= %s\n", strings.Join(configs.GetAllReleaseNames(), " "))
data += fmt.Sprintf("_used_files := %s\n", strings.Join(config.GetSortedFileList(), " "))
data += fmt.Sprintf("_ALL_RELEASE_FLAGS :=$= %s\n", strings.Join(names, " "))
for _, pName := range pNames {
data += fmt.Sprintf("_ALL_RELEASE_FLAGS.PARTITIONS.%s :=$= %s\n", pName, strings.Join(partitions[pName], " "))
}
for _, vName := range vNames {
data += fmt.Sprintf("%s :=$= %s\n", vName, makeVars[vName])
}
data += "\n\n# Values for all build flags\n"
for _, name := range names {
data += fmt.Sprintf("%s :=$= %s\n", name, makeVars[name])
}
return os.WriteFile(outFile, []byte(data), 0644)
}
func (config *ReleaseConfig) WritePartitionBuildFlags(outDir string) error {
var err error
for partition, flags := range config.PartitionBuildFlags {

View file

@ -395,94 +395,10 @@ func (configs *ReleaseConfigs) GetAllReleaseNames() []string {
allReleaseNames = append(allReleaseNames, v.Name)
allReleaseNames = append(allReleaseNames, v.OtherNames...)
}
slices.SortFunc(allReleaseNames, func(a, b string) int {
return cmp.Compare(a, b)
})
slices.Sort(allReleaseNames)
return allReleaseNames
}
// Write the makefile for this targetRelease.
func (configs *ReleaseConfigs) WriteMakefile(outFile, targetRelease string) error {
makeVars := make(map[string]string)
config, err := configs.GetReleaseConfig(targetRelease)
if err != nil {
return err
}
myFlagArtifacts := config.FlagArtifacts.Clone()
// Sort the flags by name first.
names := []string{}
for k, _ := range myFlagArtifacts {
names = append(names, k)
}
slices.SortFunc(names, func(a, b string) int {
return cmp.Compare(a, b)
})
partitions := make(map[string][]string)
vNames := []string{}
addVar := func(name, suffix, value string) {
fullName := fmt.Sprintf("_ALL_RELEASE_FLAGS.%s.%s", name, suffix)
vNames = append(vNames, fullName)
makeVars[fullName] = value
}
for _, name := range names {
flag := myFlagArtifacts[name]
decl := flag.FlagDeclaration
for _, container := range decl.Containers {
partitions[container] = append(partitions[container], name)
}
value := MarshalValue(flag.Value)
makeVars[name] = value
addVar(name, "TYPE", ValueType(flag.Value))
addVar(name, "PARTITIONS", strings.Join(decl.Containers, " "))
addVar(name, "DEFAULT", MarshalValue(decl.Value))
addVar(name, "VALUE", value)
addVar(name, "DECLARED_IN", *flag.Traces[0].Source)
addVar(name, "SET_IN", *flag.Traces[len(flag.Traces)-1].Source)
addVar(name, "NAMESPACE", *decl.Namespace)
}
pNames := []string{}
for k := range partitions {
pNames = append(pNames, k)
}
slices.SortFunc(pNames, func(a, b string) int {
return cmp.Compare(a, b)
})
// Now sort the make variables, and output them.
slices.SortFunc(vNames, func(a, b string) int {
return cmp.Compare(a, b)
})
// Write the flags as:
// _ALL_RELELASE_FLAGS
// _ALL_RELEASE_FLAGS.PARTITIONS.*
// all _ALL_RELEASE_FLAGS.*, sorted by name
// Final flag values, sorted by name.
data := fmt.Sprintf("# TARGET_RELEASE=%s\n", config.Name)
if targetRelease != config.Name {
data += fmt.Sprintf("# User specified TARGET_RELEASE=%s\n", targetRelease)
}
// As it stands this list is not per-product, but conceptually it is, and will be.
data += fmt.Sprintf("ALL_RELEASE_CONFIGS_FOR_PRODUCT :=$= %s\n", strings.Join(configs.GetAllReleaseNames(), " "))
data += fmt.Sprintf("_used_files := %s\n", strings.Join(config.GetSortedFileList(), " "))
data += fmt.Sprintf("_ALL_RELEASE_FLAGS :=$= %s\n", strings.Join(names, " "))
for _, pName := range pNames {
data += fmt.Sprintf("_ALL_RELEASE_FLAGS.PARTITIONS.%s :=$= %s\n", pName, strings.Join(partitions[pName], " "))
}
for _, vName := range vNames {
data += fmt.Sprintf("%s :=$= %s\n", vName, makeVars[vName])
}
data += "\n\n# Values for all build flags\n"
for _, name := range names {
data += fmt.Sprintf("%s :=$= %s\n", name, makeVars[name])
}
return os.WriteFile(outFile, []byte(data), 0644)
}
func (configs *ReleaseConfigs) GenerateReleaseConfigs(targetRelease string) error {
otherNames := make(map[string][]string)
for aliasName, aliasTarget := range configs.Aliases {

View file

@ -2544,7 +2544,7 @@ func collectDirectDepsProviders(ctx android.ModuleContext) (result *JarJarProvid
case Implementation:
return RenameUseInclude, "info"
default:
//fmt.Printf("LJ: %v -> %v StubsLinkType unknown\n", module, m)
//fmt.Printf("collectDirectDepsProviders: %v -> %v StubsLinkType unknown\n", module, m)
// Fall through to the heuristic logic.
}
switch reflect.TypeOf(m).String() {