Merge "Allow product-specific release configs." into main

This commit is contained in:
LaMont Jones
2024-06-05 00:07:28 +00:00
committed by Gerrit Code Review
3 changed files with 23 additions and 5 deletions

View File

@@ -48,6 +48,11 @@ type Flags struct {
// Panic on errors. // Panic on errors.
debug bool debug bool
// Allow missing release config.
// If true, and we cannot find the named release config, values for
// `trunk_staging` will be used.
allowMissing bool
} }
type CommandFunc func(*rc_lib.ReleaseConfigs, Flags, string, []string) error type CommandFunc func(*rc_lib.ReleaseConfigs, Flags, string, []string) error
@@ -284,7 +289,7 @@ func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, a
} }
// Reload the release configs. // Reload the release configs.
configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, commonFlags.targetReleases[0], commonFlags.useGetBuildVar) configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, commonFlags.targetReleases[0], commonFlags.useGetBuildVar, commonFlags.allowMissing)
if err != nil { if err != nil {
return err return err
} }
@@ -307,6 +312,7 @@ func main() {
flag.Var(&commonFlags.maps, "map", "path to a release_config_map.textproto. may be repeated") flag.Var(&commonFlags.maps, "map", "path to a release_config_map.textproto. may be repeated")
flag.StringVar(&commonFlags.outDir, "out-dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created") flag.StringVar(&commonFlags.outDir, "out-dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
flag.Var(&commonFlags.targetReleases, "release", "TARGET_RELEASE for this build") flag.Var(&commonFlags.targetReleases, "release", "TARGET_RELEASE for this build")
flag.BoolVar(&commonFlags.allowMissing, "allow-missing", false, "Use trunk_staging values if release not found")
flag.BoolVar(&commonFlags.allReleases, "all-releases", false, "operate on all releases. (Ignored for set command)") flag.BoolVar(&commonFlags.allReleases, "all-releases", false, "operate on all releases. (Ignored for set command)")
flag.BoolVar(&commonFlags.useGetBuildVar, "use-get-build-var", true, "use get_build_var PRODUCT_RELEASE_CONFIG_MAPS to get needed maps") flag.BoolVar(&commonFlags.useGetBuildVar, "use-get-build-var", true, "use get_build_var PRODUCT_RELEASE_CONFIG_MAPS to get needed maps")
flag.BoolVar(&commonFlags.debug, "debug", false, "turn on debugging output for errors") flag.BoolVar(&commonFlags.debug, "debug", false, "turn on debugging output for errors")
@@ -342,7 +348,7 @@ func main() {
if relName == "--all" || relName == "-all" { if relName == "--all" || relName == "-all" {
commonFlags.allReleases = true commonFlags.allReleases = true
} }
configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName, commonFlags.useGetBuildVar) configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName, commonFlags.useGetBuildVar, commonFlags.allowMissing)
if err != nil { if err != nil {
errorExit(err) errorExit(err)
} }

View File

@@ -34,7 +34,7 @@ func main() {
var json, pb, textproto, inheritance bool var json, pb, textproto, inheritance bool
var product string var product string
var allMake bool var allMake bool
var useBuildVar bool var useBuildVar, allowMissing bool
var guard bool var guard bool
defaultRelease := os.Getenv("TARGET_RELEASE") defaultRelease := os.Getenv("TARGET_RELEASE")
@@ -47,6 +47,7 @@ func main() {
flag.BoolVar(&quiet, "quiet", false, "disable warning messages") flag.BoolVar(&quiet, "quiet", false, "disable warning messages")
flag.Var(&releaseConfigMapPaths, "map", "path to a release_config_map.textproto. may be repeated") flag.Var(&releaseConfigMapPaths, "map", "path to a release_config_map.textproto. may be repeated")
flag.StringVar(&targetRelease, "release", defaultRelease, "TARGET_RELEASE for this build") flag.StringVar(&targetRelease, "release", defaultRelease, "TARGET_RELEASE for this build")
flag.BoolVar(&allowMissing, "allow-missing", false, "Use trunk_staging values if release not found")
flag.StringVar(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created") 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(&textproto, "textproto", true, "write artifacts as text protobuf")
flag.BoolVar(&json, "json", true, "write artifacts as json") flag.BoolVar(&json, "json", true, "write artifacts as json")
@@ -65,7 +66,7 @@ func main() {
if err = os.Chdir(top); err != nil { if err = os.Chdir(top); err != nil {
panic(err) panic(err)
} }
configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease, useBuildVar) configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease, useBuildVar, allowMissing)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -76,6 +76,11 @@ type ReleaseConfigs struct {
// A map from the config directory to its order in the list of config // A map from the config directory to its order in the list of config
// directories. // directories.
configDirIndexes ReleaseConfigDirMap configDirIndexes ReleaseConfigDirMap
// True if we should allow a missing primary release config. In this
// case, we will substitute `trunk_staging` values, but the release
// config will not be in ALL_RELEASE_CONFIGS_FOR_PRODUCT.
allowMissing bool
} }
func (configs *ReleaseConfigs) WriteInheritanceGraph(outFile string) error { func (configs *ReleaseConfigs) WriteInheritanceGraph(outFile string) error {
@@ -374,6 +379,11 @@ func (configs *ReleaseConfigs) GetReleaseConfig(name string) (*ReleaseConfig, er
if config, ok := configs.ReleaseConfigs[name]; ok { if config, ok := configs.ReleaseConfigs[name]; ok {
return config, nil return config, nil
} }
if configs.allowMissing {
if config, ok := configs.ReleaseConfigs["trunk_staging"]; ok {
return config, nil
}
}
return nil, fmt.Errorf("Missing config %s. Trace=%v", name, trace) return nil, fmt.Errorf("Missing config %s. Trace=%v", name, trace)
} }
@@ -521,7 +531,7 @@ func (configs *ReleaseConfigs) GenerateReleaseConfigs(targetRelease string) erro
return nil return nil
} }
func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string, useBuildVar bool) (*ReleaseConfigs, error) { func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string, useBuildVar, allowMissing bool) (*ReleaseConfigs, error) {
var err error var err error
if len(releaseConfigMapPaths) == 0 { if len(releaseConfigMapPaths) == 0 {
@@ -538,6 +548,7 @@ func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease strin
} }
configs := ReleaseConfigsFactory() configs := ReleaseConfigsFactory()
configs.allowMissing = allowMissing
mapsRead := make(map[string]bool) mapsRead := make(map[string]bool)
var idx int var idx int
for _, releaseConfigMapPath := range releaseConfigMapPaths { for _, releaseConfigMapPath := range releaseConfigMapPaths {