Print a warning on redundant overrides
Bug: 328495189 Test: manual Change-Id: I35bff9d6751e9aa304e4c2d7e24b9a44a3994264
This commit is contained in:
parent
f018d726ca
commit
7ac07deb9b
3 changed files with 28 additions and 3 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
func main() {
|
||||
var top string
|
||||
var quiet bool
|
||||
var releaseConfigMapPaths rc_lib.StringList
|
||||
var targetRelease string
|
||||
var outputDir string
|
||||
|
@ -30,11 +31,16 @@ func main() {
|
|||
var configs *rc_lib.ReleaseConfigs
|
||||
|
||||
flag.StringVar(&top, "top", ".", "path to top of workspace")
|
||||
flag.BoolVar(&quiet, "quiet", false, "disable warning messages")
|
||||
flag.Var(&releaseConfigMapPaths, "map", "path to a release_config_map.textproto. may be repeated")
|
||||
flag.StringVar(&targetRelease, "release", "trunk_staging", "TARGET_RELEASE for this build")
|
||||
flag.StringVar(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
|
||||
flag.Parse()
|
||||
|
||||
if quiet {
|
||||
rc_lib.DisableWarnings()
|
||||
}
|
||||
|
||||
if err = os.Chdir(top); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -64,19 +64,24 @@ func (fa *FlagArtifact) UpdateValue(flagValue FlagValue) error {
|
|||
if fa.Value.GetObsolete() {
|
||||
return fmt.Errorf("Attempting to set obsolete flag %s. Trace=%v", name, fa.Traces)
|
||||
}
|
||||
var newValue *release_config_proto.Value
|
||||
switch val := flagValue.proto.Value.Val.(type) {
|
||||
case *release_config_proto.Value_StringValue:
|
||||
fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_StringValue{val.StringValue}}
|
||||
newValue = &release_config_proto.Value{Val: &release_config_proto.Value_StringValue{val.StringValue}}
|
||||
case *release_config_proto.Value_BoolValue:
|
||||
fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_BoolValue{val.BoolValue}}
|
||||
newValue = &release_config_proto.Value{Val: &release_config_proto.Value_BoolValue{val.BoolValue}}
|
||||
case *release_config_proto.Value_Obsolete:
|
||||
if !val.Obsolete {
|
||||
return fmt.Errorf("%s: Cannot set obsolete=false. Trace=%v", name, fa.Traces)
|
||||
}
|
||||
fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_Obsolete{true}}
|
||||
newValue = &release_config_proto.Value{Val: &release_config_proto.Value_Obsolete{true}}
|
||||
default:
|
||||
return fmt.Errorf("Invalid type for flag_value: %T. Trace=%v", val, fa.Traces)
|
||||
}
|
||||
if proto.Equal(newValue, fa.Value) {
|
||||
warnf("%s: redundant override (set in %s)\n", flagValue.path, *fa.Traces[len(fa.Traces)-2].Source)
|
||||
}
|
||||
fa.Value = newValue
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import (
|
|||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var disableWarnings bool
|
||||
|
||||
type StringList []string
|
||||
|
||||
func (l *StringList) Set(v string) error {
|
||||
|
@ -62,6 +64,18 @@ func WalkTextprotoFiles(root string, subdir string, Func fs.WalkDirFunc) error {
|
|||
})
|
||||
}
|
||||
|
||||
// Turn off all warning output
|
||||
func DisableWarnings() {
|
||||
disableWarnings = true
|
||||
}
|
||||
|
||||
func warnf(format string, args ...any) (n int, err error) {
|
||||
if !disableWarnings {
|
||||
return fmt.Printf(format, args...)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func GetDefaultOutDir() string {
|
||||
outEnv := os.Getenv("OUT_DIR")
|
||||
if outEnv == "" {
|
||||
|
|
Loading…
Reference in a new issue