[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 15:02:45 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 5601e35f620eccdebab988bed4b9677b29366b79 2c9430526320b815f8722512f141e7a90f1c5eb1 -- clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp llvm/include/llvm/Support/VirtualFileSystem.h llvm/lib/Support/VirtualFileSystem.cpp llvm/unittests/Support/VirtualFileSystemTest.cpp clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 7b74b2b913..4d2109ef1d 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -310,8 +310,8 @@ public:
/// false if not (i.e. this entry is not a file or its scan fails).
bool ensureDirectiveTokensArePopulated(EntryRef Entry);
- /// Check whether \p Path exists. By default checks cached result of \c status(),
- /// and falls back on FS if unable to do so.
+ /// Check whether \p Path exists. By default checks cached result of \c
+ /// status(), and falls back on FS if unable to do so.
bool exists(const Twine &Path) override;
private:
diff --git a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index bd2fe4fe99..0693eba3a4 100644
--- a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -14,28 +14,32 @@
using namespace clang::tooling::dependencies;
namespace {
- struct InstrumentingInMemoryFilesystem
- : llvm::RTTIExtends<InstrumentingInMemoryFilesystem, llvm::vfs::InMemoryFileSystem> {
- unsigned NumStatCalls = 0;
+struct InstrumentingInMemoryFilesystem
+ : llvm::RTTIExtends<InstrumentingInMemoryFilesystem,
+ llvm::vfs::InMemoryFileSystem> {
+ unsigned NumStatCalls = 0;
- using llvm::RTTIExtends<InstrumentingInMemoryFilesystem,
- llvm::vfs::InMemoryFileSystem>::RTTIExtends;
-
- llvm::ErrorOr<llvm::vfs::Status> status(const llvm::Twine &Path) override {
- ++NumStatCalls;
- return InMemoryFileSystem::status(Path);
- }
- };
- } // namespace
+ using llvm::RTTIExtends<InstrumentingInMemoryFilesystem,
+ llvm::vfs::InMemoryFileSystem>::RTTIExtends;
+ llvm::ErrorOr<llvm::vfs::Status> status(const llvm::Twine &Path) override {
+ ++NumStatCalls;
+ return InMemoryFileSystem::status(Path);
+ }
+};
+} // namespace
TEST(DependencyScanningFilesystem, CacheStatOnExists) {
- auto InMemoryInstrumentingFS = llvm::makeIntrusiveRefCnt<InstrumentingInMemoryFilesystem>();
+ auto InMemoryInstrumentingFS =
+ llvm::makeIntrusiveRefCnt<InstrumentingInMemoryFilesystem>();
InMemoryInstrumentingFS->setCurrentWorkingDirectory("/");
- InMemoryInstrumentingFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer(""));
- InMemoryInstrumentingFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
+ InMemoryInstrumentingFS->addFile("/foo", 0,
+ llvm::MemoryBuffer::getMemBuffer(""));
+ InMemoryInstrumentingFS->addFile("/bar", 0,
+ llvm::MemoryBuffer::getMemBuffer(""));
DependencyScanningFilesystemSharedCache SharedCache;
- DependencyScanningWorkerFilesystem DepFS(SharedCache, InMemoryInstrumentingFS);
+ DependencyScanningWorkerFilesystem DepFS(SharedCache,
+ InMemoryInstrumentingFS);
DepFS.status("/foo");
DepFS.status("/foo");
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index 78fff0fcab..09a602748e 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -3443,51 +3443,51 @@ TEST(RedirectingFileSystemTest, ExternalPaths) {
TEST(RedirectingFileSystemTest, Exists) {
IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem());
auto YAML =
- MemoryBuffer::getMemBuffer("{\n"
- " 'version': 0,\n"
- " 'roots': [\n"
- " {\n"
- " 'type': 'directory-remap',\n"
- " 'name': '/dremap',\n"
- " 'external-contents': '/a',\n"
- " },"
- " {\n"
- " 'type': 'directory-remap',\n"
- " 'name': '/dmissing',\n"
- " 'external-contents': '/dmissing',\n"
- " },"
- " {\n"
- " 'type': 'directory',\n"
- " 'name': '/both',\n"
- " 'contents': [\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': 'vfile',\n"
- " 'external-contents': '/c'\n"
- " }\n"
- " ]\n"
- " },\n"
- " {\n"
- " 'type': 'directory',\n"
- " 'name': '/vdir',\n"
- " 'contents': ["
- " {\n"
- " 'type': 'directory-remap',\n"
- " 'name': 'dremap',\n"
- " 'external-contents': '/b'\n"
- " },\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': 'missing',\n"
- " 'external-contents': '/missing'\n"
- " },\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': 'vfile',\n"
- " 'external-contents': '/c'\n"
- " }]\n"
- " }]\n"
- "}");
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'directory-remap',\n"
+ " 'name': '/dremap',\n"
+ " 'external-contents': '/a',\n"
+ " },"
+ " {\n"
+ " 'type': 'directory-remap',\n"
+ " 'name': '/dmissing',\n"
+ " 'external-contents': '/dmissing',\n"
+ " },"
+ " {\n"
+ " 'type': 'directory',\n"
+ " 'name': '/both',\n"
+ " 'contents': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': 'vfile',\n"
+ " 'external-contents': '/c'\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " 'type': 'directory',\n"
+ " 'name': '/vdir',\n"
+ " 'contents': ["
+ " {\n"
+ " 'type': 'directory-remap',\n"
+ " 'name': 'dremap',\n"
+ " 'external-contents': '/b'\n"
+ " },\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': 'missing',\n"
+ " 'external-contents': '/missing'\n"
+ " },\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': 'vfile',\n"
+ " 'external-contents': '/c'\n"
+ " }]\n"
+ " }]\n"
+ "}");
Dummy->addDirectory("/a");
Dummy->addRegularFile("/a/foo");
@@ -3496,7 +3496,7 @@ TEST(RedirectingFileSystemTest, Exists) {
Dummy->addRegularFile("/both/foo");
auto Redirecting = vfs::RedirectingFileSystem::create(
- std::move(YAML), nullptr, "", nullptr, Dummy);
+ std::move(YAML), nullptr, "", nullptr, Dummy);
EXPECT_TRUE(Redirecting->exists("/dremap"));
EXPECT_FALSE(Redirecting->exists("/dmissing"));
@@ -3514,22 +3514,22 @@ TEST(RedirectingFileSystemTest, Exists) {
TEST(RedirectingFileSystemTest, ExistsFallback) {
IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem());
auto YAML =
- MemoryBuffer::getMemBuffer("{\n"
- " 'version': 0,\n"
- " 'redirecting-with': 'fallback',\n"
- " 'roots': [\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': '/fallback',\n"
- " 'external-contents': '/missing',\n"
- " },"
- " ]\n"
- "}");
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'redirecting-with': 'fallback',\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': '/fallback',\n"
+ " 'external-contents': '/missing',\n"
+ " },"
+ " ]\n"
+ "}");
Dummy->addRegularFile("/fallback");
auto Redirecting = vfs::RedirectingFileSystem::create(
- std::move(YAML), nullptr, "", nullptr, Dummy);
+ std::move(YAML), nullptr, "", nullptr, Dummy);
EXPECT_TRUE(Redirecting->exists("/fallback"));
EXPECT_FALSE(Redirecting->exists("/missing"));
@@ -3538,23 +3538,23 @@ TEST(RedirectingFileSystemTest, ExistsFallback) {
TEST(RedirectingFileSystemTest, ExistsRedirectOnly) {
IntrusiveRefCntPtr<DummyFileSystem> Dummy(new NoStatusDummyFileSystem());
auto YAML =
- MemoryBuffer::getMemBuffer("{\n"
- " 'version': 0,\n"
- " 'redirecting-with': 'redirect-only',\n"
- " 'roots': [\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': '/vfile',\n"
- " 'external-contents': '/a',\n"
- " },"
- " ]\n"
- "}");
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'redirecting-with': 'redirect-only',\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': '/vfile',\n"
+ " 'external-contents': '/a',\n"
+ " },"
+ " ]\n"
+ "}");
Dummy->addRegularFile("/a");
Dummy->addRegularFile("/b");
auto Redirecting = vfs::RedirectingFileSystem::create(
- std::move(YAML), nullptr, "", nullptr, Dummy);
+ std::move(YAML), nullptr, "", nullptr, Dummy);
EXPECT_FALSE(Redirecting->exists("/a"));
EXPECT_FALSE(Redirecting->exists("/b"));
``````````
</details>
https://github.com/llvm/llvm-project/pull/88152
More information about the cfe-commits
mailing list