From c8f6cc24f9ee537f4b1af7cbb273a405749294e8 Mon Sep 17 00:00:00 2001 From: Ramy Medhat Date: Fri, 31 Mar 2023 09:50:34 -0400 Subject: [PATCH] Enable reclient cache directory. The cache directory stores files that should persist between builds. Currently it will contain reproxy.creds, which caches the authentication mechanism and token used to make subsequent builds faster. Test: m nothing build takes 7s Change-Id: Iaaa20b92630405918e5e91e09eca6c798b8fc872 --- ui/build/build.go | 10 ++++++++-- ui/build/config.go | 9 +++++++++ ui/build/rbe.go | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index edc595d16..6874ef74d 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -259,10 +259,16 @@ func Build(ctx Context, config Config) { startGoma(ctx, config) } + rbeCh := make(chan bool) if config.StartRBE() { cleanupRBELogsDir(ctx, config) - startRBE(ctx, config) + go func() { + startRBE(ctx, config) + close(rbeCh) + }() defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb")) + } else { + close(rbeCh) } if what&RunProductConfig != 0 { @@ -315,11 +321,11 @@ func Build(ctx Context, config Config) { testForDanglingRules(ctx, config) } + <-rbeCh if what&RunNinja != 0 { if what&RunKati != 0 { installCleanIfNecessary(ctx, config) } - runNinjaForBuild(ctx, config) } diff --git a/ui/build/config.go b/ui/build/config.go index a755d14fd..bf4aec9b9 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -1374,6 +1374,15 @@ func (c *configImpl) rbeProxyLogsDir() string { return filepath.Join(buildTmpDir, "rbe") } +func (c *configImpl) rbeCacheDir() string { + for _, f := range []string{"RBE_cache_dir", "FLAG_cache_dir"} { + if v, ok := c.environ.Get(f); ok { + return v + } + } + return shared.JoinPath(c.SoongOutDir(), "rbe") +} + func (c *configImpl) shouldCleanupRBELogsDir() bool { // Perform a log directory cleanup only when the log directory // is auto created by the build rather than user-specified. diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 1d1721623..6479925dd 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -60,6 +60,7 @@ func getRBEVars(ctx Context, config Config) map[string]string { "RBE_exec_root": config.rbeExecRoot(), "RBE_output_dir": config.rbeProxyLogsDir(), "RBE_proxy_log_dir": config.rbeProxyLogsDir(), + "RBE_cache_dir": config.rbeCacheDir(), "RBE_platform": "container-image=" + remoteexec.DefaultImage, } if config.StartRBE() {