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

Commit 14e2ac68 authored by LaMont Jones's avatar LaMont Jones
Browse files

release_config: cleanup how we emit results

 - Allow each of the formats (json, pb, textproto) to be individually
   controlled.
 - Include product and release in the name of the aritfact.

Bug: 328495189
Test: manual
Change-Id: Ia08e7224200a48994bea882a61b8199d53576d38
parent 7ac07deb
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@ package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"

	rc_lib "android/soong/cmd/release_config/release_config_lib"
)
@@ -29,12 +31,23 @@ func main() {
	var outputDir string
	var err error
	var configs *rc_lib.ReleaseConfigs
	var json, pb, textproto bool
	var product string

	defaultRelease := os.Getenv("TARGET_RELEASE")
	if defaultRelease == "" {
		defaultRelease = "trunk_staging"
	}

	flag.StringVar(&top, "top", ".", "path to top of workspace")
	flag.StringVar(&product, "product", os.Getenv("TARGET_PRODUCT"), "TARGET_PRODUCT for the build")
	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(&targetRelease, "release", defaultRelease, "TARGET_RELEASE for this build")
	flag.StringVar(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
	flag.BoolVar(&textproto, "textproto", true, "write artifacts as text protobuf")
	flag.BoolVar(&json, "json", true, "write artifacts as json")
	flag.BoolVar(&pb, "pb", true, "write artifacts as binary protobuf")
	flag.Parse()

	if quiet {
@@ -48,16 +61,36 @@ func main() {
	if err != nil {
		panic(err)
	}
	config, err := configs.GetReleaseConfig(targetRelease)
	if err != nil {
		panic(err)
	}
	releaseName := config.Name
	err = os.MkdirAll(outputDir, 0775)
	if err != nil {
		panic(err)
	}
	err = configs.DumpMakefile(outputDir, targetRelease)
	makefilePath := filepath.Join(outputDir, fmt.Sprintf("release_config-%s-%s.mk", product, releaseName))
	err = configs.WriteMakefile(makefilePath, targetRelease)
	if err != nil {
		panic(err)
	}
	if json {
		err = configs.WriteArtifact(outputDir, product, "json")
		if err != nil {
			panic(err)
		}
	err = configs.DumpArtifact(outputDir)
	}
	if pb {
		err = configs.WriteArtifact(outputDir, product, "pb")
		if err != nil {
			panic(err)
		}
	}
	if textproto {
		err = configs.WriteArtifact(outputDir, product, "textproto")
		if err != nil {
			panic(err)
		}
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package {

bootstrap_go_package {
    name: "soong-cmd-release_config-lib",
    pkgPath: "android/soong/release_config/release_config_lib",
    pkgPath: "android/soong/cmd/release_config/release_config_lib",
    deps: [
        "golang-protobuf-encoding-prototext",
        "golang-protobuf-reflect-protoreflect",
+41 −16
Original line number Diff line number Diff line
@@ -17,29 +17,37 @@ package release_config_lib
import (
	"fmt"

	"android/soong/cmd/release_config/release_config_proto"
	rc_proto "android/soong/cmd/release_config/release_config_proto"

	"google.golang.org/protobuf/proto"
)

// A flag artifact, with its final value and declaration/override history.
type FlagArtifact struct {
	FlagDeclaration *release_config_proto.FlagDeclaration
	// The flag_declaration message.
	FlagDeclaration *rc_proto.FlagDeclaration

	// The index of the config directory where this flag was declared.
	// Flag values cannot be set in a location with a lower index.
	DeclarationIndex int

	Traces []*release_config_proto.Tracepoint
	// A history of value assignments and overrides.
	Traces []*rc_proto.Tracepoint

	// Assigned value
	Value *release_config_proto.Value
	// The value of the flag.
	Value *rc_proto.Value
}

// Key is flag name.
type FlagArtifacts map[string]*FlagArtifact

// Create a clone of the flag artifact.
//
// Returns:
//
//	*FlagArtifact: the copy of the artifact.
func (src *FlagArtifact) Clone() *FlagArtifact {
	value := &release_config_proto.Value{}
	value := &rc_proto.Value{}
	proto.Merge(value, src.Value)
	return &FlagArtifact{
		FlagDeclaration: src.FlagDeclaration,
@@ -48,6 +56,11 @@ func (src *FlagArtifact) Clone() *FlagArtifact {
	}
}

// Clone FlagArtifacts.
//
// Returns:
//
//	FlagArtifacts: a copy of the source FlagArtifacts.
func (src FlagArtifacts) Clone() (dst FlagArtifacts) {
	if dst == nil {
		dst = make(FlagArtifacts)
@@ -58,23 +71,34 @@ func (src FlagArtifacts) Clone() (dst FlagArtifacts) {
	return
}

// Update the value of a flag.
//
// This appends to flagArtifact.Traces, and updates flagArtifact.Value.
//
// Args:
//
//	flagValue FlagValue: the value to assign
//
// Returns:
//
//	error: any error encountered
func (fa *FlagArtifact) UpdateValue(flagValue FlagValue) error {
	name := *flagValue.proto.Name
	fa.Traces = append(fa.Traces, &release_config_proto.Tracepoint{Source: proto.String(flagValue.path), Value: flagValue.proto.Value})
	fa.Traces = append(fa.Traces, &rc_proto.Tracepoint{Source: proto.String(flagValue.path), Value: flagValue.proto.Value})
	if fa.Value.GetObsolete() {
		return fmt.Errorf("Attempting to set obsolete flag %s. Trace=%v", name, fa.Traces)
	}
	var newValue *release_config_proto.Value
	var newValue *rc_proto.Value
	switch val := flagValue.proto.Value.Val.(type) {
	case *release_config_proto.Value_StringValue:
		newValue = &release_config_proto.Value{Val: &release_config_proto.Value_StringValue{val.StringValue}}
	case *release_config_proto.Value_BoolValue:
		newValue = &release_config_proto.Value{Val: &release_config_proto.Value_BoolValue{val.BoolValue}}
	case *release_config_proto.Value_Obsolete:
	case *rc_proto.Value_StringValue:
		newValue = &rc_proto.Value{Val: &rc_proto.Value_StringValue{val.StringValue}}
	case *rc_proto.Value_BoolValue:
		newValue = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{val.BoolValue}}
	case *rc_proto.Value_Obsolete:
		if !val.Obsolete {
			return fmt.Errorf("%s: Cannot set obsolete=false.  Trace=%v", name, fa.Traces)
		}
		newValue = &release_config_proto.Value{Val: &release_config_proto.Value_Obsolete{true}}
		newValue = &rc_proto.Value{Val: &rc_proto.Value_Obsolete{true}}
	default:
		return fmt.Errorf("Invalid type for flag_value: %T.  Trace=%v", val, fa.Traces)
	}
@@ -85,8 +109,9 @@ func (fa *FlagArtifact) UpdateValue(flagValue FlagValue) error {
	return nil
}

func (fa *FlagArtifact) Marshal() (*release_config_proto.FlagArtifact, error) {
	return &release_config_proto.FlagArtifact{
// Marshal the FlagArtifact into a flag_artifact message.
func (fa *FlagArtifact) Marshal() (*rc_proto.FlagArtifact, error) {
	return &rc_proto.FlagArtifact{
		FlagDeclaration: fa.FlagDeclaration,
		Value:           fa.Value,
		Traces:          fa.Traces,
+4 −4
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@
package release_config_lib

import (
	"android/soong/cmd/release_config/release_config_proto"
	rc_proto "android/soong/cmd/release_config/release_config_proto"
)

func FlagDeclarationFactory(protoPath string) (fd *release_config_proto.FlagDeclaration) {
	fd = &release_config_proto.FlagDeclaration{}
func FlagDeclarationFactory(protoPath string) (fd *rc_proto.FlagDeclaration) {
	fd = &rc_proto.FlagDeclaration{}
	if protoPath != "" {
		LoadTextproto(protoPath, fd)
		LoadMessage(protoPath, fd)
	}
	return fd
}
+25 −8
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
package release_config_lib

import (
	"android/soong/cmd/release_config/release_config_proto"
	"strings"

	rc_proto "android/soong/cmd/release_config/release_config_proto"
)

type FlagValue struct {
@@ -23,31 +25,46 @@ type FlagValue struct {
	path string

	// Protobuf
	proto release_config_proto.FlagValue
	proto rc_proto.FlagValue
}

func FlagValueFactory(protoPath string) (fv *FlagValue) {
	fv = &FlagValue{path: protoPath}
	if protoPath != "" {
		LoadTextproto(protoPath, &fv.proto)
		LoadMessage(protoPath, &fv.proto)
	}
	return fv
}

func MarshalValue(value *release_config_proto.Value) string {
func UnmarshalValue(str string) *rc_proto.Value {
	ret := &rc_proto.Value{}
	switch v := strings.ToLower(str); v {
	case "true":
		ret = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{true}}
	case "false":
		ret = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{false}}
	case "##obsolete":
		ret = &rc_proto.Value{Val: &rc_proto.Value_Obsolete{true}}
	default:
		ret = &rc_proto.Value{Val: &rc_proto.Value_StringValue{str}}
	}
	return ret
}

func MarshalValue(value *rc_proto.Value) string {
	switch val := value.Val.(type) {
	case *release_config_proto.Value_UnspecifiedValue:
	case *rc_proto.Value_UnspecifiedValue:
		// Value was never set.
		return ""
	case *release_config_proto.Value_StringValue:
	case *rc_proto.Value_StringValue:
		return val.StringValue
	case *release_config_proto.Value_BoolValue:
	case *rc_proto.Value_BoolValue:
		if val.BoolValue {
			return "true"
		}
		// False ==> empty string
		return ""
	case *release_config_proto.Value_Obsolete:
	case *rc_proto.Value_Obsolete:
		return " #OBSOLETE"
	default:
		// Flagged as error elsewhere, so return empty string here.
Loading