Merge "Revert "Revert "Remove env config fetcher code""" into main am: 97e9b0cb8e
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2694552 Change-Id: I6ec5df70508b52b7a7e64a2888d1594fb36a0fb7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -40,9 +39,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
envConfigDir = "vendor/google/tools/soong_config"
|
envConfigDir = "vendor/google/tools/soong_config"
|
||||||
jsonSuffix = "json"
|
jsonSuffix = "json"
|
||||||
|
|
||||||
configFetcher = "vendor/google/tools/soong/expconfigfetcher"
|
|
||||||
envConfigFetchTimeout = 20 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -174,87 +170,6 @@ func checkTopDir(ctx Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchEnvConfig optionally fetches a configuration file that can then subsequently be
|
|
||||||
// loaded into Soong environment to control certain aspects of build behavior (e.g., enabling RBE).
|
|
||||||
// If a configuration file already exists on disk, the fetch is run in the background
|
|
||||||
// so as to NOT block the rest of the build execution.
|
|
||||||
func fetchEnvConfig(ctx Context, config *configImpl, envConfigName string) error {
|
|
||||||
configName := envConfigName + "." + jsonSuffix
|
|
||||||
expConfigFetcher := &smpb.ExpConfigFetcher{Filename: &configName}
|
|
||||||
defer func() {
|
|
||||||
ctx.Metrics.ExpConfigFetcher(expConfigFetcher)
|
|
||||||
}()
|
|
||||||
if !config.GoogleProdCredsExist() {
|
|
||||||
status := smpb.ExpConfigFetcher_MISSING_GCERT
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s, err := os.Stat(configFetcher)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if s.Mode()&0111 == 0 {
|
|
||||||
status := smpb.ExpConfigFetcher_ERROR
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return fmt.Errorf("configuration fetcher binary %v is not executable: %v", configFetcher, s.Mode())
|
|
||||||
}
|
|
||||||
|
|
||||||
configExists := false
|
|
||||||
outConfigFilePath := filepath.Join(config.OutDir(), configName)
|
|
||||||
if _, err := os.Stat(outConfigFilePath); err == nil {
|
|
||||||
configExists = true
|
|
||||||
}
|
|
||||||
|
|
||||||
tCtx, cancel := context.WithTimeout(ctx, envConfigFetchTimeout)
|
|
||||||
fetchStart := time.Now()
|
|
||||||
cmd := exec.CommandContext(tCtx, configFetcher, "-output_config_dir", config.OutDir(),
|
|
||||||
"-output_config_name", configName)
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
status := smpb.ExpConfigFetcher_ERROR
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchCfg := func() error {
|
|
||||||
if err := cmd.Wait(); err != nil {
|
|
||||||
status := smpb.ExpConfigFetcher_ERROR
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fetchEnd := time.Now()
|
|
||||||
expConfigFetcher.Micros = proto.Uint64(uint64(fetchEnd.Sub(fetchStart).Microseconds()))
|
|
||||||
expConfigFetcher.Filename = proto.String(outConfigFilePath)
|
|
||||||
|
|
||||||
if _, err := os.Stat(outConfigFilePath); err != nil {
|
|
||||||
status := smpb.ExpConfigFetcher_NO_CONFIG
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
status := smpb.ExpConfigFetcher_CONFIG
|
|
||||||
expConfigFetcher.Status = &status
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a config file does not exist, wait for the config file to be fetched. Otherwise
|
|
||||||
// fetch the config file in the background and return immediately.
|
|
||||||
if !configExists {
|
|
||||||
defer cancel()
|
|
||||||
return fetchCfg()
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer cancel()
|
|
||||||
if err := fetchCfg(); err != nil {
|
|
||||||
ctx.Verbosef("Failed to fetch config file %v: %v\n", configName, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadEnvConfig(ctx Context, config *configImpl, bc string) error {
|
func loadEnvConfig(ctx Context, config *configImpl, bc string) error {
|
||||||
if bc == "" {
|
if bc == "" {
|
||||||
return nil
|
return nil
|
||||||
@@ -368,9 +283,6 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||||||
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
|
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
|
||||||
|
|
||||||
if bc != "" {
|
if bc != "" {
|
||||||
if err := fetchEnvConfig(ctx, ret, bc); err != nil {
|
|
||||||
ctx.Verbosef("Failed to fetch config file: %v\n", err)
|
|
||||||
}
|
|
||||||
if err := loadEnvConfig(ctx, ret, bc); err != nil {
|
if err := loadEnvConfig(ctx, ret, bc); err != nil {
|
||||||
ctx.Fatalln("Failed to parse env config files: %v", err)
|
ctx.Fatalln("Failed to parse env config files: %v", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user