Merge "Break constant information out of product vars"
This commit is contained in:
@@ -420,6 +420,8 @@ func saveToBazelConfigFile(config *productVariables, outDir string) error {
|
||||
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
|
||||
`,
|
||||
@@ -429,6 +431,13 @@ arch_variant_product_var_constraints = _arch_variant_product_var_constraints
|
||||
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(`
|
||||
product_var_constraints = %s
|
||||
arch_variant_product_var_constraints = %s
|
||||
`, nonArchVariantProductVariablesJson, archVariantProductVariablesJson)), 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 {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/starlark_fmt"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -62,6 +64,7 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) ([]BazelFil
|
||||
// TODO(b/269691302) value of apiLevelsContent is product variable dependent and should be avoided for soong injection
|
||||
files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent)))
|
||||
files = append(files, newFile("api_levels", "api_levels.bzl", android.StarlarkApiLevelConfigs(cfg)))
|
||||
files = append(files, newFile("api_levels", "platform_versions.bzl", platformVersionContents(cfg)))
|
||||
|
||||
files = append(files, newFile("allowlists", GeneratedBuildFileName, ""))
|
||||
files = append(files, newFile("allowlists", "env.bzl", android.EnvironmentVarsFile(cfg)))
|
||||
@@ -72,6 +75,26 @@ func soongInjectionFiles(cfg android.Config, metrics CodegenMetrics) ([]BazelFil
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func platformVersionContents(cfg android.Config) string {
|
||||
// Despite these coming from cfg.productVariables, they are actually hardcoded in global
|
||||
// makefiles, not set in individual product config makesfiles, so they're safe to just export
|
||||
// and load() directly.
|
||||
|
||||
platformVersionActiveCodenames := make([]string, 0, len(cfg.PlatformVersionActiveCodenames()))
|
||||
for _, codename := range cfg.PlatformVersionActiveCodenames() {
|
||||
platformVersionActiveCodenames = append(platformVersionActiveCodenames, fmt.Sprintf("%q", codename))
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
platform_versions = struct(
|
||||
platform_sdk_final = %s,
|
||||
platform_sdk_version = %d,
|
||||
platform_sdk_codename = %q,
|
||||
platform_version_active_codenames = [%s],
|
||||
)
|
||||
`, starlark_fmt.PrintBool(cfg.PlatformSdkFinal()), cfg.PlatformSdkVersion().FinalInt(), cfg.PlatformSdkCodename(), strings.Join(platformVersionActiveCodenames, ", "))
|
||||
}
|
||||
|
||||
func CreateBazelFiles(
|
||||
cfg android.Config,
|
||||
ruleShims map[string]RuleShim,
|
||||
|
@@ -153,6 +153,10 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
|
||||
dir: "api_levels",
|
||||
basename: "api_levels.bzl",
|
||||
},
|
||||
{
|
||||
dir: "api_levels",
|
||||
basename: "platform_versions.bzl",
|
||||
},
|
||||
{
|
||||
dir: "allowlists",
|
||||
basename: GeneratedBuildFileName,
|
||||
|
@@ -35,7 +35,11 @@ func Indention(level int) string {
|
||||
|
||||
// PrintBool returns a Starlark compatible bool string.
|
||||
func PrintBool(item bool) string {
|
||||
return strings.Title(fmt.Sprintf("%t", item))
|
||||
if item {
|
||||
return "True"
|
||||
} else {
|
||||
return "False"
|
||||
}
|
||||
}
|
||||
|
||||
// PrintsStringList returns a Starlark-compatible string of a list of Strings/Labels.
|
||||
|
Reference in New Issue
Block a user