Merge "Remove saveToBazelConfigFile" into main am: ba80e4c16b
am: 2ce7466a03
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3132087 Change-Id: I91a4d8f8017d3a81536619eb436d42427db48918 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
be0f95b374
1 changed files with 1 additions and 79 deletions
|
@ -22,7 +22,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -37,9 +36,7 @@ import (
|
|||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android/soongconfig"
|
||||
"android/soong/bazel"
|
||||
"android/soong/remoteexec"
|
||||
"android/soong/starlark_fmt"
|
||||
)
|
||||
|
||||
// Bool re-exports proptools.Bool for the android package.
|
||||
|
@ -418,7 +415,7 @@ func loadFromConfigFile(configurable *ProductVariables, filename string) error {
|
|||
proptools.StringPtr(String(configurable.Platform_sdk_codename))
|
||||
}
|
||||
|
||||
return saveToBazelConfigFile(configurable, filepath.Dir(filename))
|
||||
return nil
|
||||
}
|
||||
|
||||
// atomically writes the config file in case two copies of soong_build are running simultaneously
|
||||
|
@ -452,81 +449,6 @@ func saveToConfigFile(config *ProductVariables, filename string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type productVariableStarlarkRepresentation struct {
|
||||
soongType string
|
||||
selectable bool
|
||||
archVariant bool
|
||||
}
|
||||
|
||||
func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
|
||||
dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
|
||||
err := createDirIfNonexistent(dir, os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not create dir %s: %s", dir, err)
|
||||
}
|
||||
|
||||
allProductVariablesType := reflect.TypeOf((*ProductVariables)(nil)).Elem()
|
||||
productVariablesInfo := make(map[string]productVariableStarlarkRepresentation)
|
||||
p := variableProperties{}
|
||||
t := reflect.TypeOf(p.Product_variables)
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
archVariant := proptools.HasTag(f, "android", "arch_variant")
|
||||
if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok {
|
||||
productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{
|
||||
soongType: stringRepresentationOfSimpleType(mainProductVariablesStructField.Type),
|
||||
selectable: true,
|
||||
archVariant: archVariant,
|
||||
}
|
||||
} else {
|
||||
panic("Unknown variable " + f.Name)
|
||||
}
|
||||
}
|
||||
|
||||
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
|
||||
# product_var_constant_info is a map of product variables to information about them. The fields are:
|
||||
# - soongType: The type of the product variable as it appears in soong's ProductVariables struct.
|
||||
# examples are string, bool, int, *bool, *string, []string, etc. This may be an overly
|
||||
# conservative estimation of the type, for example a *bool could oftentimes just be a
|
||||
# bool that defaults to false.
|
||||
# - selectable: if this product variable can be selected on in Android.bp/build files. This means
|
||||
# it's listed in the "variableProperties" soong struct. Currently all variables in
|
||||
# this list are selectable because we only need the selectable ones at the moment,
|
||||
# but the list may be expanded later.
|
||||
# - archVariant: If the variable is tagged as arch variant in the "variableProperties" struct.
|
||||
product_var_constant_info = %s
|
||||
product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable]
|
||||
arch_variant_product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable and v.archVariant]
|
||||
`, starlark_fmt.PrintAny(productVariablesInfo, 0))), 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not write .bzl config file %s", err)
|
||||
}
|
||||
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"),
|
||||
[]byte(bazel.GeneratedBazelFileWarning), 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not write BUILD config file %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func stringRepresentationOfSimpleType(ty reflect.Type) string {
|
||||
switch ty.Kind() {
|
||||
case reflect.String:
|
||||
return "string"
|
||||
case reflect.Bool:
|
||||
return "bool"
|
||||
case reflect.Int:
|
||||
return "int"
|
||||
case reflect.Slice:
|
||||
return "[]" + stringRepresentationOfSimpleType(ty.Elem())
|
||||
case reflect.Pointer:
|
||||
return "*" + stringRepresentationOfSimpleType(ty.Elem())
|
||||
default:
|
||||
panic("unimplemented type: " + ty.Kind().String())
|
||||
}
|
||||
}
|
||||
|
||||
// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
|
||||
// use the android package.
|
||||
func NullConfig(outDir, soongOutDir string) Config {
|
||||
|
|
Loading…
Reference in a new issue