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

Commit 498a732e authored by Ramy Medhat's avatar Ramy Medhat Committed by Kousik Kumar
Browse files

[DO NOT MERGE] Generate RBE socket address randomly for each invocation of soong.

Test: started soong multiple times and saw different socket files in
out/soong/.temp

Bug: b/166182389
Change-Id: Ib0087dd3867bdbf584c6868196070840cff291aa
Merged-In: Ib0087dd3867bdbf584c6868196070840cff291aa
parent fc5a03c8
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -152,7 +152,8 @@ func NewConfig(ctx Context, args ...string) Config {
	// Tell python not to spam the source tree with .pyc files.
	ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")

	ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
	tmpDir := absPath(ctx, ret.TempDir())
	ret.environ.Set("TMPDIR", tmpDir)

	// Precondition: the current directory is the top of the source tree
	if _, err := os.Stat(srcDirFileCheck); err != nil {
@@ -218,12 +219,19 @@ func NewConfig(ctx Context, args ...string) Config {
	} else {
		content = strconv.FormatInt(time.Now().Unix(), 10)
	}

	err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
	if err != nil {
		ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
	}
	ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)

	if ret.UseRBE() {
		for k, v := range getRBEVars(ctx, tmpDir) {
			ret.environ.Set(k, v)
		}
	}

	return Config{ret}
}

+8 −0
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@
package build

import (
	"fmt"
	"math/rand"
	"path/filepath"
	"time"

	"android/soong/ui/metrics"
)
@@ -24,6 +27,11 @@ const bootstrapCmd = "bootstrap"
const rbeLeastNProcs = 2500
const rbeLeastNFiles = 16000

func getRBEVars(ctx Context, tmpDir string) 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))}
}

func startRBE(ctx Context, config Config) {
	ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap")
	defer ctx.EndTrace()