aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar lpino <lpino@google.com>2017-04-07 10:22:28 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-04-07 16:44:42 +0200
commit1fde2308afc7b323ca3c57b7176c0ea18ad52bbb (patch)
tree25e62c222e482f9c708f909a7868c14267ccf95d /src/main/java/com/google/devtools/build/lib
parent184faf617c4c90adfc33b7217aac53aab98354b2 (diff)
PiperOrigin-RevId: 152483983
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java18
2 files changed, 32 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
index 98c56c48c8..5be28a29e4 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
@@ -192,7 +192,20 @@ public final class BlazeWorkspace {
*/
public CommandEnvironment initCommand() {
CommandEnvironment env = new CommandEnvironment(
- runtime, this, new EventBus(eventBusExceptionHandler), Thread.currentThread());
+ runtime, this, new EventBus(eventBusExceptionHandler), Thread.currentThread(), null, null);
+ skyframeExecutor.setClientEnv(env.getClientEnv());
+ return env;
+ }
+
+ /**
+ * Same as {@code #initCommand()} but setting the command name and the options manually since
+ * those values are set by {@code CommandEnvironment#beforeCommand()} which is not called for
+ * testing. Use ONLY for testing purposes.
+ */
+ public CommandEnvironment initCommandForTesting(String commandName, OptionsProvider options) {
+ CommandEnvironment env = new CommandEnvironment(
+ runtime, this, new EventBus(eventBusExceptionHandler), Thread.currentThread(),
+ commandName, options);
skyframeExecutor.setClientEnv(env.getClientEnv());
return env;
}
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 cb2c80416b..4fcea318cb 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
@@ -147,6 +147,24 @@ public final class CommandEnvironment {
workspace.getSkyframeExecutor().setEventBus(eventBus);
}
+ /**
+ * Same as CommandEnvironment(BlazeRuntime, BlazeWorkspace, EventBus, Thread) but with an
+ * explicit commandName and options.
+ *
+ * ONLY for testing.
+ */
+ @VisibleForTesting
+ CommandEnvironment(
+ BlazeRuntime runtime, BlazeWorkspace workspace, EventBus eventBus, Thread commandThread,
+ String commandNameForTesting, OptionsProvider optionsForTesting) {
+ this(runtime, workspace, eventBus, commandThread);
+ // Both commandName and options are normally set by beforeCommand(); however this method is not
+ // called in tests (i.e. tests use BlazeRuntimeWrapper). These fields should only be set for
+ // testing.
+ this.commandName = commandNameForTesting;
+ this.options = optionsForTesting;
+ }
+
public BlazeRuntime getRuntime() {
return runtime;
}