RELEASE_ACONFIG_VALUE_SETS is a reserved flag
Disallow setting the flag via protobuf files, and adjust it internally
to be more like any other build flag. This makes the generated output
more consistent.
Also default to TARGET_RELEASE if no release is given to `build-flag`.
Bug: 328495189
Test: manual
Change-Id: I9db57137fc4e5ed42a38adc939c430826afe4f63
diff --git a/cmd/release_config/build_flag/main.go b/cmd/release_config/build_flag/main.go
index ec7d64f..56c49d8 100644
--- a/cmd/release_config/build_flag/main.go
+++ b/cmd/release_config/build_flag/main.go
@@ -325,7 +325,12 @@
}
if len(commonFlags.targetReleases) == 0 {
- commonFlags.targetReleases = rc_lib.StringList{"trunk_staging"}
+ release, ok := os.LookupEnv("TARGET_RELEASE")
+ if ok {
+ commonFlags.targetReleases = rc_lib.StringList{release}
+ } else {
+ commonFlags.targetReleases = rc_lib.StringList{"trunk_staging"}
+ }
}
if err = os.Chdir(commonFlags.top); err != nil {
diff --git a/cmd/release_config/release_config_lib/release_config.go b/cmd/release_config/release_config_lib/release_config.go
index e51ff08..f25cc6e 100644
--- a/cmd/release_config/release_config_lib/release_config.go
+++ b/cmd/release_config/release_config_lib/release_config.go
@@ -90,7 +90,13 @@
if !ok {
return fmt.Errorf("Could not inherit flag %s from %s", name, iConfig.Name)
}
- if len(fa.Traces) > 1 {
+ if name == "RELEASE_ACONFIG_VALUE_SETS" {
+ if len(fa.Traces) > 0 {
+ myFa.Traces = append(myFa.Traces, fa.Traces...)
+ myFa.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{
+ myFa.Value.GetStringValue() + " " + fa.Value.GetStringValue()}}
+ }
+ } else if len(fa.Traces) > 1 {
// A value was assigned. Set our value.
myFa.Traces = append(myFa.Traces, fa.Traces[1:]...)
myFa.Value = fa.Value
@@ -111,21 +117,7 @@
// Start with only the flag declarations.
config.FlagArtifacts = configs.FlagArtifacts.Clone()
- // Add RELEASE_ACONFIG_VALUE_SETS
- workflowManual := rc_proto.Workflow(rc_proto.Workflow_MANUAL)
- releaseAconfigValueSets := FlagArtifact{
- FlagDeclaration: &rc_proto.FlagDeclaration{
- Name: proto.String("RELEASE_ACONFIG_VALUE_SETS"),
- Namespace: proto.String("android_UNKNOWN"),
- Description: proto.String("Aconfig value sets assembled by release-config"),
- Workflow: &workflowManual,
- Containers: []string{"system", "system_ext", "product", "vendor"},
- Value: &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}},
- },
- DeclarationIndex: -1,
- Traces: []*rc_proto.Tracepoint{},
- }
- config.FlagArtifacts["RELEASE_ACONFIG_VALUE_SETS"] = &releaseAconfigValueSets
+ releaseAconfigValueSets := config.FlagArtifacts["RELEASE_ACONFIG_VALUE_SETS"]
// Generate any configs we need to inherit. This will detect loops in
// the config.
@@ -154,27 +146,22 @@
}
contributionsToApply = append(contributionsToApply, config.Contributions...)
- myAconfigValueSets := strings.Split(releaseAconfigValueSets.Value.GetStringValue(), " ")
- myAconfigValueSetsMap := map[string]bool{}
- for _, v := range myAconfigValueSets {
- myAconfigValueSetsMap[v] = true
- }
+ workflowManual := rc_proto.Workflow(rc_proto.Workflow_MANUAL)
myDirsMap := make(map[int]bool)
for _, contrib := range contributionsToApply {
contribAconfigValueSets := []string{}
- // Gather the aconfig_value_sets from this contribution that are not already in the list.
+ // Gather the aconfig_value_sets from this contribution, allowing duplicates for simplicity.
for _, v := range contrib.proto.AconfigValueSets {
- if _, ok := myAconfigValueSetsMap[v]; !ok {
- contribAconfigValueSets = append(contribAconfigValueSets, v)
- myAconfigValueSetsMap[v] = true
- }
+ contribAconfigValueSets = append(contribAconfigValueSets, v)
}
- myAconfigValueSets = append(myAconfigValueSets, contribAconfigValueSets...)
+ contribAconfigValueSetsString := strings.Join(contribAconfigValueSets, " ")
+ releaseAconfigValueSets.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{
+ releaseAconfigValueSets.Value.GetStringValue() + " " + contribAconfigValueSetsString}}
releaseAconfigValueSets.Traces = append(
releaseAconfigValueSets.Traces,
&rc_proto.Tracepoint{
Source: proto.String(contrib.path),
- Value: &rc_proto.Value{Val: &rc_proto.Value_StringValue{strings.Join(contribAconfigValueSets, " ")}},
+ Value: &rc_proto.Value{Val: &rc_proto.Value_StringValue{contribAconfigValueSetsString}},
})
myDirsMap[contrib.DeclarationIndex] = true
@@ -204,6 +191,16 @@
}
}
}
+ // Now remove any duplicates from the actual value of RELEASE_ACONFIG_VALUE_SETS
+ myAconfigValueSets := []string{}
+ myAconfigValueSetsMap := map[string]bool{}
+ for _, v := range strings.Split(releaseAconfigValueSets.Value.GetStringValue(), " ") {
+ if myAconfigValueSetsMap[v] {
+ continue
+ }
+ myAconfigValueSetsMap[v] = true
+ myAconfigValueSets = append(myAconfigValueSets, v)
+ }
releaseAconfigValueSets.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{strings.TrimSpace(strings.Join(myAconfigValueSets, " "))}}
directories := []string{}
diff --git a/cmd/release_config/release_config_lib/release_configs.go b/cmd/release_config/release_config_lib/release_configs.go
index cedf247..3429400 100644
--- a/cmd/release_config/release_config_lib/release_configs.go
+++ b/cmd/release_config/release_config_lib/release_configs.go
@@ -95,7 +95,7 @@
}
func ReleaseConfigsFactory() (c *ReleaseConfigs) {
- return &ReleaseConfigs{
+ configs := ReleaseConfigs{
Aliases: make(map[string]*string),
FlagArtifacts: make(map[string]*FlagArtifact),
ReleaseConfigs: make(map[string]*ReleaseConfig),
@@ -103,6 +103,21 @@
configDirs: []string{},
configDirIndexes: make(ReleaseConfigDirMap),
}
+ workflowManual := rc_proto.Workflow(rc_proto.Workflow_MANUAL)
+ releaseAconfigValueSets := FlagArtifact{
+ FlagDeclaration: &rc_proto.FlagDeclaration{
+ Name: proto.String("RELEASE_ACONFIG_VALUE_SETS"),
+ Namespace: proto.String("android_UNKNOWN"),
+ Description: proto.String("Aconfig value sets assembled by release-config"),
+ Workflow: &workflowManual,
+ Containers: []string{"system", "system_ext", "product", "vendor"},
+ Value: &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}},
+ },
+ DeclarationIndex: -1,
+ Traces: []*rc_proto.Tracepoint{},
+ }
+ configs.FlagArtifacts["RELEASE_ACONFIG_VALUE_SETS"] = &releaseAconfigValueSets
+ return &configs
}
func ReleaseConfigMapFactory(protoPath string) (m *ReleaseConfigMap) {
@@ -166,6 +181,9 @@
}
m.FlagDeclarations = append(m.FlagDeclarations, *flagDeclaration)
name := *flagDeclaration.Name
+ if name == "RELEASE_ACONFIG_VALUE_SETS" {
+ return fmt.Errorf("%s: %s is a reserved build flag", path, name)
+ }
if def, ok := configs.FlagArtifacts[name]; !ok {
configs.FlagArtifacts[name] = &FlagArtifact{FlagDeclaration: flagDeclaration, DeclarationIndex: ConfigDirIndex}
} else if !proto.Equal(def.FlagDeclaration, flagDeclaration) {
@@ -176,7 +194,7 @@
FlagValue{path: path, proto: rc_proto.FlagValue{
Name: proto.String(name), Value: flagDeclaration.Value}})
if configs.FlagArtifacts[name].Redacted {
- return fmt.Errorf("%s may not be redacted by default.", *flagDeclaration.Name)
+ return fmt.Errorf("%s may not be redacted by default.", name)
}
return nil
})
@@ -203,6 +221,9 @@
if fmt.Sprintf("%s.textproto", *flagValue.proto.Name) != filepath.Base(path) {
return fmt.Errorf("%s incorrectly sets value for flag %s", path, *flagValue.proto.Name)
}
+ if *flagValue.proto.Name == "RELEASE_ACONFIG_VALUE_SETS" {
+ return fmt.Errorf("%s: %s is a reserved build flag", path, *flagValue.proto.Name)
+ }
releaseConfigContribution.FlagValues = append(releaseConfigContribution.FlagValues, flagValue)
return nil
})
@@ -382,7 +403,9 @@
if len(releaseConfigMapPaths) == 0 {
return nil, fmt.Errorf("No maps found")
}
- warnf("No --map argument provided. Using: --map %s\n", strings.Join(releaseConfigMapPaths, " --map "))
+ if !useBuildVar {
+ warnf("No --map argument provided. Using: --map %s\n", strings.Join(releaseConfigMapPaths, " --map "))
+ }
}
configs := ReleaseConfigsFactory()