Disable WatchFs on Windows
The current implementation of WatchFs always holds the handles of the files being watched, this will cause bazel clean and many other clean functions to fail. Make --watchfs a non-op until we have a proper implementation for Windows.
Related: https://github.com/bazelbuild/bazel/issues/1931#issuecomment-496013304
RELNOTES: None
PiperOrigin-RevId: 250144238
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
index e75ffe7..5a26d8d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
@@ -48,14 +48,14 @@
*/
public static final class Options extends OptionsBase {
@Option(
- name = "watchfs",
- defaultValue = "false",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help =
- "If true, %{product} tries to use the operating system's file watch service for "
- + "local changes instead of scanning every file for a change."
- )
+ name = "watchfs",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "On Linux/macOS: If true, %{product} tries to use the operating system's file watch "
+ + "service for local changes instead of scanning every file for a change. On "
+ + "Windows: this flag is a non-op.")
public boolean watchFS;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WatchServiceDiffAwareness.java b/src/main/java/com/google/devtools/build/lib/skyframe/WatchServiceDiffAwareness.java
index cc1033c..7a7ffb7 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/WatchServiceDiffAwareness.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/WatchServiceDiffAwareness.java
@@ -17,6 +17,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.util.OS;
import com.google.devtools.common.options.OptionsProvider;
import java.io.IOException;
import java.nio.file.ClosedWatchServiceException;
@@ -84,7 +85,9 @@
// contain files that are modified between init() and poll() below, because those are
// already taken into account for the current build, as we ended up with
// ModifiedFileSet.EVERYTHING_MODIFIED in the current build.
- boolean watchFs = options.getOptions(Options.class).watchFS;
+ // Disable WatchFs on Windows, because it is not implemented correctly on Windows.
+ // TODO(pcloudy): Enable watchFs on Windows, https://github.com/bazelbuild/bazel/issues/1931
+ boolean watchFs = options.getOptions(Options.class).watchFS && OS.getCurrent() != OS.WINDOWS;
if (watchFs && watchService == null) {
init();
} else if (!watchFs && (watchService != null)) {