From eebb25935669d18072ec6f11416bf69a48e00990 Mon Sep 17 00:00:00 2001 From: Yu Liu Date: Thu, 12 Oct 2023 20:31:27 -0700 Subject: [PATCH] Handle the case where the release value set is a list. Bug: 304814040 Test: CI, unit test, b build build/make/tools/aconfig:aconfig.test.cpp b test build/make/tools/aconfig:AconfigJavaHostTest Change-Id: I9ca939348a063c39e9528f24e788f9757458d30c --- aconfig/aconfig_declarations.go | 4 +-- android/allowlists/allowlists.go | 2 ++ android/config.go | 24 +++++++++-------- android/variable.go | 4 +-- bp2build/bp2build_product_config.go | 42 +++++++++++++++++++++++++++-- 5 files changed, 59 insertions(+), 17 deletions(-) diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go index f19ddb8be..897f8925a 100644 --- a/aconfig/aconfig_declarations.go +++ b/aconfig/aconfig_declarations.go @@ -74,8 +74,8 @@ func (module *DeclarationsModule) DepsMutator(ctx android.BottomUpMutatorContext // RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that // match our package. valuesFromConfig := ctx.Config().ReleaseAconfigValueSets() - if valuesFromConfig != "" { - ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig) + if len(valuesFromConfig) > 0 { + ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig...) } } diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 53546114a..40f7d7f5c 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -531,6 +531,8 @@ var ( } Bp2buildModuleAlwaysConvertList = []string{ + "aconfig.test.cpp", + "AconfigJavaHostTest", // aconfig "libonce_cell", "libanyhow", diff --git a/android/config.go b/android/config.go index 2930c86a6..8f72239b9 100644 --- a/android/config.go +++ b/android/config.go @@ -200,21 +200,23 @@ func (c Config) ReleaseVersion() string { } // The aconfig value set passed to aconfig, derived from RELEASE_VERSION -func (c Config) ReleaseAconfigValueSets() string { +func (c Config) ReleaseAconfigValueSets() []string { // This logic to handle both Soong module name and bazel target is temporary in order to // provide backward compatibility where aosp and internal both have the release // aconfig value set but can't be updated at the same time to use bazel target - value := strings.Split(c.config.productVariables.ReleaseAconfigValueSets, ":") - value_len := len(value) - if value_len > 2 { - // This shouldn't happen as this should be either a module name or a bazel target path. - panic(fmt.Errorf("config file: invalid value for release aconfig value sets: %s", - c.config.productVariables.ReleaseAconfigValueSets)) + var valueSets []string + for _, valueSet := range c.config.productVariables.ReleaseAconfigValueSets { + value := strings.Split(valueSet, ":") + valueLen := len(value) + if valueLen > 2 { + // This shouldn't happen as this should be either a module name or a bazel target path. + panic(fmt.Errorf("config file: invalid value for release aconfig value sets: %s", valueSet)) + } + if valueLen > 0 { + valueSets = append(valueSets, value[valueLen-1]) + } } - if value_len > 0 { - return value[value_len-1] - } - return "" + return valueSets } // The flag default permission value passed to aconfig diff --git a/android/variable.go b/android/variable.go index 006a77f11..ab6dfefd6 100644 --- a/android/variable.go +++ b/android/variable.go @@ -474,8 +474,8 @@ type ProductVariables struct { ProductBrand string `json:",omitempty"` BuildVersionTags []string `json:",omitempty"` - ReleaseVersion string `json:",omitempty"` - ReleaseAconfigValueSets string `json:",omitempty"` + ReleaseVersion string `json:",omitempty"` + ReleaseAconfigValueSets []string `json:",omitempty"` ReleaseAconfigFlagDefaultPermission string `json:",omitempty"` diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go index 3e004534e..2adccccfd 100644 --- a/bp2build/bp2build_product_config.go +++ b/bp2build/bp2build_product_config.go @@ -29,6 +29,8 @@ type bazelLabel struct { target string } +const releaseAconfigValueSetsName = "release_aconfig_value_sets" + func (l *bazelLabel) Less(other *bazelLabel) bool { if l.repo < other.repo { return true @@ -343,10 +345,11 @@ func platformMappingSingleProduct( result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand)) result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer)) result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission)) - // Empty string can't be used as label_flag on the bazel side + releaseAconfigValueSets := "//build/bazel/product_config:empty_aconfig_value_sets" if len(productVariables.ReleaseAconfigValueSets) > 0 { - result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", productVariables.ReleaseAconfigValueSets)) + releaseAconfigValueSets = "@//" + label.pkg + ":" + releaseAconfigValueSetsName + "_" + label.target } + result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", releaseAconfigValueSets)) result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_version=%s\n", productVariables.ReleaseVersion)) result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version)) result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack))) @@ -481,6 +484,7 @@ func starlarkMapToProductVariables(in map[string]starlark.Value) (android.Produc func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) { createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res) createAvbKeyFilegroups(productLabelsToVariables, res) + createReleaseAconfigValueSetsFilegroup(productLabelsToVariables, res) for label, variables := range productLabelsToVariables { createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res) } @@ -515,6 +519,40 @@ func createGeneratedAndroidCertificateDirectories(productLabelsToVariables map[b } } +func createReleaseAconfigValueSetsFilegroup(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) { + for label, productVariables := range productLabelsToVariables { + if len(productVariables.ReleaseAconfigValueSets) > 0 { + key := label.target + dir := label.pkg + var value_sets strings.Builder + for _, value_set := range productVariables.ReleaseAconfigValueSets { + value_sets.WriteString(" \"" + value_set + "\",\n") + } + + name := releaseAconfigValueSetsName + "_" + key + content := "aconfig_value_sets(\n" + + " name = \"" + name + "\",\n" + + " value_sets = [\n" + + value_sets.String() + + " ],\n" + + " visibility = [\"//visibility:public\"],\n" + + ")" + targets[dir] = append(targets[dir], BazelTarget{ + name: name, + packageName: dir, + content: content, + ruleClass: "aconfig_value_sets", + loads: []BazelLoad{{ + file: "//build/bazel/rules/aconfig:aconfig_value_sets.bzl", + symbols: []BazelLoadSymbol{{ + symbol: "aconfig_value_sets", + }}, + }}, + }) + } + } +} + func createAvbKeyFilegroups(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) { var allAvbKeys []string for _, productVariables := range productLabelsToVariables {