build-flag: ensure release_config declaration exists
If we are setting a flag for a release config in a map directory that doesn't yet declare that release config, this map directory needs to contribute to the release config. Bug: 345278765 Test: manual Change-Id: Ie4e74bce008c4c4fdc4bc16e3209f0d9ef9cf8a2
This commit is contained in:
parent
ef0024775f
commit
6b002a7d08
2 changed files with 24 additions and 1 deletions
|
@ -278,6 +278,23 @@ func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, a
|
|||
valueDir = mapDir
|
||||
}
|
||||
|
||||
var updatedFiles []string
|
||||
rcPath := filepath.Join(valueDir, "release_configs", fmt.Sprintf("%s.textproto", targetRelease))
|
||||
// Create the release config declaration only if necessary.
|
||||
if _, err = os.Stat(rcPath); err != nil {
|
||||
if err = os.MkdirAll(filepath.Dir(rcPath), 0775); err != nil {
|
||||
return err
|
||||
}
|
||||
rcValue := &rc_proto.ReleaseConfig{
|
||||
Name: proto.String(targetRelease),
|
||||
}
|
||||
err = rc_lib.WriteMessage(rcPath, rcValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updatedFiles = append(updatedFiles, rcPath)
|
||||
}
|
||||
|
||||
flagValue := &rc_proto.FlagValue{
|
||||
Name: proto.String(name),
|
||||
Value: rc_lib.UnmarshalValue(value),
|
||||
|
@ -297,7 +314,8 @@ func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, a
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Updated: %s\n", flagPath)
|
||||
updatedFiles = append(updatedFiles, flagPath)
|
||||
fmt.Printf("Added/Updated: %s\n", strings.Join(updatedFiles, " "))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,11 @@ func WriteMessage(path string, message proto.Message) (err error) {
|
|||
// error: any error encountered.
|
||||
func WriteFormattedMessage(path, format string, message proto.Message) (err error) {
|
||||
var data []byte
|
||||
if _, err := os.Stat(filepath.Dir(path)); err != nil {
|
||||
if err = os.MkdirAll(filepath.Dir(path), 0775); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
switch format {
|
||||
case "json":
|
||||
data, err = json.MarshalIndent(message, "", " ")
|
||||
|
|
Loading…
Reference in a new issue