Merge "Add CFI product config variables to platform_mappings" into main
This commit is contained in:
@@ -18,7 +18,6 @@ package android
|
|||||||
// product variables necessary for soong_build's operation.
|
// product variables necessary for soong_build's operation.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -431,32 +430,6 @@ func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
|
|||||||
return fmt.Errorf("cannot marshal arch variant product variable data: %s", err.Error())
|
return fmt.Errorf("cannot marshal arch variant product variable data: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
configJson, err := json.MarshalIndent(&config, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot marshal config data: %s", err.Error())
|
|
||||||
}
|
|
||||||
// The backslashes need to be escaped because this text is going to be put
|
|
||||||
// inside a Starlark string literal.
|
|
||||||
configJson = bytes.ReplaceAll(configJson, []byte("\\"), []byte("\\\\"))
|
|
||||||
|
|
||||||
bzl := []string{
|
|
||||||
bazel.GeneratedBazelFileWarning,
|
|
||||||
fmt.Sprintf(`_product_vars = json.decode("""%s""")`, configJson),
|
|
||||||
fmt.Sprintf(`_product_var_constraints = %s`, nonArchVariantProductVariablesJson),
|
|
||||||
fmt.Sprintf(`_arch_variant_product_var_constraints = %s`, archVariantProductVariablesJson),
|
|
||||||
"\n", `
|
|
||||||
product_vars = _product_vars
|
|
||||||
|
|
||||||
# TODO(b/269577299) Remove these when everything switches over to loading them from product_variable_constants.bzl
|
|
||||||
product_var_constraints = _product_var_constraints
|
|
||||||
arch_variant_product_var_constraints = _arch_variant_product_var_constraints
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variables.bzl"),
|
|
||||||
[]byte(strings.Join(bzl, "\n")), 0644)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Could not write .bzl config file %s", err)
|
|
||||||
}
|
|
||||||
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
|
err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(`
|
||||||
product_var_constraints = %s
|
product_var_constraints = %s
|
||||||
arch_variant_product_var_constraints = %s
|
arch_variant_product_var_constraints = %s
|
||||||
|
@@ -163,12 +163,29 @@ func platformMappingContent(mainProductLabel string, mainProductVariables *andro
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bazelPlatformSuffixes = []string{
|
||||||
|
"",
|
||||||
|
"_darwin_arm64",
|
||||||
|
"_darwin_x86_64",
|
||||||
|
"_linux_bionic_arm64",
|
||||||
|
"_linux_bionic_x86_64",
|
||||||
|
"_linux_musl_x86",
|
||||||
|
"_linux_musl_x86_64",
|
||||||
|
"_linux_x86",
|
||||||
|
"_linux_x86_64",
|
||||||
|
"_windows_x86",
|
||||||
|
"_windows_x86_64",
|
||||||
|
}
|
||||||
|
|
||||||
func platformMappingSingleProduct(label string, productVariables *android.ProductVariables) string {
|
func platformMappingSingleProduct(label string, productVariables *android.ProductVariables) string {
|
||||||
buildSettings := ""
|
buildSettings := ""
|
||||||
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride))
|
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride))
|
||||||
|
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ","))
|
||||||
|
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ","))
|
||||||
|
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true))
|
||||||
result := ""
|
result := ""
|
||||||
for _, extension := range []string{"", "_linux_x86_64", "_linux_bionic_x86_64", "_linux_musl_x86", "_linux_musl_x86_64"} {
|
for _, suffix := range bazelPlatformSuffixes {
|
||||||
result += " " + label + extension + "\n" + buildSettings
|
result += " " + label + suffix + "\n" + buildSettings
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -176,7 +193,19 @@ func platformMappingSingleProduct(label string, productVariables *android.Produc
|
|||||||
func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
|
func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
|
||||||
var err error
|
var err error
|
||||||
result := android.ProductVariables{}
|
result := android.ProductVariables{}
|
||||||
result.ApexGlobalMinSdkVersionOverride, err = starlark_import.NoneableString(in["ApexGlobalMinSdkVersionOverride"])
|
result.ApexGlobalMinSdkVersionOverride, err = starlark_import.UnmarshalNoneable[string](in["ApexGlobalMinSdkVersionOverride"])
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
result.CFIIncludePaths, err = starlark_import.Unmarshal[[]string](in["CFIIncludePaths"])
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
result.CFIExcludePaths, err = starlark_import.Unmarshal[[]string](in["CFIExcludePaths"])
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
result.EnableCFI, err = starlark_import.UnmarshalNoneable[bool](in["EnableCFI"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
@@ -289,16 +289,13 @@ func typeOfStarlarkValue(value starlark.Value) (reflect.Type, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoneableString converts a starlark.Value to a string pointer. If the starlark.Value is NoneType,
|
// UnmarshalNoneable is like Unmarshal, but it will accept None as the top level (but not nested)
|
||||||
// a nil pointer will be returned instead. All other types of starlark values are errors.
|
// starlark value. If the value is None, a nil pointer will be returned, otherwise a pointer
|
||||||
func NoneableString(value starlark.Value) (*string, error) {
|
// to the result of Unmarshal will be returned.
|
||||||
switch v := value.(type) {
|
func UnmarshalNoneable[T any](value starlark.Value) (*T, error) {
|
||||||
case starlark.String:
|
if _, ok := value.(starlark.NoneType); ok {
|
||||||
result := v.GoString()
|
|
||||||
return &result, nil
|
|
||||||
case starlark.NoneType:
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("expected string or none, got %q", value.Type())
|
|
||||||
}
|
}
|
||||||
|
ret, err := Unmarshal[T](value)
|
||||||
|
return &ret, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user