Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Watchman-backed DiffAwareness implementation #22615

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ java_library(
":broken_diff_awareness_exception",
":incompatible_view_exception",
":workspace_info",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
Expand Down Expand Up @@ -1704,16 +1705,21 @@ java_library(
"LocalDiffAwareness.java",
"MacOSXFsEventsDiffAwareness.java",
"WatchServiceDiffAwareness.java",
"WatchmanDiffAwareness.java",
],
deps = [
":broken_diff_awareness_exception",
":diff_awareness",
":incompatible_view_exception",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/jni",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/common/options",
"//third_party:flogger",
"//third_party:gson",
"//third_party:guava",
"//third_party:jsr305",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe;

import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
Expand Down Expand Up @@ -63,7 +64,8 @@ default WorkspaceInfoFromDiff getWorkspaceInfo() {
* {@link DiffAwareness} instance. The {@link DiffAwareness} is expected to close itself in
* this case.
*/
View getCurrentView(OptionsProvider options) throws BrokenDiffAwarenessException;
View getCurrentView(OptionsProvider options, EventHandler eventHandler)
throws BrokenDiffAwarenessException;

/**
* Returns the set of files of interest that have been modified between the given two views.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public ProcessableModifiedFileSet getDiff(
DiffAwareness diffAwareness = diffAwarenessState.diffAwareness;
View newView;
try (SilentCloseable c = Profiler.instance().profile("diffAwareness.getCurrentView")) {
newView = diffAwareness.getCurrentView(options);
newView = diffAwareness.getCurrentView(options, eventHandler);
} catch (BrokenDiffAwarenessException e) {
handleBrokenDiffAwareness(eventHandler, pathEntry, ignoredPaths, e);
return BrokenProcessableModifiedFileSet.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
Expand Down Expand Up @@ -71,6 +72,19 @@ public static final class Options extends OptionsBase {
"If true, experimental Windows support for --watchfs is enabled. Otherwise --watchfs"
+ "is a non-op on Windows. Make sure to also enable --watchfs.")
public boolean windowsWatchFS;

@Option(
name = "experimental_watchman_path",
defaultValue = "",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
converter = OptionsUtils.PathFragmentConverter.class,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"If set to a non-empty value, the specified Watchman binary will be used for file "
+ "system watching instead of the builtin OS-specific file system watching "
+ "mechanism. If only a basename is provided, the binary will be searched for in "
+ "PATH.")
public PathFragment watchmanPath;
}

/** Factory for creating {@link LocalDiffAwareness} instances. */
Expand Down Expand Up @@ -106,14 +120,21 @@ public DiffAwareness maybeCreate(
return null;
}
}

ImmutableSet<Path> ignoredNioPaths =
ignoredPaths.stream().map(p -> Path.of(p.toString())).collect(toImmutableSet());

PathFragment watchmanPath = optionsProvider.getOptions(Options.class).watchmanPath;
if (!watchmanPath.isEmpty()) {
return new WatchmanDiffAwareness(resolvedPathEntryFragment.toString(), ignoredNioPaths);
}

// On OSX uses FsEvents due to https://bugs.openjdk.java.net/browse/JDK-7133447
if (OS.getCurrent() == OS.DARWIN) {
return new MacOSXFsEventsDiffAwareness(resolvedPathEntryFragment.toString());
}

return new WatchServiceDiffAwareness(
resolvedPathEntryFragment.toString(),
ignoredPaths.stream().map(p -> Path.of(p.toString())).collect(toImmutableSet()));
return new WatchServiceDiffAwareness(resolvedPathEntryFragment.toString(), ignoredNioPaths);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.jni.JniLoader;
import com.google.devtools.common.options.OptionsProvider;
import java.nio.file.Path;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void close() {
}

@Override
public View getCurrentView(OptionsProvider options)
public View getCurrentView(OptionsProvider options, EventHandler eventHandler)
throws BrokenDiffAwarenessException {
if (!JNI_AVAILABLE) {
return EVERYTHING_MODIFIED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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.events.EventHandler;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.common.options.OptionsProvider;
import java.io.IOException;
Expand Down Expand Up @@ -70,7 +71,8 @@ private void init() {
}

@Override
public View getCurrentView(OptionsProvider options) throws BrokenDiffAwarenessException {
public View getCurrentView(OptionsProvider options, EventHandler eventHandler)
throws BrokenDiffAwarenessException {
// We need to consider 4 cases for watchFs:
// previous view current view
// disabled disabled -> EVERYTHING_MODIFIED
Expand Down
Loading