Skip to content

Commit

Permalink
Add CommandLinePathFactory to CommandEnvironment
Browse files Browse the repository at this point in the history
Progress on bazelbuild#15856

Closes bazelbuild#15905.

PiperOrigin-RevId: 462369707
Change-Id: If8dd493227b67dd4ffe30c9e0af4d8f71de4fb9f
  • Loading branch information
Yannic authored and ckolli5 committed Jul 22, 2022
1 parent 05e758d commit 308fba5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class CommandEnvironment {
private final ImmutableList<Any> commandExtensions;
private final ImmutableList.Builder<Any> responseExtensions = ImmutableList.builder();
private final Consumer<String> shutdownReasonConsumer;
private final BuildResultListener buildResultListener;
private final CommandLinePathFactory commandLinePathFactory;

private OutputService outputService;
private TopDownActionCache topDownActionCache;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -840,4 +847,12 @@ public ImmutableList<Any> getResponseExtensions() {
public void addResponseExtensions(Iterable<Any> extensions) {
responseExtensions.addAll(extensions);
}

public BuildResultListener getBuildResultListener() {
return buildResultListener;
}

public CommandLinePathFactory getCommandLinePathFactory() {
return commandLinePathFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,11 +46,27 @@ public final class CommandLinePathFactory {
private final FileSystem fileSystem;
private final ImmutableMap<String, Path> roots;

@VisibleForTesting
public CommandLinePathFactory(FileSystem fileSystem, ImmutableMap<String, Path> 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<String, Path> 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<String, String> env, String value) throws IOException {
Preconditions.checkNotNull(env);
Expand Down

0 comments on commit 308fba5

Please sign in to comment.