diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
9 files changed, 100 insertions, 74 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java index f57f8b9df5..ad45de4b62 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java @@ -122,19 +122,19 @@ public class BlazeCommandDispatcher { * Only some commands work if cwd != workspaceSuffix in Blaze. In that case, also check if Blaze * was called from the output directory and fail if it was. */ - private ExitCode checkCwdInWorkspace(Command commandAnnotation, String commandName, - OutErr outErr) { + private ExitCode checkCwdInWorkspace(CommandEnvironment env, Command commandAnnotation, + String commandName, OutErr outErr) { if (!commandAnnotation.mustRunInWorkspace()) { return ExitCode.SUCCESS; } - if (!runtime.inWorkspace()) { - outErr.printErrLn("The '" + commandName + "' command is only supported from within a " - + "workspace."); + if (!env.inWorkspace()) { + outErr.printErrLn( + "The '" + commandName + "' command is only supported from within a workspace."); return ExitCode.COMMAND_LINE_ERROR; } - Path workspace = runtime.getWorkspace(); + Path workspace = env.getWorkspace(); // TODO(kchodorow): Remove this once spaces are supported. if (workspace.getPathString().contains(" ")) { outErr.printErrLn(Constants.PRODUCT_NAME + " does not currently work properly from paths " @@ -256,7 +256,7 @@ public class BlazeCommandDispatcher { } try { - Path commandLog = getCommandLogPath(runtime.getOutputBase()); + Path commandLog = getCommandLogPath(env.getOutputBase()); // Unlink old command log from previous build, if present, so scripts // reading it don't conflate it with the command log we're about to write. @@ -269,7 +269,7 @@ public class BlazeCommandDispatcher { Level.WARNING, "Unable to delete or open command.log", ioException); } - ExitCode result = checkCwdInWorkspace(commandAnnotation, commandName, outErr); + ExitCode result = checkCwdInWorkspace(env, commandAnnotation, commandName, outErr); if (result != ExitCode.SUCCESS) { return result.getNumericExitCode(); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 7c598c0eed..638e5f964f 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -212,7 +212,7 @@ public final class BlazeRuntime { this.directories = directories; this.skyframeExecutor = skyframeExecutor; - if (inWorkspace()) { + if (directories.inWorkspace()) { writeOutputBaseReadmeFile(); writeDoNotBuildHereFile(); } @@ -396,14 +396,6 @@ public final class BlazeRuntime { return lastExecutionRange; } - public String getWorkspaceName() { - Path workspace = directories.getWorkspace(); - if (workspace == null) { - return ""; - } - return workspace.getBaseName(); - } - /** * Returns the Blaze directories object for this runtime. */ @@ -417,48 +409,25 @@ public final class BlazeRuntime { * <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() { + private Path getWorkspace() { return directories.getWorkspace(); } /** - * Returns if the client passed a valid workspace to be used for the build. - */ - public boolean inWorkspace() { - return directories.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() { + private Path getOutputBase() { return directories.getOutputBase(); } /** - * Returns the output path associated with this Blaze server process.. - */ - public Path getOutputPath() { - return directories.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 directories.getExecRoot(); + private Path getServerDirectory() { + return getDirectories().getOutputBase().getChild("server"); } public BinTools getBinTools() { 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()); } } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java index c6e3a2a3ee..12630051e6 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java @@ -86,7 +86,6 @@ public final class CleanCommand implements BlazeCommand { @Override public ExitCode exec(CommandEnvironment env, OptionsProvider options) throws ShutdownBlazeServerException { - BlazeRuntime runtime = env.getRuntime(); Options cleanOptions = options.getOptions(Options.class); cleanOptions.expunge_async = cleanOptions.cleanStyle.equals("expunge_async"); cleanOptions.expunge = cleanOptions.cleanStyle.equals("expunge"); @@ -109,7 +108,7 @@ public final class CleanCommand implements BlazeCommand { try { String symlinkPrefix = options.getOptions(BuildRequest.BuildRequestOptions.class).getSymlinkPrefix(); - actuallyClean(env, runtime.getOutputBase(), cleanOptions, symlinkPrefix); + actuallyClean(env, env.getOutputBase(), cleanOptions, symlinkPrefix); return ExitCode.SUCCESS; } catch (IOException e) { env.getReporter().handle(Event.error(e.getMessage())); @@ -167,7 +166,7 @@ public final class CleanCommand implements BlazeCommand { // In order to be sure that we delete everything, delete the workspace directory both for // --deep_execroot and for --nodeep_execroot. for (String directory : new String[] { - runtime.getWorkspaceName(), "execroot/" + runtime.getWorkspaceName() }) { + env.getWorkspaceName(), "execroot/" + env.getWorkspaceName() }) { Path child = outputBase.getRelative(directory); if (child.exists()) { LOG.finest("Cleaning " + child); @@ -177,7 +176,7 @@ public final class CleanCommand implements BlazeCommand { } // remove convenience links OutputDirectoryLinksUtils.removeOutputDirectoryLinks( - runtime.getWorkspaceName(), runtime.getWorkspace(), env.getReporter(), symlinkPrefix); + env.getWorkspaceName(), env.getWorkspace(), env.getReporter(), symlinkPrefix); // shutdown on expunge cleans if (cleanOptions.expunge || cleanOptions.expunge_async) { throw new ShutdownBlazeServerException(0); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java index 81e19a0334..6acf54658b 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java @@ -151,7 +151,7 @@ public class DumpCommand implements BlazeCommand { if (dumpOptions.dumpVfs) { out.println("Filesystem cache"); - FileSystemUtils.dump(runtime.getOutputBase().getFileSystem(), out); + FileSystemUtils.dump(env.getOutputBase().getFileSystem(), out); out.println(); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index 93a947a9ff..65d72552f2 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -284,10 +284,10 @@ public class InfoCommand implements BlazeCommand { Supplier<BuildConfiguration> configurationSupplier, OptionsProvider options) { switch (key) { // directories - case WORKSPACE : return runtime.getWorkspace(); + case WORKSPACE : return runtime.getDirectories().getWorkspace(); case INSTALL_BASE : return runtime.getDirectories().getInstallBase(); - case OUTPUT_BASE : return runtime.getOutputBase(); - case EXECUTION_ROOT : return runtime.getExecRoot(); + case OUTPUT_BASE : return runtime.getDirectories().getOutputBase(); + case EXECUTION_ROOT : return runtime.getDirectories().getExecRoot(); case OUTPUT_PATH : return runtime.getDirectories().getOutputPath(); // These are the only (non-hidden) info items that require a configuration, because the // corresponding paths contain the short name. Maybe we should recommend using the symlinks @@ -297,10 +297,11 @@ public class InfoCommand implements BlazeCommand { case BLAZE_TESTLOGS : return configurationSupplier.get().getTestLogsDirectory().getPath(); // logs - case COMMAND_LOG : return BlazeCommandDispatcher.getCommandLogPath(runtime.getOutputBase()); + case COMMAND_LOG : return BlazeCommandDispatcher.getCommandLogPath( + runtime.getDirectories().getOutputBase()); case MESSAGE_LOG : // NB: Duplicated in EventLogModule - return runtime.getOutputBase().getRelative("message.log"); + return runtime.getDirectories().getOutputBase().getRelative("message.log"); // misc case RELEASE : return BlazeVersionInfo.instance().getReleaseName(); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java index 9b2cc21bc2..970cb5c007 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java @@ -30,7 +30,6 @@ import com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics; import com.google.devtools.build.lib.profiler.statistics.PhaseStatistics; import com.google.devtools.build.lib.profiler.statistics.PhaseSummaryStatistics; import com.google.devtools.build.lib.runtime.BlazeCommand; -import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; @@ -178,7 +177,6 @@ public final class ProfileCommand implements BlazeCommand { @Override public ExitCode exec(final CommandEnvironment env, OptionsProvider options) { - final BlazeRuntime runtime = env.getRuntime(); ProfileOptions opts = options.getOptions(ProfileOptions.class); @@ -194,7 +192,7 @@ public final class ProfileCommand implements BlazeCommand { MultiProfileStatistics statistics = new MultiProfileStatistics( env.getWorkingDirectory(), - runtime.getWorkspaceName(), + env.getWorkspaceName(), options.getResidue(), getInfoListener(env), opts.vfsStatsLimit > 0); @@ -250,7 +248,7 @@ public final class ProfileCommand implements BlazeCommand { phaseStatistics.put( phase, new PhaseStatistics( - phase, info, runtime.getWorkspaceName(), opts.vfsStatsLimit > 0)); + phase, info, env.getWorkspaceName(), opts.vfsStatsLimit > 0)); } CriticalPathStatistics critPathStats = new CriticalPathStatistics(info); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java index 240a0ecd5c..cfdabe690e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java @@ -65,10 +65,10 @@ public final class ProjectFileSupport { // relative to the cwd instead. PathFragment projectFilePath = new PathFragment(targets.get(0).substring(1)); List<Path> packagePath = PathPackageLocator.create( - runtime.getOutputBase(), + env.getOutputBase(), optionsParser.getOptions(PackageCacheOptions.class).packagePath, env.getReporter(), - runtime.getWorkspace(), + env.getWorkspace(), env.getWorkingDirectory()).getPathEntries(); ProjectFile projectFile = projectFileProvider.getProjectFile( env.getWorkingDirectory(), packagePath, projectFilePath); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index 34f6819afd..836c154cfa 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -242,15 +242,14 @@ public class RunCommand implements BlazeCommand { // replaced with a shorter relative path that uses the symlinks in the workspace. PathFragment prettyExecutablePath = OutputDirectoryLinksUtils.getPrettyPath(executablePath, - runtime.getWorkspaceName(), runtime.getWorkspace(), + env.getWorkspaceName(), env.getWorkspace(), options.getOptions(BuildRequestOptions.class).getSymlinkPrefix()); List<String> cmdLine = new ArrayList<>(); if (runOptions.scriptPath == null) { PathFragment processWrapperPath = runtime.getBinTools().getExecPath(PROCESS_WRAPPER); Preconditions.checkNotNull( processWrapperPath, PROCESS_WRAPPER + " not found in embedded tools"); - cmdLine.add(runtime.getDirectories().getExecRoot() - .getRelative(processWrapperPath).getPathString()); + cmdLine.add(env.getExecRoot().getRelative(processWrapperPath).getPathString()); cmdLine.add("-1"); cmdLine.add("15"); cmdLine.add("-"); @@ -356,7 +355,7 @@ public class RunCommand implements BlazeCommand { Artifact manifest = runfilesSupport.getRunfilesManifest(); PathFragment runfilesDir = runfilesSupport.getRunfilesDirectoryExecPath(); - Path workingDir = env.getRuntime().getExecRoot() + Path workingDir = env.getExecRoot() .getRelative(runfilesDir) .getRelative(runfilesSupport.getRunfiles().getSuffix()); @@ -372,7 +371,7 @@ public class RunCommand implements BlazeCommand { manifest.getExecPath(), runfilesDir, false); - helper.createSymlinksUsingCommand(env.getRuntime().getExecRoot(), target.getConfiguration(), + helper.createSymlinksUsingCommand(env.getExecRoot(), target.getConfiguration(), env.getRuntime().getBinTools()); return workingDir; } |