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:
@@ -278,6 +278,23 @@ func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, a
|
|||||||
valueDir = mapDir
|
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{
|
flagValue := &rc_proto.FlagValue{
|
||||||
Name: proto.String(name),
|
Name: proto.String(name),
|
||||||
Value: rc_lib.UnmarshalValue(value),
|
Value: rc_lib.UnmarshalValue(value),
|
||||||
@@ -297,7 +314,8 @@ func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, a
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("Updated: %s\n", flagPath)
|
updatedFiles = append(updatedFiles, flagPath)
|
||||||
|
fmt.Printf("Added/Updated: %s\n", strings.Join(updatedFiles, " "))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -83,6 +83,11 @@ func WriteMessage(path string, message proto.Message) (err error) {
|
|||||||
// error: any error encountered.
|
// error: any error encountered.
|
||||||
func WriteFormattedMessage(path, format string, message proto.Message) (err error) {
|
func WriteFormattedMessage(path, format string, message proto.Message) (err error) {
|
||||||
var data []byte
|
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 {
|
switch format {
|
||||||
case "json":
|
case "json":
|
||||||
data, err = json.MarshalIndent(message, "", " ")
|
data, err = json.MarshalIndent(message, "", " ")
|
||||||
|
Reference in New Issue
Block a user