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

Commit db600990 authored by LaMont Jones's avatar LaMont Jones
Browse files

release_config: container is a repeated string field

Container is a string, and a flag can be in more than one container.

Bug: 328495189
Test: manual
Change-Id: I5a2a9855532027584d2b67f63f1b9584fce3d8d9
parent 2d5e7579
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -102,10 +102,13 @@ func ProcessBuildFlags(dir string, namespaceMap map[string]string) error {
			description = ""
			continue
		}
		declValue := matches[declRegexp.SubexpIndex("value")]
		declName := matches[declRegexp.SubexpIndex("name")]
		container := rc_proto.Container(rc_proto.Container_value[matches[declRegexp.SubexpIndex("container")]])
		declValue := matches[declRegexp.SubexpIndex("value")]
		description = strings.TrimSpace(description)
		containers := []string{strings.ToLower(matches[declRegexp.SubexpIndex("container")])}
		if containers[0] == "all" {
			containers = []string{"product", "system", "system_ext", "vendor"}
		}
		var namespace string
		var ok bool
		if namespace, ok = namespaceMap[declName]; !ok {
@@ -115,7 +118,7 @@ func ProcessBuildFlags(dir string, namespaceMap map[string]string) error {
			Name:        proto.String(declName),
			Namespace:   proto.String(namespace),
			Description: proto.String(description),
			Container:   &container,
			Containers:  containers,
		}
		description = ""
		// Most build flags are `workflow: PREBUILT`.
@@ -213,6 +216,12 @@ func ProcessBuildConfigs(dir, name string, paths []string, releaseProto *rc_prot
	return err
}

var (
	allContainers = func() []string {
		return []string{"product", "system", "system_ext", "vendor"}
	}()
)

func ProcessReleaseConfigMap(dir string, descriptionMap map[string]string) error {
	path := filepath.Join(dir, "release_config_map.mk")
	if _, err := os.Stat(path); err != nil {
@@ -235,16 +244,16 @@ func ProcessReleaseConfigMap(dir string, descriptionMap map[string]string) error
		return err
	}
	cleanDir := strings.TrimLeft(dir, "../")
	var defaultContainer rc_proto.Container
	var defaultContainers []string
	switch {
	case strings.HasPrefix(cleanDir, "build/") || cleanDir == "vendor/google_shared/build":
		defaultContainer = rc_proto.Container(rc_proto.Container_ALL)
		defaultContainers = allContainers
	case cleanDir == "vendor/google/release":
		defaultContainer = rc_proto.Container(rc_proto.Container_ALL)
		defaultContainers = allContainers
	default:
		defaultContainer = rc_proto.Container(rc_proto.Container_VENDOR)
		defaultContainers = []string{"vendor"}
	}
	releaseConfigMap := &rc_proto.ReleaseConfigMap{DefaultContainer: &defaultContainer}
	releaseConfigMap := &rc_proto.ReleaseConfigMap{DefaultContainers: defaultContainers}
	// If we find a description for the directory, include it.
	if description, ok := descriptionMap[cleanDir]; ok {
		releaseConfigMap.Description = proto.String(description)
+21 −41
Original line number Diff line number Diff line
@@ -109,23 +109,17 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro
	config.FlagArtifacts = configs.FlagArtifacts.Clone()
	// Add RELEASE_ACONFIG_VALUE_SETS
	workflowManual := rc_proto.Workflow(rc_proto.Workflow_MANUAL)
	container := rc_proto.Container(rc_proto.Container_ALL)
	releaseAconfigValueSets := FlagArtifact{
		FlagDeclaration: &rc_proto.FlagDeclaration{
			Name:        proto.String("RELEASE_ACONFIG_VALUE_SETS"),
			Namespace:   proto.String("android_UNKNOWN"),
			Description: proto.String("Aconfig value sets assembled by release-config"),
			Workflow:    &workflowManual,
			Container:   &container,
			Value:       &rc_proto.Value{Val: &rc_proto.Value_StringValue{""}},
			Containers:  []string{"system", "system_ext", "product", "vendor"},
			Value:       &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}},
		},
		DeclarationIndex: -1,
		Traces: []*rc_proto.Tracepoint{
			&rc_proto.Tracepoint{
				Source: proto.String("$release-config"),
				Value:  &rc_proto.Value{Val: &rc_proto.Value_StringValue{""}},
			},
		},
		Traces:           []*rc_proto.Tracepoint{},
	}
	config.FlagArtifacts["RELEASE_ACONFIG_VALUE_SETS"] = &releaseAconfigValueSets

@@ -163,8 +157,8 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro
	}
	myDirsMap := make(map[int]bool)
	for _, contrib := range contributionsToApply {
		if len(contrib.proto.AconfigValueSets) > 0 {
		contribAconfigValueSets := []string{}
		// Gather the aconfig_value_sets from this contribution that are not already in the list.
		for _, v := range contrib.proto.AconfigValueSets {
			if _, ok := myAconfigValueSetsMap[v]; !ok {
				contribAconfigValueSets = append(contribAconfigValueSets, v)
@@ -178,7 +172,7 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro
				Source: proto.String(contrib.path),
				Value:  &rc_proto.Value{Val: &rc_proto.Value_StringValue{strings.Join(contribAconfigValueSets, " ")}},
			})
		}

		myDirsMap[contrib.DeclarationIndex] = true
		for _, value := range contrib.FlagValues {
			name := *value.proto.Name
@@ -214,30 +208,16 @@ func (config *ReleaseConfig) GenerateReleaseConfig(configs *ReleaseConfigs) erro

	// Now build the per-partition artifacts
	config.PartitionBuildFlags = make(map[string]*rc_proto.FlagArtifacts)
	addPartitionArtifact := func(container string, artifact *rc_proto.FlagArtifact) {
		if _, ok := config.PartitionBuildFlags[container]; !ok {
			config.PartitionBuildFlags[container] = &rc_proto.FlagArtifacts{}
		}
		config.PartitionBuildFlags[container].FlagArtifacts = append(config.PartitionBuildFlags[container].FlagArtifacts, artifact)
	}
	for _, v := range config.FlagArtifacts {
		container := strings.ToLower(rc_proto.Container_name[int32(v.FlagDeclaration.GetContainer())])
		artifact, err := v.MarshalWithoutTraces()
		if err != nil {
			return err
		}
		switch container {
		case "all":
			for cVal, cName := range rc_proto.Container_name {
				// Skip unspecified, and "ALL", but place the flag in the rest.
				if cVal == 0 || cName == "ALL" {
					continue
				}
				cName = strings.ToLower(cName)
				addPartitionArtifact(cName, artifact)
		for _, container := range v.FlagDeclaration.Containers {
			if _, ok := config.PartitionBuildFlags[container]; !ok {
				config.PartitionBuildFlags[container] = &rc_proto.FlagArtifacts{}
			}
		default:
			addPartitionArtifact(container, artifact)
			config.PartitionBuildFlags[container].FlagArtifacts = append(config.PartitionBuildFlags[container].FlagArtifacts, artifact)
		}
	}
	config.ReleaseConfigArtifact = &rc_proto.ReleaseConfigArtifact{
+18 −13
Original line number Diff line number Diff line
@@ -118,9 +118,14 @@ func ReleaseConfigMapFactory(protoPath string) (m *ReleaseConfigMap) {

func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex int) error {
	m := ReleaseConfigMapFactory(path)
	if m.proto.DefaultContainer == nil {
	if m.proto.DefaultContainers == nil {
		return fmt.Errorf("Release config map %s lacks default_container", path)
	}
	for _, container := range m.proto.DefaultContainers {
		if !validContainer(container) {
			return fmt.Errorf("Release config map %s has invalid container %s", path, container)
		}
	}
	dir := filepath.Dir(path)
	// Record any aliases, checking for duplicates.
	for _, alias := range m.proto.Aliases {
@@ -138,9 +143,16 @@ func (configs *ReleaseConfigs) LoadReleaseConfigMap(path string, ConfigDirIndex
	err = WalkTextprotoFiles(dir, "flag_declarations", func(path string, d fs.DirEntry, err error) error {
		flagDeclaration := FlagDeclarationFactory(path)
		// Container must be specified.
		if flagDeclaration.Container == nil {
			flagDeclaration.Container = m.proto.DefaultContainer
		if flagDeclaration.Containers == nil {
			flagDeclaration.Containers = m.proto.DefaultContainers
		} else {
			for _, container := range flagDeclaration.Containers {
				if !validContainer(container) {
					return fmt.Errorf("Flag declaration %s has invalid container %s", path, container)
				}
			}
		}

		// TODO: once we have namespaces initialized, we can throw an error here.
		if flagDeclaration.Namespace == nil {
			flagDeclaration.Namespace = proto.String("android_UNKNOWN")
@@ -253,19 +265,12 @@ func (configs *ReleaseConfigs) WriteMakefile(outFile, targetRelease string) erro
		flag := myFlagArtifacts[name]
		decl := flag.FlagDeclaration

		// cName := strings.ToLower(rc_proto.Container_name[decl.GetContainer()])
		cName := strings.ToLower(decl.Container.String())
		if cName == strings.ToLower(rc_proto.Container_ALL.String()) {
			partitions["product"] = append(partitions["product"], name)
			partitions["system"] = append(partitions["system"], name)
			partitions["system_ext"] = append(partitions["system_ext"], name)
			partitions["vendor"] = append(partitions["vendor"], name)
		} else {
			partitions[cName] = append(partitions[cName], name)
		for _, container := range decl.Containers {
			partitions[container] = append(partitions[container], name)
		}
		value := MarshalValue(flag.Value)
		makeVars[name] = value
		addVar(name, "PARTITIONS", cName)
		addVar(name, "PARTITIONS", strings.Join(decl.Containers, " "))
		addVar(name, "DEFAULT", MarshalValue(decl.Value))
		addVar(name, "VALUE", value)
		addVar(name, "DECLARED_IN", *flag.Traces[0].Source)
+9 −1
Original line number Diff line number Diff line
@@ -20,13 +20,17 @@ import (
	"io/fs"
	"os"
	"path/filepath"
	"regexp"
	"strings"

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

var disableWarnings bool
var (
	disableWarnings    bool
	containerRegexp, _ = regexp.Compile("^[a-z][a-z0-9]*([._][a-z][a-z0-9]*)*$")
)

type StringList []string

@@ -128,6 +132,10 @@ func warnf(format string, args ...any) (n int, err error) {
	return 0, nil
}

func validContainer(container string) bool {
	return containerRegexp.MatchString(container)
}

// Returns the default value for release config artifacts.
func GetDefaultOutDir() string {
	outEnv := os.Getenv("OUT_DIR")
+68 −153

File changed.

Preview size limit exceeded, changes collapsed.

Loading