Merge "implement USE_BAZEL_VERSION for m"

This commit is contained in:
Treehugger Robot
2023-06-01 22:06:17 +00:00
committed by Gerrit Code Review
4 changed files with 36 additions and 10 deletions

View File

@@ -26,10 +26,11 @@ import (
"time" "time"
) )
// Logs fatal events of ProxyServer. // Logs events of ProxyServer.
type ServerLogger interface { type ServerLogger interface {
Fatal(v ...interface{}) Fatal(v ...interface{})
Fatalf(format string, v ...interface{}) Fatalf(format string, v ...interface{})
Println(v ...interface{})
} }
// CmdRequest is a request to the Bazel Proxy server. // CmdRequest is a request to the Bazel Proxy server.
@@ -71,9 +72,10 @@ type ProxyClient struct {
// The ProxyServer will only live as long as soong_ui does; the // The ProxyServer will only live as long as soong_ui does; the
// underlying Bazel server will live past the duration of the build. // underlying Bazel server will live past the duration of the build.
type ProxyServer struct { type ProxyServer struct {
logger ServerLogger logger ServerLogger
outDir string outDir string
workspaceDir string workspaceDir string
bazeliskVersion string
// The server goroutine will listen on this channel and stop handling requests // The server goroutine will listen on this channel and stop handling requests
// once it is written to. // once it is written to.
done chan struct{} done chan struct{}
@@ -119,12 +121,17 @@ func (b *ProxyClient) IssueCommand(req CmdRequest) (CmdResponse, error) {
} }
// NewProxyServer is a constructor for a ProxyServer. // NewProxyServer is a constructor for a ProxyServer.
func NewProxyServer(logger ServerLogger, outDir string, workspaceDir string) *ProxyServer { func NewProxyServer(logger ServerLogger, outDir string, workspaceDir string, bazeliskVersion string) *ProxyServer {
if len(bazeliskVersion) > 0 {
logger.Println("** Using Bazelisk for this build, due to env var USE_BAZEL_VERSION=" + bazeliskVersion + " **")
}
return &ProxyServer{ return &ProxyServer{
logger: logger, logger: logger,
outDir: outDir, outDir: outDir,
workspaceDir: workspaceDir, workspaceDir: workspaceDir,
done: make(chan struct{}), done: make(chan struct{}),
bazeliskVersion: bazeliskVersion,
} }
} }
@@ -155,6 +162,9 @@ func (b *ProxyServer) handleRequest(conn net.Conn) error {
return fmt.Errorf("Error decoding request: %s", err) return fmt.Errorf("Error decoding request: %s", err)
} }
if len(b.bazeliskVersion) > 0 {
req.Env = append(req.Env, "USE_BAZEL_VERSION="+b.bazeliskVersion)
}
stdout, stderr, cmdErr := ExecBazel("./build/bazel/bin/bazel", b.workspaceDir, req) stdout, stderr, cmdErr := ExecBazel("./build/bazel/bin/bazel", b.workspaceDir, req)
errorString := "" errorString := ""
if cmdErr != nil { if cmdErr != nil {

View File

@@ -552,6 +552,12 @@ func main() {
} }
writeMetrics(configuration, ctx.EventHandler, metricsDir) writeMetrics(configuration, ctx.EventHandler, metricsDir)
} }
// Register this environment variablesas being an implicit dependencies of
// soong_build. Changes to this environment variable will result in
// retriggering soong_build.
configuration.Getenv("USE_BAZEL_VERSION")
writeUsedEnvironmentFile(configuration) writeUsedEnvironmentFile(configuration)
// Touch the output file so that it's the newest file created by soong_build. // Touch the output file so that it's the newest file created by soong_build.

View File

@@ -1642,6 +1642,16 @@ func (c *configImpl) IsPersistentBazelEnabled() bool {
return c.Environment().IsEnvTrue("USE_PERSISTENT_BAZEL") return c.Environment().IsEnvTrue("USE_PERSISTENT_BAZEL")
} }
// GetBazeliskBazelVersion returns the Bazel version to use for this build,
// or the empty string if the current canonical prod Bazel should be used.
// This environment variable should only be set to debug the build system.
// The Bazel version, if set, will be passed to Bazelisk, and Bazelisk will
// handle downloading and invoking the correct Bazel binary.
func (c *configImpl) GetBazeliskBazelVersion() string {
value, _ := c.Environment().Get("USE_BAZEL_VERSION")
return value
}
func (c *configImpl) BazelModulesForceEnabledByFlag() string { func (c *configImpl) BazelModulesForceEnabledByFlag() string {
return c.bazelForceEnabledModules return c.bazelForceEnabledModules
} }

View File

@@ -533,7 +533,7 @@ func runSoong(ctx Context, config Config) {
defer ctx.EndTrace() defer ctx.EndTrace()
if config.IsPersistentBazelEnabled() { if config.IsPersistentBazelEnabled() {
bazelProxy := bazel.NewProxyServer(ctx.Logger, config.OutDir(), filepath.Join(config.SoongOutDir(), "workspace")) bazelProxy := bazel.NewProxyServer(ctx.Logger, config.OutDir(), filepath.Join(config.SoongOutDir(), "workspace"), config.GetBazeliskBazelVersion())
bazelProxy.Start() bazelProxy.Start()
defer bazelProxy.Close() defer bazelProxy.Close()
} }