Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b002a7d authored by LaMont Jones's avatar LaMont Jones
Browse files

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
parent ef002477
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -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
}

+5 −0
Original line number Diff line number Diff line
@@ -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, "", "  ")