From de14adebfcc0d66ff48aec9ace3a4d36343200f5 Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Fri, 14 Oct 2016 14:20:31 +0000 Subject: Make --watchfs a common command option. Adding an options parameter to DiffAwareness#getCurrentView seems like the simplest way to achieve that. Alternatives considered: 1. Making the diff awareness modules stateful. However, I did not want to do so as I've also been working on improving the module API to reduce state, or at least to have a proper lifecycle management for any necessary state. 2. Making the watchFs flag a constructor parameter. However, that would also invalidate any implementations that don't use the flag (of which we have several). 3. Only passing in a single boolean flag instead of an options class provider; however, this is a more principled, futureproof API, which allows other modules / awareness implementations to use their own options. RELNOTES: --watchfs is now a command option; the startup option of the same name is deprecated. I.e., use bazel build --watchfs, not blaze --watchfs build. -- MOS_MIGRATED_REVID=136154395 --- .../build/lib/skyframe/DiffAwarenessManager.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java') diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java index 02870970d4..76f00a7fb4 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java @@ -13,17 +13,16 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.skyframe.DiffAwareness.View; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; - +import com.google.devtools.common.options.OptionsClassProvider; import java.util.Map; import java.util.logging.Logger; - import javax.annotation.Nullable; /** @@ -34,11 +33,13 @@ public final class DiffAwarenessManager { private static final Logger LOG = Logger.getLogger(DiffAwarenessManager.class.getName()); - private final ImmutableSet diffAwarenessFactories; + // The manager attempts to instantiate these in the order in which they are passed to the + // constructor; this is critical in the case where a factory always succeeds. + private final ImmutableList diffAwarenessFactories; private Map currentDiffAwarenessStates = Maps.newHashMap(); public DiffAwarenessManager(Iterable diffAwarenessFactories) { - this.diffAwarenessFactories = ImmutableSet.copyOf(diffAwarenessFactories); + this.diffAwarenessFactories = ImmutableList.copyOf(diffAwarenessFactories); } private static class DiffAwarenessState { @@ -79,7 +80,8 @@ public final class DiffAwarenessManager { * Gets the set of changed files since the last call with this path entry, or * {@code ModifiedFileSet.EVERYTHING_MODIFIED} if this is the first such call. */ - public ProcessableModifiedFileSet getDiff(EventHandler eventHandler, Path pathEntry) { + public ProcessableModifiedFileSet getDiff( + EventHandler eventHandler, Path pathEntry, OptionsClassProvider options) { DiffAwarenessState diffAwarenessState = maybeGetDiffAwarenessState(pathEntry); if (diffAwarenessState == null) { return BrokenProcessableModifiedFileSet.INSTANCE; @@ -87,7 +89,7 @@ public final class DiffAwarenessManager { DiffAwareness diffAwareness = diffAwarenessState.diffAwareness; View newView; try { - newView = diffAwareness.getCurrentView(); + newView = diffAwareness.getCurrentView(options); } catch (BrokenDiffAwarenessException e) { handleBrokenDiffAwareness(eventHandler, pathEntry, e); return BrokenProcessableModifiedFileSet.INSTANCE; -- cgit v1.2.3