Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CommandLinePathFactory to CommandEnvironment #15946

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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