From 184366a18f97e9891135866aae126a9479465c85 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 21 Dec 2022 15:55:33 +0000 Subject: [PATCH] Stop changes to BAZEL_METRICS_DIR regenerating ninja file Bug: 262738679 Test: BAZEL_METRICS_DIR=dir1 m nothing BAZEL_METRICS_DIR=dir2 m nothing # Make sure that the second does not regenerate the ninja file. Change-Id: If30f13eee5d27d902c894af04af38078f437b6df --- android/bazel_handler.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/android/bazel_handler.go b/android/bazel_handler.go index e9c97d0ce..b56d31b43 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -437,16 +437,26 @@ func NewBazelContext(c *config) (BazelContext, error) { vars := []struct { name string ptr *string + + // True if the environment variable needs to be tracked so that changes to the variable + // cause the ninja file to be regenerated, false otherwise. False should only be set for + // environment variables that have no effect on the generated ninja file. + track bool }{ - {"BAZEL_HOME", &paths.homeDir}, - {"BAZEL_PATH", &paths.bazelPath}, - {"BAZEL_OUTPUT_BASE", &paths.outputBase}, - {"BAZEL_WORKSPACE", &paths.workspaceDir}, - {"BAZEL_METRICS_DIR", &paths.metricsDir}, - {"BAZEL_DEPS_FILE", &paths.bazelDepsFile}, + {"BAZEL_HOME", &paths.homeDir, true}, + {"BAZEL_PATH", &paths.bazelPath, true}, + {"BAZEL_OUTPUT_BASE", &paths.outputBase, true}, + {"BAZEL_WORKSPACE", &paths.workspaceDir, true}, + {"BAZEL_METRICS_DIR", &paths.metricsDir, false}, + {"BAZEL_DEPS_FILE", &paths.bazelDepsFile, true}, } for _, v := range vars { - if s := c.Getenv(v.name); len(s) > 1 { + if v.track { + if s := c.Getenv(v.name); len(s) > 1 { + *v.ptr = s + continue + } + } else if s, ok := c.env[v.name]; ok { *v.ptr = s } else { missing = append(missing, v.name)