release-config: disallow new duplicate flag declarations
Flags must only be declared in one place in the tree. This change prevents new ones from being added while we fix the bad flags already present. Bug: 352105274 Test: manual Merged-In: I8c4bf2b2852685e84177500f28fe8908016082b9 Change-Id: I8c4bf2b2852685e84177500f28fe8908016082b9
This commit is contained in:
@@ -18,10 +18,21 @@ import (
|
|||||||
rc_proto "android/soong/cmd/release_config/release_config_proto"
|
rc_proto "android/soong/cmd/release_config/release_config_proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Allowlist: these flags may have duplicate (identical) declarations
|
||||||
|
// without generating an error. This will be removed once all such
|
||||||
|
// declarations have been fixed.
|
||||||
|
DuplicateDeclarationAllowlist = map[string]bool{}
|
||||||
|
)
|
||||||
|
|
||||||
func FlagDeclarationFactory(protoPath string) (fd *rc_proto.FlagDeclaration) {
|
func FlagDeclarationFactory(protoPath string) (fd *rc_proto.FlagDeclaration) {
|
||||||
fd = &rc_proto.FlagDeclaration{}
|
fd = &rc_proto.FlagDeclaration{}
|
||||||
if protoPath != "" {
|
if protoPath != "" {
|
||||||
LoadMessage(protoPath, fd)
|
LoadMessage(protoPath, fd)
|
||||||
}
|
}
|
||||||
|
// If the input didn't specify a value, create one (== UnspecifiedValue).
|
||||||
|
if fd.Value == nil {
|
||||||
|
fd.Value = &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}}
|
||||||
|
}
|
||||||
return fd
|
return fd
|
||||||
}
|
}
|
||||||
|
@@ -276,6 +276,20 @@ func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex
|
|||||||
configs.Aliases[name] = alias.Target
|
configs.Aliases[name] = alias.Target
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
|
// Temporarily allowlist duplicate flag declaration files to prevent
|
||||||
|
// more from entering the tree while we work to clean up the duplicates
|
||||||
|
// that already exist.
|
||||||
|
dupFlagFile := filepath.Join(dir, "duplicate_allowlist.txt")
|
||||||
|
data, err := os.ReadFile(dupFlagFile)
|
||||||
|
if err == nil {
|
||||||
|
for _, flag := range strings.Split(string(data), "\n") {
|
||||||
|
flag = strings.TrimSpace(flag)
|
||||||
|
if strings.HasPrefix(flag, "//") || strings.HasPrefix(flag, "#") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
DuplicateDeclarationAllowlist[flag] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
err = WalkTextprotoFiles(dir, "flag_declarations", func(path string, d fs.DirEntry, err error) error {
|
err = WalkTextprotoFiles(dir, "flag_declarations", func(path string, d fs.DirEntry, err error) error {
|
||||||
flagDeclaration := FlagDeclarationFactory(path)
|
flagDeclaration := FlagDeclarationFactory(path)
|
||||||
// Container must be specified.
|
// Container must be specified.
|
||||||
@@ -289,14 +303,6 @@ func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: once we have namespaces initialized, we can throw an error here.
|
|
||||||
if flagDeclaration.Namespace == nil {
|
|
||||||
flagDeclaration.Namespace = proto.String("android_UNKNOWN")
|
|
||||||
}
|
|
||||||
// If the input didn't specify a value, create one (== UnspecifiedValue).
|
|
||||||
if flagDeclaration.Value == nil {
|
|
||||||
flagDeclaration.Value = &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}}
|
|
||||||
}
|
|
||||||
m.FlagDeclarations = append(m.FlagDeclarations, *flagDeclaration)
|
m.FlagDeclarations = append(m.FlagDeclarations, *flagDeclaration)
|
||||||
name := *flagDeclaration.Name
|
name := *flagDeclaration.Name
|
||||||
if name == "RELEASE_ACONFIG_VALUE_SETS" {
|
if name == "RELEASE_ACONFIG_VALUE_SETS" {
|
||||||
@@ -304,8 +310,8 @@ func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex
|
|||||||
}
|
}
|
||||||
if def, ok := configs.FlagArtifacts[name]; !ok {
|
if def, ok := configs.FlagArtifacts[name]; !ok {
|
||||||
configs.FlagArtifacts[name] = &FlagArtifact{FlagDeclaration: flagDeclaration, DeclarationIndex: ConfigDirIndex}
|
configs.FlagArtifacts[name] = &FlagArtifact{FlagDeclaration: flagDeclaration, DeclarationIndex: ConfigDirIndex}
|
||||||
} else if !proto.Equal(def.FlagDeclaration, flagDeclaration) {
|
} else if !proto.Equal(def.FlagDeclaration, flagDeclaration) || !DuplicateDeclarationAllowlist[name] {
|
||||||
return fmt.Errorf("Duplicate definition of %s", *flagDeclaration.Name)
|
return fmt.Errorf("Duplicate definition of %s in %s", *flagDeclaration.Name, path)
|
||||||
}
|
}
|
||||||
// Set the initial value in the flag artifact.
|
// Set the initial value in the flag artifact.
|
||||||
configs.FilesUsedMap[path] = true
|
configs.FilesUsedMap[path] = true
|
||||||
|
Reference in New Issue
Block a user