aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2017-01-10 17:20:05 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-01-10 19:42:25 +0000
commitffbddeb49b2aa8b2b8b25a9f66667cfd10cb31f9 (patch)
tree417889527b9b16252a284a37bc8bc4c6cc7f1057 /src/main/java/com/google/devtools/build/lib/runtime
parent9bd768c05c474c80e6ae7698573209becb5fcc17 (diff)
Skylark repositories: propage value from --action_env to repository_ctx.environ
The environment is now computed with a mixture of the client environment and the values specified by the --action_env flag. If a user want to overwrite its environment for skylark repository, they can do `--action_env FOO=BAR` and the repository will see FOO as having the value BAR, whichever value is set in the client environment. Also propagate it to all repository functions, and deduplicate the way the client environment is passed to repository functions. Design doc: https://bazel.build/designs/2016/10/18/repository-invalidation.html [step 1] RELNOTES[INC]: repository_ctx environment is now affected by --action_env flag (value from the client environment will be replaced by value given on the command line through --action_env). -- Change-Id: I131a9695439aa9949d5001f820e2ae450e41332f Reviewed-on: https://cr.bazel.build/7971 PiperOrigin-RevId: 144091492 MOS_MIGRATED_REVID=144091492
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java16
1 files changed, 16 insertions, 0 deletions
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 264fa22195..cc473da5e6 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
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.analysis.SkyframePackageRootResolver;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
+import com.google.devtools.build.lib.analysis.config.DefaultsPackage;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Reporter;
@@ -82,6 +83,7 @@ public final class CommandEnvironment {
private final BlazeModule.ModuleEnvironment blazeModuleEnvironment;
private final Map<String, String> clientEnv = new TreeMap<>();
private final Set<String> visibleClientEnv = new TreeSet<>();
+ private final Map<String, String> actionClientEnv = new TreeMap<>();
private final TimestampGranularityMonitor timestampGranularityMonitor;
private final Thread commandThread;
@@ -592,6 +594,11 @@ public final class CommandEnvironment {
// Start the performance and memory profilers.
runtime.beforeCommand(this, options, execStartTimeNanos);
+ // actionClientEnv contains the environment where values from actionEnvironment are
+ // overridden.
+ actionClientEnv.clear();
+ actionClientEnv.putAll(clientEnv);
+
if (command.builds()) {
Map<String, String> testEnv = new TreeMap<>();
for (Map.Entry<String, String> entry :
@@ -607,6 +614,7 @@ public final class CommandEnvironment {
visibleClientEnv.add(entry.getKey());
} else {
visibleClientEnv.remove(entry.getKey());
+ actionClientEnv.put(entry.getKey(), entry.getValue());
}
}
@@ -644,4 +652,12 @@ public final class CommandEnvironment {
}
return workspace.getOutputBaseFilesystemTypeName();
}
+
+ /**
+ * Returns the client environment for which value specified in the command line with the flag
+ * --action_env have been enforced.
+ */
+ public Map<String, String> getActionClientEnv() {
+ return Collections.unmodifiableMap(actionClientEnv);
+ }
}