From 6f33a1c54e517d7343c36d0479713655a19f3224 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 13 Sep 2016 16:46:10 +0000 Subject: Track client environment in Skyframe ...to determine which actions have to be recomputed based on changes to the client environment. Note that this change does it the simple way and reconsideres all actions on a changed client environment, while still only reexecuting those, where the part that was inherited from the environment actually did change. -- Change-Id: Ie1116d094642165e5e959447a6fcf49d19b37d6e Reviewed-on: https://bazel-review.googlesource.com/#/c/5431 MOS_MIGRATED_REVID=133010705 --- .../build/lib/runtime/CommandEnvironment.java | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/runtime') diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java index 1ace4adb91..bb6fb831a6 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java @@ -57,10 +57,11 @@ import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; @@ -77,7 +78,8 @@ public final class CommandEnvironment { private final Reporter reporter; private final EventBus eventBus; private final BlazeModule.ModuleEnvironment blazeModuleEnvironment; - private final Map clientEnv = new HashMap<>(); + private final Map clientEnv = new TreeMap<>(); + private final Set visibleClientEnv = new TreeSet<>(); private final TimestampGranularityMonitor timestampGranularityMonitor; private String[] crashData; @@ -163,6 +165,21 @@ public final class CommandEnvironment { return Collections.unmodifiableMap(clientEnv); } + /** + * Return an ordered version of the client environment restricted to those variables + * whitelisted by the command-line options to be inheritable by actions. + */ + private Map getCommandlineWhitelistedClientEnv() { + Map visibleEnv = new TreeMap<>(); + for (String var : visibleClientEnv) { + String value = clientEnv.get(var); + if (value != null) { + visibleEnv.put(var, value); + } + } + return Collections.unmodifiableMap(visibleEnv); + } + @VisibleForTesting void updateClientEnv(List> clientEnvList, boolean ignoreClientEnv) { Preconditions.checkState(clientEnv.isEmpty()); @@ -407,8 +424,16 @@ public final class CommandEnvironment { if (!skyframeExecutor.hasIncrementalState()) { skyframeExecutor.resetEvaluator(); } - skyframeExecutor.sync(reporter, packageCacheOptions, getOutputBase(), - getWorkingDirectory(), defaultsPackageContents, getCommandId(), + skyframeExecutor.sync( + reporter, + packageCacheOptions, + getOutputBase(), + getWorkingDirectory(), + defaultsPackageContents, + getCommandId(), + // TODO(bazel-team): this optimization disallows rule-specified additional dependencies + // on the client environment! + getCommandlineWhitelistedClientEnv(), timestampGranularityMonitor); } @@ -499,6 +524,17 @@ public final class CommandEnvironment { testEnv.put(entry.getKey(), entry.getValue()); } + // Compute the set of environment variables that are whitelisted on the commandline + // for inheritence. + for (Map.Entry entry : + optionsParser.getOptions(BuildConfiguration.Options.class).actionEnvironment) { + if (entry.getValue() == null) { + visibleClientEnv.add(entry.getKey()); + } else { + visibleClientEnv.remove(entry.getKey()); + } + } + try { for (Map.Entry entry : testEnv.entrySet()) { if (entry.getValue() == null) { -- cgit v1.2.3