Unverified Commit 7e4c74b9 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Make the "non-recursive" logic for the fs watcher a runtime flag…

Turbopack: Make the "non-recursive" logic for the fs watcher a runtime flag instead of a build-time one (#82031)

We use different modes on macos/windows and linux for watching files for performance reasons: https://github.com/vercel/turborepo/pull/4100

Now with `TURBO_TASKS_FORCE_WATCH_MODE=recursive` or `TURBO_TASKS_FORCE_WATCH_MODE=nonrecursive`, you can force the watcher into either mode, independent of platform.

### Why?

- Platform-specific compilation flags are annoying and it's easy to accidentally break compilation on another platform.
- It's actually really useful to be able to force recursive or non-recursive mode without switching platforms when testing the watcher to narrow down bugs. E.g. on Linux:

```
# this fails to receive watch events after directories are added/removed
rm -rf /tmp/fuzz && RUST_BACKTRACE=1 TURBO_TASKS_FORCE_WATCH_MODE=nonrecursive cargo run --release -p turbo-tasks-fuzz -- fs-watcher --fs-root /tmp/fuzz

# but this (simulating the behavior of macos/windows) works fine
rm -rf /tmp/fuzz && RUST_BACKTRACE=1 TURBO_TASKS_FORCE_WATCH_MODE=recursive cargo run --release -p turbo-tasks-fuzz -- fs-watcher --fs-root /tmp/fuzz
```

- There's not all that many places this flag needs to be checked, and compared to the cost of the syscalls happening at those callsites, the impact should be basically zero.
parent ad4fd37d
......@@ -255,9 +255,10 @@ impl DiskFileSystemInner {
let invalidator = turbo_tasks::get_invalidator();
self.invalidator_map
.insert(path_to_key(path), invalidator, None);
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
if let Some(dir) = path.parent() {
self.watcher.ensure_watching(dir, self.root_path())?;
if let Some(non_recursive) = &self.watcher.non_recursive_state
&& let Some(dir) = path.parent()
{
non_recursive.ensure_watching(&self.watcher, dir, self.root_path())?;
}
Ok(())
}
......@@ -284,9 +285,10 @@ impl DiskFileSystemInner {
.collect::<Vec<_>>();
invalidators.insert(invalidator, Some(write_content));
drop(invalidator_map);
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
if let Some(dir) = path.parent() {
self.watcher.ensure_watching(dir, self.root_path())?;
if let Some(non_recursive) = &self.watcher.non_recursive_state
&& let Some(dir) = path.parent()
{
non_recursive.ensure_watching(&self.watcher, dir, self.root_path())?;
}
Ok(old_invalidators)
}
......@@ -297,8 +299,9 @@ impl DiskFileSystemInner {
let invalidator = turbo_tasks::get_invalidator();
self.dir_invalidator_map
.insert(path_to_key(path), invalidator, None);
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
self.watcher.ensure_watching(path, self.root_path())?;
if let Some(non_recursive) = &self.watcher.non_recursive_state {
non_recursive.ensure_watching(&self.watcher, path, self.root_path())?;
}
Ok(())
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment