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

Commit 6f14c848 authored by Ramy Medhat's avatar Ramy Medhat Committed by Automerger Merge Worker
Browse files

[DO NOT MERGE] Add reasonable defaults to RBE configuration parameters. am: 19c39230

Original change: https://googleplex-android-review.googlesource.com/c/platform/build/soong/+/12595315

Change-Id: I684817629c64a6cb8a953ce10a7e98548343e1ee
parents 7abebafe 19c39230
Loading
Loading
Loading
Loading
+64 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package build
import (
	"io/ioutil"
	"log"
	"fmt"
	"os"
	"path/filepath"
	"runtime"
@@ -227,7 +228,7 @@ func NewConfig(ctx Context, args ...string) Config {
	ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)

	if ret.UseRBE() {
		for k, v := range getRBEVars(ctx, tmpDir) {
		for k, v := range getRBEVars(ctx, Config{ret}) {
			ret.environ.Set(k, v)
		}
	}
@@ -522,14 +523,74 @@ func (c *configImpl) StartRBE() bool {
	return true
}

func (c *configImpl) RBEStatsOutputDir() string {
func (c *configImpl) logDir() string {
	if c.Dist() {
		return filepath.Join(c.DistDir(), "logs")
	}
	return c.OutDir()
}

func (c *configImpl) rbeStatsOutputDir() string {
	for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} {
		if v, ok := c.environ.Get(f); ok {
			return v
		}
	}
	return c.logDir()
}

func (c *configImpl) rbeLogPath() string {
	for _, f := range []string{"RBE_log_path", "FLAG_log_path"} {
		if v, ok := c.environ.Get(f); ok {
			return v
		}
	}
	return fmt.Sprintf("text://%v/reproxy_log.txt", c.logDir())
}

func (c *configImpl) rbeExecRoot() string {
	for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} {
		if v, ok := c.environ.Get(f); ok {
			return v
		}
	}
	wd, err := os.Getwd()
	if err != nil {
		return ""
	}
	return wd
}

func (c *configImpl) rbeDir() string {
	if v, ok := c.environ.Get("RBE_DIR"); ok {
		return v
	}
	return "prebuilts/remoteexecution-client/live/"
}

func (c *configImpl) rbeReproxy() string {
	for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} {
		if v, ok := c.environ.Get(f); ok {
			return v
		}
	}
	return filepath.Join(c.rbeDir(), "reproxy")
}

func (c *configImpl) rbeAuth() (string, string) {
	credFlags := []string{"use_application_default_credentials", "use_gce_credentials", "credential_file"}
	for _, cf := range credFlags {
		for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} {
			if v, ok := c.environ.Get(f); ok {
				v = strings.TrimSpace(v)
				if v != "" && v != "false" && v != "0" {
					return "RBE_" + cf, v
				}
			}
		}
	}
	return "RBE_use_application_default_credentials", "true"
}

func (c *configImpl) UseRemoteBuild() bool {
	return c.UseGoma() || c.UseRBE()
+16 −6
Original line number Diff line number Diff line
@@ -37,10 +37,8 @@ const (

func rbeCommand(ctx Context, config Config, rbeCmd string) string {
	var cmdPath string
	if rbeDir, ok := config.Environment().Get("RBE_DIR"); ok {
	if rbeDir := config.rbeDir(); rbeDir != "" {
		cmdPath = filepath.Join(rbeDir, rbeCmd)
	} else if home, ok := config.Environment().Get("HOME"); ok {
		cmdPath = filepath.Join(home, "rbe", rbeCmd)
	} else {
		ctx.Fatalf("rbe command path not found")
	}
@@ -52,9 +50,18 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string {
	return cmdPath
}

func getRBEVars(ctx Context, tmpDir string) map[string]string {
func getRBEVars(ctx Context, config Config) map[string]string {
	rand.Seed(time.Now().UnixNano())
	return map[string]string{"RBE_server_address": fmt.Sprintf("unix://%v/reproxy_%v.sock", tmpDir, rand.Intn(1000))}
	vars := map[string]string{
		"RBE_server_address": fmt.Sprintf("unix://%v/reproxy_%v.sock", absPath(ctx, config.TempDir()), rand.Intn(1000)),
		"RBE_log_path":       config.rbeLogPath(),
		"RBE_re_proxy":       config.rbeReproxy(),
		"RBE_exec_root":      config.rbeExecRoot(),
		"RBE_output_dir":     config.rbeStatsOutputDir(),
	}
	k, v := config.rbeAuth()
	vars[k] = v
	return vars
}

func startRBE(ctx Context, config Config) {
@@ -102,7 +109,7 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) {
		return
	}

	outputDir := config.RBEStatsOutputDir()
	outputDir := config.rbeStatsOutputDir()
	if outputDir == "" {
		ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.")
	}
@@ -111,6 +118,9 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) {
	// Stop the proxy first in order to generate the RBE metrics protobuf file.
	stopRBE(ctx, config)

	if metricsFile == filename {
		return
	}
	if _, err := copyFile(metricsFile, filename); err != nil {
		ctx.Fatalf("failed to copy %q to %q: %v\n", metricsFile, filename, err)
	}
+6 −21
Original line number Diff line number Diff line
@@ -88,23 +88,12 @@ func TestDumpRBEMetricsErrors(t *testing.T) {
	ctx := testContext()
	tests := []struct {
		description      string
		rbeOutputDirDefined bool
		bootstrapProgram string
		expectedErr      string
	}{{
		description:      "output_dir not defined",
		bootstrapProgram: rbeBootstrapProgram,
		expectedErr:      "RBE output dir variable not defined",
	}, {
		description:      "stopRBE failed",
		rbeOutputDirDefined: true,
		bootstrapProgram: "#!/bin/bash\nexit 1\n",
		expectedErr:      "shutdown failed",
	}, {
		description:         "failed to copy metrics file",
		rbeOutputDirDefined: true,
		bootstrapProgram:    "#!/bin/bash\n",
		expectedErr:         "failed to copy",
	}}

	for _, tt := range tests {
@@ -132,10 +121,6 @@ func TestDumpRBEMetricsErrors(t *testing.T) {
			env.Set("OUT_DIR", tmpDir)
			env.Set("RBE_DIR", tmpDir)

			if tt.rbeOutputDirDefined {
				env.Set("RBE_output_dir", tmpDir)
			}

			config := Config{&configImpl{
				environ: env,
			}}