Merge "Handle the case where the release value set is a list." into main

This commit is contained in:
Yu Liu 2023-10-14 03:27:30 +00:00 committed by Gerrit Code Review
commit f613da45db
5 changed files with 59 additions and 17 deletions

View file

@ -74,8 +74,8 @@ func (module *DeclarationsModule) DepsMutator(ctx android.BottomUpMutatorContext
// RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that // RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that
// match our package. // match our package.
valuesFromConfig := ctx.Config().ReleaseAconfigValueSets() valuesFromConfig := ctx.Config().ReleaseAconfigValueSets()
if valuesFromConfig != "" { if len(valuesFromConfig) > 0 {
ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig) ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig...)
} }
} }

View file

@ -539,6 +539,8 @@ var (
} }
Bp2buildModuleAlwaysConvertList = []string{ Bp2buildModuleAlwaysConvertList = []string{
"aconfig.test.cpp",
"AconfigJavaHostTest",
// aconfig // aconfig
"libonce_cell", "libonce_cell",
"libanyhow", "libanyhow",

View file

@ -200,21 +200,23 @@ func (c Config) ReleaseVersion() string {
} }
// The aconfig value set passed to aconfig, derived from RELEASE_VERSION // 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 // 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 // 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 // aconfig value set but can't be updated at the same time to use bazel target
value := strings.Split(c.config.productVariables.ReleaseAconfigValueSets, ":") var valueSets []string
value_len := len(value) for _, valueSet := range c.config.productVariables.ReleaseAconfigValueSets {
if value_len > 2 { value := strings.Split(valueSet, ":")
// This shouldn't happen as this should be either a module name or a bazel target path. valueLen := len(value)
panic(fmt.Errorf("config file: invalid value for release aconfig value sets: %s", if valueLen > 2 {
c.config.productVariables.ReleaseAconfigValueSets)) // 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 valueSets
return value[value_len-1]
}
return ""
} }
// The flag default permission value passed to aconfig // The flag default permission value passed to aconfig

View file

@ -474,8 +474,8 @@ type ProductVariables struct {
ProductBrand string `json:",omitempty"` ProductBrand string `json:",omitempty"`
BuildVersionTags []string `json:",omitempty"` BuildVersionTags []string `json:",omitempty"`
ReleaseVersion string `json:",omitempty"` ReleaseVersion string `json:",omitempty"`
ReleaseAconfigValueSets string `json:",omitempty"` ReleaseAconfigValueSets []string `json:",omitempty"`
ReleaseAconfigFlagDefaultPermission string `json:",omitempty"` ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`

View file

@ -29,6 +29,8 @@ type bazelLabel struct {
target string target string
} }
const releaseAconfigValueSetsName = "release_aconfig_value_sets"
func (l *bazelLabel) Less(other *bazelLabel) bool { func (l *bazelLabel) Less(other *bazelLabel) bool {
if l.repo < other.repo { if l.repo < other.repo {
return true 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_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:product_manufacturer=%s\n", productVariables.ProductManufacturer))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission)) 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 { 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: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:platform_sdk_version=%d\n", platform_sdk_version))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack))) 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) { func createTargets(productLabelsToVariables map[bazelLabel]*android.ProductVariables, res map[string]BazelTargets) {
createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res) createGeneratedAndroidCertificateDirectories(productLabelsToVariables, res)
createAvbKeyFilegroups(productLabelsToVariables, res) createAvbKeyFilegroups(productLabelsToVariables, res)
createReleaseAconfigValueSetsFilegroup(productLabelsToVariables, res)
for label, variables := range productLabelsToVariables { for label, variables := range productLabelsToVariables {
createSystemPartition(label, &variables.PartitionVarsForBazelMigrationOnlyDoNotUse, res) 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) { func createAvbKeyFilegroups(productLabelsToVariables map[bazelLabel]*android.ProductVariables, targets map[string]BazelTargets) {
var allAvbKeys []string var allAvbKeys []string
for _, productVariables := range productLabelsToVariables { for _, productVariables := range productLabelsToVariables {