From 4373197059117c8a91788ab14f4e9a415c843c4a Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Mon, 18 Jul 2022 15:47:49 +0200 Subject: [PATCH] Add CommandLinePathFactory to CommandEnvironment Progress on #15856 --- .../build/lib/runtime/CommandEnvironment.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 a3830c527e4f16..977da98b0604e5 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 @@ -107,6 +107,7 @@ public class CommandEnvironment { private final ImmutableList.Builder responseExtensions = ImmutableList.builder(); private final Consumer shutdownReasonConsumer; private final BuildResultListener buildResultListener; + private final CommandLinePathFactory commandLinePathFactory; private OutputService outputService; private String workspaceName; @@ -273,6 +274,23 @@ public void exit(AbruptExitException exception) { } this.buildResultListener = new BuildResultListener(); this.eventBus.register(this.buildResultListener); + + ImmutableMap.Builder 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 void putIfValueNotNull( + ImmutableMap.Builder map, K key, @Nullable V value) { + Preconditions.checkNotNull(map); + Preconditions.checkNotNull(key); + + if (value != null) { + map.put(key, value); + } } private Path computeWorkingDirectory(CommonCommandOptions commandOptions) @@ -840,4 +858,8 @@ public void addResponseExtensions(Iterable extensions) { public BuildResultListener getBuildResultListener() { return buildResultListener; } + + public CommandLinePathFactory getCommandLinePathFactory() { + return commandLinePathFactory; + } }