Skip to content

Commit

Permalink
Add CommandLinePathFactory to CommandEnvironment
Browse files Browse the repository at this point in the history
Progress on bazelbuild#15856
  • Loading branch information
Yannic committed Jul 18, 2022
1 parent 33516e2 commit 4373197
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class CommandEnvironment {
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 String workspaceName;
Expand Down Expand Up @@ -273,6 +274,23 @@ public void exit(AbruptExitException exception) {
}
this.buildResultListener = new BuildResultListener();
this.eventBus.register(this.buildResultListener);

ImmutableMap.Builder<String, Path> wellKnownRoots = ImmutableMap.builder();
// This is necessary because some tests don't have a workspace set.
putIfValueNotNull(wellKnownRoots, "workspace", directories.getWorkspace());

this.commandLinePathFactory =
new CommandLinePathFactory(runtime.getFileSystem(), wellKnownRoots.build());
}

private static <K, V> void putIfValueNotNull(
ImmutableMap.Builder<K, V> map, K key, @Nullable V value) {
Preconditions.checkNotNull(map);
Preconditions.checkNotNull(key);

if (value != null) {
map.put(key, value);
}
}

private Path computeWorkingDirectory(CommonCommandOptions commandOptions)
Expand Down Expand Up @@ -840,4 +858,8 @@ public void addResponseExtensions(Iterable<Any> extensions) {
public BuildResultListener getBuildResultListener() {
return buildResultListener;
}

public CommandLinePathFactory getCommandLinePathFactory() {
return commandLinePathFactory;
}
}

0 comments on commit 4373197

Please sign in to comment.