diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java | 78 |
1 files changed, 69 insertions, 9 deletions
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 acbd1200fa..ee80c85deb 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 @@ -73,6 +73,7 @@ import java.util.concurrent.atomic.AtomicReference; */ public final class CommandEnvironment { private final BlazeRuntime runtime; + private final BlazeDirectories directories; private final UUID commandId; // Unique identifier for the command being run private final Reporter reporter; @@ -107,6 +108,7 @@ public final class CommandEnvironment { public CommandEnvironment(BlazeRuntime runtime, UUID commandId, EventBus eventBus) { this.runtime = runtime; + this.directories = runtime.getDirectories(); this.commandId = commandId; this.reporter = new Reporter(); this.eventBus = eventBus; @@ -120,7 +122,7 @@ public final class CommandEnvironment { // TODO(ulfjack): We don't call beforeCommand() in tests, but rely on workingDirectory being set // in setupPackageCache(). This leads to NPE if we don't set it here. - this.workingDirectory = runtime.getWorkspace(); + this.workingDirectory = directories.getWorkspace(); } public BlazeRuntime getRuntime() { @@ -128,7 +130,7 @@ public final class CommandEnvironment { } public BlazeDirectories getDirectories() { - return runtime.getDirectories(); + return directories; } /** @@ -208,11 +210,69 @@ public final class CommandEnvironment { } /** + * Returns the working directory of the server. + * + * <p>This is often the first entry on the {@code --package_path}, but not always. + * Callers should certainly not make this assumption. The Path returned may be null. + */ + public Path getWorkspace() { + return getDirectories().getWorkspace(); + } + + public String getWorkspaceName() { + Path workspace = getDirectories().getWorkspace(); + if (workspace == null) { + return ""; + } + return workspace.getBaseName(); + } + + /** + * Returns if the client passed a valid workspace to be used for the build. + */ + public boolean inWorkspace() { + return getDirectories().inWorkspace(); + } + + /** + * Returns the output base directory associated with this Blaze server + * process. This is the base directory for shared Blaze state as well as tool + * and strategy specific subdirectories. + */ + public Path getOutputBase() { + return getDirectories().getOutputBase(); + } + + /** + * Returns the output path associated with this Blaze server process.. + */ + public Path getOutputPath() { + return getDirectories().getOutputPath(); + } + + /** + * The directory in which blaze stores the server state - that is, the socket + * file and a log. + */ + public Path getServerDirectory() { + return getOutputBase().getChild("server"); + } + + /** + * Returns the execution root directory associated with this Blaze server + * process. This is where all input and output files visible to the actual + * build reside. + */ + public Path getExecRoot() { + return getDirectories().getExecRoot(); + } + + /** * Returns the working directory of the {@code blaze} client process. * * <p>This may be equal to {@code BlazeRuntime#getWorkspace()}, or beneath it. * - * @see BlazeRuntime#getWorkspace() + * @see #getWorkspace() */ public Path getWorkingDirectory() { return workingDirectory; @@ -246,7 +306,7 @@ public final class CommandEnvironment { throw new InvalidConfigurationException("Configuration creation failed"); } return getSkyframeExecutor().createConfigurations(reporter, runtime.getConfigurationFactory(), - buildOptions, runtime.getDirectories(), ImmutableSet.<String>of(), keepGoing); + buildOptions, getDirectories(), ImmutableSet.<String>of(), keepGoing); } // TODO(ulfjack): Do we even need this method? With Skyframe, the config creation should @@ -304,7 +364,7 @@ public final class CommandEnvironment { if (!skyframeExecutor.hasIncrementalState()) { skyframeExecutor.resetEvaluator(); } - skyframeExecutor.sync(reporter, packageCacheOptions, runtime.getOutputBase(), + skyframeExecutor.sync(reporter, packageCacheOptions, getOutputBase(), getWorkingDirectory(), defaultsPackageContents, commandId, timestampGranularityMonitor); } @@ -365,12 +425,12 @@ public final class CommandEnvironment { this.outputFileSystem = determineOutputFileSystem(); // Ensure that the working directory will be under the workspace directory. - Path workspace = runtime.getWorkspace(); + Path workspace = getWorkspace(); Path workingDirectory; - if (runtime.inWorkspace()) { + if (inWorkspace()) { workingDirectory = workspace.getRelative(options.clientCwd); } else { - workspace = FileSystemUtils.getWorkingDirectory(runtime.getDirectories().getFileSystem()); + workspace = FileSystemUtils.getWorkingDirectory(getDirectories().getFileSystem()); workingDirectory = workspace; } this.relativeWorkingDirectory = workingDirectory.relativeTo(workspace); @@ -428,7 +488,7 @@ public final class CommandEnvironment { return getOutputService().getFilesSystemName(); } try (AutoProfiler p = profiled("Finding output file system", ProfilerTask.INFO)) { - return FileSystemUtils.getFileSystem(runtime.getOutputBase()); + return FileSystemUtils.getFileSystem(getOutputBase()); } } } |