release_config: better default map paths
- Automatically determine the top of the workspace. - build-flag defaults to using `get_build_var` to get product specific release config maps. - release-config defaults to using PRODUCT_RELEASE_CONFIG_MAPS but does not use `get_build_var` unless the argument is given. Bug: 328495189 Test: manual Change-Id: I4ba3c5dfab43c4ebc3eeda13318f42e886dada4e
This commit is contained in:
@@ -184,6 +184,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
var commonFlags Flags
|
var commonFlags Flags
|
||||||
var configs *rc_lib.ReleaseConfigs
|
var configs *rc_lib.ReleaseConfigs
|
||||||
|
var useBuildVar bool
|
||||||
|
|
||||||
outEnv := os.Getenv("OUT_DIR")
|
outEnv := os.Getenv("OUT_DIR")
|
||||||
if outEnv == "" {
|
if outEnv == "" {
|
||||||
@@ -195,6 +196,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(&useBuildVar, "use_get_build_var", true, "use get_build_var PRODUCT_RELEASE_CONFIG_MAPS")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if commonFlags.quiet {
|
if commonFlags.quiet {
|
||||||
@@ -215,7 +217,7 @@ func main() {
|
|||||||
// If the users said `--release --all`, grab trunk staging for simplicity.
|
// If the users said `--release --all`, grab trunk staging for simplicity.
|
||||||
relName = "trunk_staging"
|
relName = "trunk_staging"
|
||||||
}
|
}
|
||||||
configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName)
|
configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -311,8 +311,9 @@ func main() {
|
|||||||
var dirs rc_lib.StringList
|
var dirs rc_lib.StringList
|
||||||
var namespacesFile string
|
var namespacesFile string
|
||||||
var descriptionsFile string
|
var descriptionsFile string
|
||||||
|
defaultTopDir, err := rc_lib.GetTopDir()
|
||||||
|
|
||||||
flag.StringVar(&top, "top", ".", "path to top of workspace")
|
flag.StringVar(&top, "top", defaultTopDir, "path to top of workspace")
|
||||||
flag.Var(&dirs, "dir", "directory to process, relative to the top of the workspace")
|
flag.Var(&dirs, "dir", "directory to process, relative to the top of the workspace")
|
||||||
flag.StringVar(&namespacesFile, "namespaces", "", "location of file with 'flag_name namespace' information")
|
flag.StringVar(&namespacesFile, "namespaces", "", "location of file with 'flag_name namespace' information")
|
||||||
flag.StringVar(&descriptionsFile, "descriptions", "", "location of file with 'directory description' information")
|
flag.StringVar(&descriptionsFile, "descriptions", "", "location of file with 'directory description' information")
|
||||||
|
@@ -34,6 +34,7 @@ func main() {
|
|||||||
var json, pb, textproto bool
|
var json, pb, textproto bool
|
||||||
var product string
|
var product string
|
||||||
var allMake bool
|
var allMake bool
|
||||||
|
var useBuildVar bool
|
||||||
|
|
||||||
defaultRelease := os.Getenv("TARGET_RELEASE")
|
defaultRelease := os.Getenv("TARGET_RELEASE")
|
||||||
if defaultRelease == "" {
|
if defaultRelease == "" {
|
||||||
@@ -50,6 +51,8 @@ func main() {
|
|||||||
flag.BoolVar(&json, "json", true, "write artifacts as json")
|
flag.BoolVar(&json, "json", true, "write artifacts as json")
|
||||||
flag.BoolVar(&pb, "pb", true, "write artifacts as binary protobuf")
|
flag.BoolVar(&pb, "pb", true, "write artifacts as binary protobuf")
|
||||||
flag.BoolVar(&allMake, "all_make", true, "write makefiles for all release configs")
|
flag.BoolVar(&allMake, "all_make", true, "write makefiles for all release configs")
|
||||||
|
flag.BoolVar(&useBuildVar, "use_get_build_var", false, "use get_build_var PRODUCT_RELEASE_CONFIG_MAPS")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if quiet {
|
if quiet {
|
||||||
@@ -59,7 +62,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)
|
configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease, useBuildVar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -365,11 +365,14 @@ func (configs *ReleaseConfigs) GenerateReleaseConfigs(targetRelease string) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string) (*ReleaseConfigs, error) {
|
func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string, useBuildVar bool) (*ReleaseConfigs, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if len(releaseConfigMapPaths) == 0 {
|
if len(releaseConfigMapPaths) == 0 {
|
||||||
releaseConfigMapPaths = GetDefaultMapPaths()
|
releaseConfigMapPaths, err = GetDefaultMapPaths(useBuildVar)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if len(releaseConfigMapPaths) == 0 {
|
if len(releaseConfigMapPaths) == 0 {
|
||||||
return nil, fmt.Errorf("No maps found")
|
return nil, fmt.Errorf("No maps found")
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -145,22 +146,64 @@ func GetDefaultOutDir() string {
|
|||||||
return filepath.Join(outEnv, "soong", "release-config")
|
return filepath.Join(outEnv, "soong", "release-config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the top of the workspace.
|
||||||
|
//
|
||||||
|
// This mirrors the logic in build/envsetup.sh's gettop().
|
||||||
|
func GetTopDir() (topDir string, err error) {
|
||||||
|
workingDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
topFile := "build/make/core/envsetup.mk"
|
||||||
|
for topDir = workingDir; topDir != "/"; topDir = filepath.Dir(topDir) {
|
||||||
|
if _, err = os.Stat(filepath.Join(topDir, topFile)); err == nil {
|
||||||
|
return filepath.Rel(workingDir, topDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("Unable to locate top of workspace")
|
||||||
|
}
|
||||||
|
|
||||||
// Return the default list of map files to use.
|
// Return the default list of map files to use.
|
||||||
func GetDefaultMapPaths() StringList {
|
func GetDefaultMapPaths(queryMaps bool) (defaultLocations StringList, err error) {
|
||||||
var defaultMapPaths StringList
|
var defaultMapPaths StringList
|
||||||
defaultLocations := StringList{
|
workingDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
os.Chdir(workingDir)
|
||||||
|
}()
|
||||||
|
topDir, err := GetTopDir()
|
||||||
|
os.Chdir(topDir)
|
||||||
|
|
||||||
|
defaultLocations = StringList{
|
||||||
"build/release/release_config_map.textproto",
|
"build/release/release_config_map.textproto",
|
||||||
"vendor/google_shared/build/release/release_config_map.textproto",
|
"vendor/google_shared/build/release/release_config_map.textproto",
|
||||||
"vendor/google/release/release_config_map.textproto",
|
"vendor/google/release/release_config_map.textproto",
|
||||||
}
|
}
|
||||||
for _, path := range defaultLocations {
|
for _, path := range defaultLocations {
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err = os.Stat(path); err == nil {
|
||||||
defaultMapPaths = append(defaultMapPaths, path)
|
defaultMapPaths = append(defaultMapPaths, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prodMaps := os.Getenv("PRODUCT_RELEASE_CONFIG_MAPS")
|
|
||||||
if prodMaps != "" {
|
var prodMaps string
|
||||||
|
if queryMaps {
|
||||||
|
getBuildVar := exec.Command("build/soong/soong_ui.bash", "--dumpvar-mode", "PRODUCT_RELEASE_CONFIG_MAPS")
|
||||||
|
var stdout strings.Builder
|
||||||
|
getBuildVar.Stdin = strings.NewReader("")
|
||||||
|
getBuildVar.Stdout = &stdout
|
||||||
|
err = getBuildVar.Run()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prodMaps = stdout.String()
|
||||||
|
} else {
|
||||||
|
prodMaps = os.Getenv("PRODUCT_RELEASE_CONFIG_MAPS")
|
||||||
|
}
|
||||||
|
prodMaps = strings.TrimSpace(prodMaps)
|
||||||
|
if len(prodMaps) > 0 {
|
||||||
defaultMapPaths = append(defaultMapPaths, strings.Split(prodMaps, " ")...)
|
defaultMapPaths = append(defaultMapPaths, strings.Split(prodMaps, " ")...)
|
||||||
}
|
}
|
||||||
return defaultMapPaths
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user