diff options
author | 2017-10-27 12:12:11 -0400 | |
---|---|---|
committer | 2017-10-30 10:40:06 -0400 | |
commit | f903eb5ace7e4d9e72ca95f3e5fa39816be93a76 (patch) | |
tree | 3f5f33de008ecd0c82996a134fad2968146312e3 /src/main/java/com/google/devtools/build/lib/runtime | |
parent | 4abd9434447e08c70266cc5583456816537718c3 (diff) |
Thread FileSystem through to a single Path#delete call site.
This requires a fairly large amount of changes to fundamental objects like BlazeRuntime, Executor, and so on, as well as changing a lot of test code to thread the file system through. I expect future CLs to be much smaller.
PiperOrigin-RevId: 173678144
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
5 files changed, 51 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java index 01aeaf1757..683a5243f4 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java @@ -85,21 +85,25 @@ public abstract class BlazeModule { } /** - * Called when Bazel starts up after {@link #getStartupOptions}, {@link #globalInit}, and - * {@link #getFileSystem}. + * Called when Bazel starts up after {@link #getStartupOptions}, {@link #globalInit}, and {@link + * #getFileSystem}. * * @param startupOptions the server's startup options * @param versionInfo the Bazel version currently running * @param instanceId the id of the current Bazel server + * @param fileSystem * @param directories the install directory * @param clock the clock - * * @throws AbruptExitException to shut down the server immediately */ - public void blazeStartup(OptionsProvider startupOptions, - BlazeVersionInfo versionInfo, UUID instanceId, ServerDirectories directories, - Clock clock) throws AbruptExitException { - } + public void blazeStartup( + OptionsProvider startupOptions, + BlazeVersionInfo versionInfo, + UUID instanceId, + FileSystem fileSystem, + ServerDirectories directories, + Clock clock) + throws AbruptExitException {} /** * Called to initialize a new server ({@link BlazeRuntime}). Modules can override this method to 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 29b9e45650..8eb5ffbb47 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 @@ -122,6 +122,7 @@ public final class BlazeRuntime { private static final Logger logger = Logger.getLogger(BlazeRuntime.class.getName()); + private final FileSystem fileSystem; private final Iterable<BlazeModule> blazeModules; private final Map<String, BlazeCommand> commandMap = new LinkedHashMap<>(); private final Clock clock; @@ -153,6 +154,7 @@ public final class BlazeRuntime { private BlazeWorkspace workspace; private BlazeRuntime( + FileSystem fileSystem, QueryEnvironmentFactory queryEnvironmentFactory, ImmutableList<QueryFunction> queryFunctions, ImmutableList<OutputFormatter> queryOutputFormatters, @@ -171,6 +173,7 @@ public final class BlazeRuntime { String productName, PathConverter pathToUriConverter) { // Server state + this.fileSystem = fileSystem; this.blazeModules = blazeModules; overrideCommands(commands); @@ -283,6 +286,10 @@ public final class BlazeRuntime { return false; } + public FileSystem getFileSystem() { + return fileSystem; + } + public BlazeWorkspace getWorkspace() { return workspace; } @@ -959,18 +966,21 @@ public final class BlazeRuntime { ServerDirectories serverDirectories = new ServerDirectories(installBasePath, outputBasePath, startupOptions.installMD5); Clock clock = BlazeClock.instance(); - BlazeRuntime.Builder runtimeBuilder = new BlazeRuntime.Builder() - .setProductName(productName) - .setServerDirectories(serverDirectories) - .setStartupOptionsProvider(options) - .setClock(clock) - .setAbruptShutdownHandler(abruptShutdownHandler) - // TODO(bazel-team): Make BugReportingExceptionHandler the default. - // See bug "Make exceptions in EventBus subscribers fatal" - .setEventBusExceptionHandler( - startupOptions.fatalEventBusExceptions || !BlazeVersionInfo.instance().isReleasedBlaze() - ? new BlazeRuntime.BugReportingExceptionHandler() - : new BlazeRuntime.RemoteExceptionHandler()); + BlazeRuntime.Builder runtimeBuilder = + new BlazeRuntime.Builder() + .setProductName(productName) + .setFileSystem(fs) + .setServerDirectories(serverDirectories) + .setStartupOptionsProvider(options) + .setClock(clock) + .setAbruptShutdownHandler(abruptShutdownHandler) + // TODO(bazel-team): Make BugReportingExceptionHandler the default. + // See bug "Make exceptions in EventBus subscribers fatal" + .setEventBusExceptionHandler( + startupOptions.fatalEventBusExceptions + || !BlazeVersionInfo.instance().isReleasedBlaze() + ? new BlazeRuntime.BugReportingExceptionHandler() + : new BlazeRuntime.RemoteExceptionHandler()); if (System.getenv("TEST_TMPDIR") != null && System.getenv("NO_CRASH_ON_LOGGING_IN_TEST") == null) { @@ -1103,6 +1113,7 @@ public final class BlazeRuntime { * an exception. Please plan appropriately. */ public static class Builder { + private FileSystem fileSystem; private ServerDirectories serverDirectories; private Clock clock; private Runnable abruptShutdownHandler; @@ -1122,8 +1133,13 @@ public final class BlazeRuntime { Preconditions.checkNotNull(clock); for (BlazeModule module : blazeModules) { - module.blazeStartup(startupOptionsProvider, - BlazeVersionInfo.instance(), instanceId, serverDirectories, clock); + module.blazeStartup( + startupOptionsProvider, + BlazeVersionInfo.instance(), + instanceId, + fileSystem, + serverDirectories, + clock); } ServerBuilder serverBuilder = new ServerBuilder(); serverBuilder.addQueryOutputFormatters(OutputFormatter.getDefaultFormatters()); @@ -1142,7 +1158,7 @@ public final class BlazeRuntime { Package.Builder.Helper packageBuilderHelper = null; for (BlazeModule module : blazeModules) { Package.Builder.Helper candidateHelper = - module.getPackageBuilderHelper(ruleClassProvider, serverDirectories.getFileSystem()); + module.getPackageBuilderHelper(ruleClassProvider, fileSystem); if (candidateHelper != null) { Preconditions.checkState(packageBuilderHelper == null, "more than one module defines a package builder helper"); @@ -1173,6 +1189,7 @@ public final class BlazeRuntime { } return new BlazeRuntime( + fileSystem, serverBuilder.getQueryEnvironmentFactory(), serverBuilder.getQueryFunctions(), serverBuilder.getQueryOutputFormatters(), @@ -1197,6 +1214,11 @@ public final class BlazeRuntime { return this; } + public Builder setFileSystem(FileSystem fileSystem) { + this.fileSystem = fileSystem; + return this; + } + public Builder setServerDirectories(ServerDirectories serverDirectories) { this.serverDirectories = serverDirectories; return this; 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 6329ee1a05..a36f3afaba 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 @@ -612,7 +612,7 @@ public final class CommandEnvironment { if (inWorkspace()) { workingDirectory = workspace.getRelative(commonOptions.clientCwd); } else { - workspace = FileSystemUtils.getWorkingDirectory(getDirectories().getFileSystem()); + workspace = FileSystemUtils.getWorkingDirectory(getRuntime().getFileSystem()); workingDirectory = workspace; } this.relativeWorkingDirectory = workingDirectory.relativeTo(workspace); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java index 882f6f03e2..6b9266702b 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java @@ -78,6 +78,7 @@ public final class WorkspaceBuilder { SkyframeExecutor skyframeExecutor = skyframeExecutorFactory.create( packageFactory, + runtime.getFileSystem(), directories, workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java index cbfdb5e277..0badadd258 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java @@ -498,7 +498,7 @@ public abstract class InfoItem { return print("unknown"); } // Tunnel through a Path object in order to normalize the representation of the path. - Path javaHomePath = env.getDirectories().getFileSystem().getPath(javaHome); + Path javaHomePath = env.getRuntime().getFileSystem().getPath(javaHome); return print(javaHomePath.getPathString()); } } |