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 9d6919cf83c10d..7c60338a4f7041 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 @@ -104,6 +104,8 @@ public class CommandEnvironment { private final ImmutableList commandExtensions; private final ImmutableList.Builder responseExtensions = ImmutableList.builder(); private final Consumer shutdownReasonConsumer; + private final BuildResultListener buildResultListener; + private final CommandLinePathFactory commandLinePathFactory; private OutputService outputService; private TopDownActionCache topDownActionCache; @@ -266,6 +268,11 @@ public void exit(AbruptExitException exception) { repoEnvFromOptions.put(name, value); } } + this.buildResultListener = new BuildResultListener(); + this.eventBus.register(this.buildResultListener); + + this.commandLinePathFactory = + CommandLinePathFactory.create(runtime.getFileSystem(), directories); } private Path computeWorkingDirectory(CommonCommandOptions commandOptions) @@ -840,4 +847,12 @@ public ImmutableList getResponseExtensions() { public void addResponseExtensions(Iterable extensions) { responseExtensions.addAll(extensions); } + + public BuildResultListener getBuildResultListener() { + return buildResultListener; + } + + public CommandLinePathFactory getCommandLinePathFactory() { + return commandLinePathFactory; + } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java index e39bf074b2d91c..3726ddac64fc2a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java @@ -13,10 +13,12 @@ // limitations under the License. package com.google.devtools.build.lib.runtime; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -44,11 +46,27 @@ public final class CommandLinePathFactory { private final FileSystem fileSystem; private final ImmutableMap roots; + @VisibleForTesting public CommandLinePathFactory(FileSystem fileSystem, ImmutableMap roots) { this.fileSystem = Preconditions.checkNotNull(fileSystem); this.roots = Preconditions.checkNotNull(roots); } + static CommandLinePathFactory create(FileSystem fileSystem, BlazeDirectories directories) { + Preconditions.checkNotNull(fileSystem); + Preconditions.checkNotNull(directories); + + ImmutableMap.Builder wellKnownRoots = ImmutableMap.builder(); + + // This is necessary because some tests don't have a workspace set. + Path workspace = directories.getWorkspace(); + if (workspace != null) { + wellKnownRoots.put("workspace", workspace); + } + + return new CommandLinePathFactory(fileSystem, wellKnownRoots.buildOrThrow()); + } + /** Creates a {@link Path}. */ public Path create(Map env, String value) throws IOException { Preconditions.checkNotNull(env);