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

Commit 76e05c8c authored by LaMont Jones's avatar LaMont Jones Committed by Gerrit Code Review
Browse files

Merge changes If068597b,Icbadbe6d into main

* changes:
  release_config: make the code more sharable
  release_config: add namespace to proto
parents 1a8906d9 ac79679f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -3,28 +3,16 @@ package {
}

bootstrap_go_package {
    name: "release-config",
    pkgPath: "android/soong/cmd/release_config",
    name: "soong-cmd-release_config-release_config",
    pkgPath: "android/soong/cmd/release_config/release_config",
    deps: [
        "golang-protobuf-encoding-prototext",
        "golang-protobuf-reflect-protoreflect",
        "golang-protobuf-runtime-protoimpl",
        "soong-cmd-release-config-proto",
        "soong-cmd-release_config-proto",
        "soong-cmd-release_config-lib",
    ],
    srcs: [
        "main.go",
    ],
}

bootstrap_go_package {
    name: "soong-cmd-release-config-proto",
    pkgPath: "android/soong/cmd/release_config/release_config_proto",
    deps: [
        "golang-protobuf-reflect-protoreflect",
        "golang-protobuf-runtime-protoimpl",
    ],
    srcs: [
        "release_config_proto/build_flags_out.pb.go",
        "release_config_proto/build_flags_src.pb.go",
    ],
}
+57 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"flag"
	"os"

	rc_lib "android/soong/cmd/release_config/release_config_lib"
)

func main() {
	var top string
	var releaseConfigMapPaths rc_lib.StringList
	var targetRelease string
	var outputDir string
	var err error
	var configs *rc_lib.ReleaseConfigs

	flag.StringVar(&top, "top", ".", "path to top of workspace")
	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(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
	flag.Parse()

	if err = os.Chdir(top); err != nil {
		panic(err)
	}
	configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease)
	if err != nil {
		panic(err)
	}
	err = os.MkdirAll(outputDir, 0775)
	if err != nil {
		panic(err)
	}
	err = configs.DumpMakefile(outputDir, targetRelease)
	if err != nil {
		panic(err)
	}
	err = configs.DumpArtifact(outputDir)
	if err != nil {
		panic(err)
	}
}
+36 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

bootstrap_go_package {
    name: "soong-cmd-release_config-lib",
    pkgPath: "android/soong/release_config/release_config_lib",
    deps: [
        "golang-protobuf-encoding-prototext",
        "golang-protobuf-reflect-protoreflect",
        "golang-protobuf-runtime-protoimpl",
        "soong-cmd-release_config-proto",
    ],
    srcs: [
        "flag_artifact.go",
        "flag_declaration.go",
        "flag_value.go",
        "release_config.go",
        "release_configs.go",
        "util.go",
    ],
}
+89 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package release_config_lib

import (
	"fmt"

	"android/soong/cmd/release_config/release_config_proto"

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

type FlagArtifact struct {
	FlagDeclaration *release_config_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

	// Assigned value
	Value *release_config_proto.Value
}

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

func (src *FlagArtifact) Clone() *FlagArtifact {
	value := &release_config_proto.Value{}
	proto.Merge(value, src.Value)
	return &FlagArtifact{
		FlagDeclaration: src.FlagDeclaration,
		Traces:          src.Traces,
		Value:           value,
	}
}

func (src FlagArtifacts) Clone() (dst FlagArtifacts) {
	if dst == nil {
		dst = make(FlagArtifacts)
	}
	for k, v := range src {
		dst[k] = v.Clone()
	}
	return
}

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})
	if fa.Value.GetObsolete() {
		return fmt.Errorf("Attempting to set obsolete flag %s. Trace=%v", name, fa.Traces)
	}
	switch val := flagValue.proto.Value.Val.(type) {
	case *release_config_proto.Value_StringValue:
		fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_StringValue{val.StringValue}}
	case *release_config_proto.Value_BoolValue:
		fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_BoolValue{val.BoolValue}}
	case *release_config_proto.Value_Obsolete:
		if !val.Obsolete {
			return fmt.Errorf("%s: Cannot set obsolete=false.  Trace=%v", name, fa.Traces)
		}
		fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_Obsolete{true}}
	default:
		return fmt.Errorf("Invalid type for flag_value: %T.  Trace=%v", val, fa.Traces)
	}
	return nil
}

func (fa *FlagArtifact) Marshal() (*release_config_proto.FlagArtifact, error) {
	return &release_config_proto.FlagArtifact{
		FlagDeclaration: fa.FlagDeclaration,
		Value:           fa.Value,
		Traces:          fa.Traces,
	}, nil
}
+27 −0
Original line number Diff line number Diff line
// Copyright 2024 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package release_config_lib

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

func FlagDeclarationFactory(protoPath string) (fd *release_config_proto.FlagDeclaration) {
	fd = &release_config_proto.FlagDeclaration{}
	if protoPath != "" {
		LoadTextproto(protoPath, fd)
	}
	return fd
}
Loading