summaryrefslogtreecommitdiff
path: root/android/soongconfig/modules.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2024-01-04 14:47:45 -0800
committer Colin Cross <ccross@android.com> 2024-01-05 09:54:09 -0800
commit3cc3154d33265d956bb1036d1e9a569cf3eb8d4a (patch)
tree211a6495af9f6e1f680b5806d75f3ee8c6cdfd3f /android/soongconfig/modules.go
parentd3f7d1a44c2ea75072197b0e610c07216ba92ae2 (diff)
Remove more bp2build
Bug: 315353489 Test: m blueprint_tests Change-Id: Ib854fe1a448c258fe086691a6e5ed2d98537f5e4
Diffstat (limited to 'android/soongconfig/modules.go')
-rw-r--r--android/soongconfig/modules.go112
1 files changed, 2 insertions, 110 deletions
diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go
index 23c8afa0b..f6b49382c 100644
--- a/android/soongconfig/modules.go
+++ b/android/soongconfig/modules.go
@@ -16,16 +16,12 @@ package soongconfig
import (
"fmt"
+ "github.com/google/blueprint/parser"
+ "github.com/google/blueprint/proptools"
"io"
"reflect"
"sort"
"strings"
- "sync"
-
- "github.com/google/blueprint/parser"
- "github.com/google/blueprint/proptools"
-
- "android/soong/starlark_fmt"
)
const conditionsDefault = "conditions_default"
@@ -236,110 +232,6 @@ type SoongConfigDefinition struct {
variables map[string]soongConfigVariable
}
-// Bp2BuildSoongConfigDefinition keeps a global record of all soong config
-// string vars, bool vars and value vars created by every
-// soong_config_module_type in this build.
-type Bp2BuildSoongConfigDefinitions struct {
- StringVars map[string]map[string]bool
- BoolVars map[string]bool
- ValueVars map[string]bool
-}
-
-var bp2buildSoongConfigVarsLock sync.Mutex
-
-// SoongConfigVariablesForBp2build extracts information from a
-// SoongConfigDefinition that bp2build needs to generate constraint settings and
-// values for, in order to migrate soong_config_module_type usages to Bazel.
-func (defs *Bp2BuildSoongConfigDefinitions) AddVars(mtDef *SoongConfigDefinition) {
- // In bp2build mode, this method is called concurrently in goroutines from
- // loadhooks while parsing soong_config_module_type, so add a mutex to
- // prevent concurrent map writes. See b/207572723
- bp2buildSoongConfigVarsLock.Lock()
- defer bp2buildSoongConfigVarsLock.Unlock()
-
- if defs.StringVars == nil {
- defs.StringVars = make(map[string]map[string]bool)
- }
- if defs.BoolVars == nil {
- defs.BoolVars = make(map[string]bool)
- }
- if defs.ValueVars == nil {
- defs.ValueVars = make(map[string]bool)
- }
- // varCache contains a cache of string variables namespace + property
- // The same variable may be used in multiple module types (for example, if need support
- // for cc_default and java_default), only need to process once
- varCache := map[string]bool{}
-
- for _, moduleType := range mtDef.ModuleTypes {
- for _, v := range moduleType.Variables {
- key := strings.Join([]string{moduleType.ConfigNamespace, v.variableProperty()}, "__")
-
- // The same variable may be used in multiple module types (for example, if need support
- // for cc_default and java_default), only need to process once
- if _, keyInCache := varCache[key]; keyInCache {
- continue
- } else {
- varCache[key] = true
- }
-
- if strVar, ok := v.(*stringVariable); ok {
- if _, ok := defs.StringVars[key]; !ok {
- defs.StringVars[key] = make(map[string]bool, len(strVar.values))
- }
- for _, value := range strVar.values {
- defs.StringVars[key][value] = true
- }
- } else if _, ok := v.(*boolVariable); ok {
- defs.BoolVars[key] = true
- } else if _, ok := v.(*valueVariable); ok {
- defs.ValueVars[key] = true
- } else {
- panic(fmt.Errorf("Unsupported variable type: %+v", v))
- }
- }
- }
-}
-
-// This is a copy of the one available in soong/android/util.go, but depending
-// on the android package causes a cyclic dependency. A refactoring here is to
-// extract common utils out from android/utils.go for other packages like this.
-func sortedStringKeys(m interface{}) []string {
- v := reflect.ValueOf(m)
- if v.Kind() != reflect.Map {
- panic(fmt.Sprintf("%#v is not a map", m))
- }
- keys := v.MapKeys()
- s := make([]string, 0, len(keys))
- for _, key := range keys {
- s = append(s, key.String())
- }
- sort.Strings(s)
- return s
-}
-
-// String emits the Soong config variable definitions as Starlark dictionaries.
-func (defs Bp2BuildSoongConfigDefinitions) String() string {
- ret := ""
- ret += "soong_config_bool_variables = "
- ret += starlark_fmt.PrintBoolDict(defs.BoolVars, 0)
- ret += "\n\n"
-
- ret += "soong_config_value_variables = "
- ret += starlark_fmt.PrintBoolDict(defs.ValueVars, 0)
- ret += "\n\n"
-
- stringVars := make(map[string][]string, len(defs.StringVars))
- for k, v := range defs.StringVars {
- stringVars[k] = sortedStringKeys(v)
- }
-
- ret += "soong_config_string_variables = "
- ret += starlark_fmt.PrintStringListDict(stringVars, 0)
-
- return ret
-}
-
// CreateProperties returns a reflect.Value of a newly constructed type that contains the desired
// property layout for the Soong config variables, with each possible value an interface{} that
// contains a nil pointer to another newly constructed type that contains the affectable properties.