Skip to content

Commit 4373197

Browse files
committed
Add CommandLinePathFactory to CommandEnvironment
Progress on bazelbuild#15856
1 parent 33516e2 commit 4373197

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class CommandEnvironment {
107107
private final ImmutableList.Builder<Any> responseExtensions = ImmutableList.builder();
108108
private final Consumer<String> shutdownReasonConsumer;
109109
private final BuildResultListener buildResultListener;
110+
private final CommandLinePathFactory commandLinePathFactory;
110111

111112
private OutputService outputService;
112113
private String workspaceName;
@@ -273,6 +274,23 @@ public void exit(AbruptExitException exception) {
273274
}
274275
this.buildResultListener = new BuildResultListener();
275276
this.eventBus.register(this.buildResultListener);
277+
278+
ImmutableMap.Builder<String, Path> wellKnownRoots = ImmutableMap.builder();
279+
// This is necessary because some tests don't have a workspace set.
280+
putIfValueNotNull(wellKnownRoots, "workspace", directories.getWorkspace());
281+
282+
this.commandLinePathFactory =
283+
new CommandLinePathFactory(runtime.getFileSystem(), wellKnownRoots.build());
284+
}
285+
286+
private static <K, V> void putIfValueNotNull(
287+
ImmutableMap.Builder<K, V> map, K key, @Nullable V value) {
288+
Preconditions.checkNotNull(map);
289+
Preconditions.checkNotNull(key);
290+
291+
if (value != null) {
292+
map.put(key, value);
293+
}
276294
}
277295

278296
private Path computeWorkingDirectory(CommonCommandOptions commandOptions)
@@ -840,4 +858,8 @@ public void addResponseExtensions(Iterable<Any> extensions) {
840858
public BuildResultListener getBuildResultListener() {
841859
return buildResultListener;
842860
}
861+
862+
public CommandLinePathFactory getCommandLinePathFactory() {
863+
return commandLinePathFactory;
864+
}
843865
}

0 commit comments

Comments
 (0)