aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
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;
}