[clang][deps] Don't share in-memory VFS across scans
authorJan Svoboda <jan_svoboda@apple.com>
Tue, 11 Oct 2022 23:02:10 +0000 (16:02 -0700)
committerJan Svoboda <jan_svoboda@apple.com>
Thu, 13 Oct 2022 01:40:34 +0000 (18:40 -0700)
commit98672596626862e4b21319da7c01737bf7e20ae4
treec4bf34b92d92983b44ce97bb43c16ef2c93b2b50
parent4f158995b9cddae392bfb5989af8c83101ae0789
[clang][deps] Don't share in-memory VFS across scans

The dependency scanning worker may create an in-memory VFS and inject that into its `FileManager`. (Implemented in D109485.) This VFS currently persists between scans, which is not correct: in-memory files created in one scan could affect subsequent scans. This patch changes things so that the in-memory VFS is local to `DependencyScanningWorker::computeDependencies()`.

To test this, one would first scan for dependencies of a named module and then run second scan (on the same worker) for something unrelated, which would pick up the in-memory file created in the first scan. This set up is impossible to achieve with `clang-scan-deps`. We could set this up in `ToolingTests`, but the scanner needs to access the physical filesystem to store `.pcm` files. AFAIK we don't have a good way to propagate something like `%t` into unit tests to make that feasible. (This could be achieved with something like the virtualized `OutputManager`.)

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D135414
clang/include/clang/Basic/FileManager.h
clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp