Remove more bp2build
Bug: 315353489
Test: m blueprint_tests
Change-Id: Ib854fe1a448c258fe086691a6e5ed2d98537f5e4
diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go
index 23c8afa..f6b4938 100644
--- a/android/soongconfig/modules.go
+++ b/android/soongconfig/modules.go
@@ -16,16 +16,12 @@
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 @@
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.
diff --git a/android/soongconfig/modules_test.go b/android/soongconfig/modules_test.go
index a5fa349..00e8b78 100644
--- a/android/soongconfig/modules_test.go
+++ b/android/soongconfig/modules_test.go
@@ -413,220 +413,3 @@
t.Fatalf("Error message was not correct, expected %q, got %q", expected, err.Error())
}
}
-
-func Test_Bp2BuildSoongConfigDefinitionsAddVars(t *testing.T) {
- testCases := []struct {
- desc string
- defs []*SoongConfigDefinition
- expected Bp2BuildSoongConfigDefinitions
- }{
- {
- desc: "non-overlapping",
- defs: []*SoongConfigDefinition{
- &SoongConfigDefinition{
- ModuleTypes: map[string]*ModuleType{
- "a": &ModuleType{
- ConfigNamespace: "foo",
- Variables: []soongConfigVariable{
- &stringVariable{
- baseVariable: baseVariable{"string_var"},
- values: []string{"a", "b", "c"},
- },
- },
- },
- },
- },
- &SoongConfigDefinition{
- ModuleTypes: map[string]*ModuleType{
- "b": &ModuleType{
- ConfigNamespace: "foo",
- Variables: []soongConfigVariable{
- &stringVariable{
- baseVariable: baseVariable{"string_var"},
- values: []string{"a", "b", "c"},
- },
- &boolVariable{baseVariable: baseVariable{"bool_var"}},
- &valueVariable{baseVariable: baseVariable{"variable_var"}},
- },
- },
- },
- },
- },
- expected: Bp2BuildSoongConfigDefinitions{
- StringVars: map[string]map[string]bool{
- "foo__string_var": map[string]bool{"a": true, "b": true, "c": true},
- },
- BoolVars: map[string]bool{"foo__bool_var": true},
- ValueVars: map[string]bool{"foo__variable_var": true},
- },
- },
- {
- desc: "overlapping",
- defs: []*SoongConfigDefinition{
- &SoongConfigDefinition{
- ModuleTypes: map[string]*ModuleType{
- "a": &ModuleType{
- ConfigNamespace: "foo",
- Variables: []soongConfigVariable{
- &stringVariable{
- baseVariable: baseVariable{"string_var"},
- values: []string{"a", "b", "c"},
- },
- },
- },
- },
- },
- &SoongConfigDefinition{
- ModuleTypes: map[string]*ModuleType{
- "b": &ModuleType{
- ConfigNamespace: "foo",
- Variables: []soongConfigVariable{
- &stringVariable{
- baseVariable: baseVariable{"string_var"},
- values: []string{"b", "c", "d"},
- },
- &boolVariable{baseVariable: baseVariable{"bool_var"}},
- &valueVariable{baseVariable: baseVariable{"variable_var"}},
- },
- },
- },
- },
- },
- expected: Bp2BuildSoongConfigDefinitions{
- StringVars: map[string]map[string]bool{
- "foo__string_var": map[string]bool{"a": true, "b": true, "c": true, "d": true},
- },
- BoolVars: map[string]bool{"foo__bool_var": true},
- ValueVars: map[string]bool{"foo__variable_var": true},
- },
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- actual := &Bp2BuildSoongConfigDefinitions{}
- for _, d := range tc.defs {
- func(def *SoongConfigDefinition) {
- actual.AddVars(def)
- }(d)
- }
- if !reflect.DeepEqual(*actual, tc.expected) {
- t.Errorf("Expected %#v, got %#v", tc.expected, *actual)
- }
- })
- }
-
-}
-
-func Test_Bp2BuildSoongConfigDefinitions(t *testing.T) {
- testCases := []struct {
- desc string
- defs Bp2BuildSoongConfigDefinitions
- expected string
- }{
- {
- desc: "all empty",
- defs: Bp2BuildSoongConfigDefinitions{},
- expected: `soong_config_bool_variables = {}
-
-soong_config_value_variables = {}
-
-soong_config_string_variables = {}`}, {
- desc: "only bool",
- defs: Bp2BuildSoongConfigDefinitions{
- BoolVars: map[string]bool{
- "bool_var": true,
- },
- },
- expected: `soong_config_bool_variables = {
- "bool_var": True,
-}
-
-soong_config_value_variables = {}
-
-soong_config_string_variables = {}`}, {
- desc: "only value vars",
- defs: Bp2BuildSoongConfigDefinitions{
- ValueVars: map[string]bool{
- "value_var": true,
- },
- },
- expected: `soong_config_bool_variables = {}
-
-soong_config_value_variables = {
- "value_var": True,
-}
-
-soong_config_string_variables = {}`}, {
- desc: "only string vars",
- defs: Bp2BuildSoongConfigDefinitions{
- StringVars: map[string]map[string]bool{
- "string_var": map[string]bool{
- "choice1": true,
- "choice2": true,
- "choice3": true,
- },
- },
- },
- expected: `soong_config_bool_variables = {}
-
-soong_config_value_variables = {}
-
-soong_config_string_variables = {
- "string_var": [
- "choice1",
- "choice2",
- "choice3",
- ],
-}`}, {
- desc: "all vars",
- defs: Bp2BuildSoongConfigDefinitions{
- BoolVars: map[string]bool{
- "bool_var_one": true,
- },
- ValueVars: map[string]bool{
- "value_var_one": true,
- "value_var_two": true,
- },
- StringVars: map[string]map[string]bool{
- "string_var_one": map[string]bool{
- "choice1": true,
- "choice2": true,
- "choice3": true,
- },
- "string_var_two": map[string]bool{
- "foo": true,
- "bar": true,
- },
- },
- },
- expected: `soong_config_bool_variables = {
- "bool_var_one": True,
-}
-
-soong_config_value_variables = {
- "value_var_one": True,
- "value_var_two": True,
-}
-
-soong_config_string_variables = {
- "string_var_one": [
- "choice1",
- "choice2",
- "choice3",
- ],
- "string_var_two": [
- "bar",
- "foo",
- ],
-}`},
- }
- for _, test := range testCases {
- t.Run(test.desc, func(t *testing.T) {
- actual := test.defs.String()
- if actual != test.expected {
- t.Errorf("Expected:\n%s\nbut got:\n%s", test.expected, actual)
- }
- })
- }
-}