plotfi updated this revision to Diff 213209. plotfi added a comment. Cleanup some stuff
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D65704/new/ https://reviews.llvm.org/D65704 Files: clang/include/clang/DirectoryWatcher/DirectoryWatcher.h clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp =================================================================== --- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp +++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp @@ -280,8 +280,8 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - - checkEventualResultWithTimeout(TestConsumer); + if (DW) + checkEventualResultWithTimeout(TestConsumer); } TEST(DirectoryWatcherTest, InitialScanAsync) { @@ -311,8 +311,8 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/false); - - checkEventualResultWithTimeout(TestConsumer); + if (DW) + checkEventualResultWithTimeout(TestConsumer); } TEST(DirectoryWatcherTest, AddFiles) { @@ -331,12 +331,12 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - - fixture.addFile("a"); - fixture.addFile("b"); - fixture.addFile("c"); - - checkEventualResultWithTimeout(TestConsumer); + if (DW) { + fixture.addFile("a"); + fixture.addFile("b"); + fixture.addFile("c"); + checkEventualResultWithTimeout(TestConsumer); + } } TEST(DirectoryWatcherTest, ModifyFile) { @@ -356,17 +356,18 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); + if (DW) { + // modify the file + { + std::error_code error; + llvm::raw_fd_ostream bStream(fixture.getPathInWatched("a"), error, + CD_OpenExisting); + assert(!error); + bStream << "foo"; + } - // modify the file - { - std::error_code error; - llvm::raw_fd_ostream bStream(fixture.getPathInWatched("a"), error, - CD_OpenExisting); - assert(!error); - bStream << "foo"; + checkEventualResultWithTimeout(TestConsumer); } - - checkEventualResultWithTimeout(TestConsumer); } TEST(DirectoryWatcherTest, DeleteFile) { @@ -386,10 +387,10 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - - fixture.deleteFile("a"); - - checkEventualResultWithTimeout(TestConsumer); + if (DW) { + fixture.deleteFile("a"); + checkEventualResultWithTimeout(TestConsumer); + } } TEST(DirectoryWatcherTest, DeleteWatchedDir) { @@ -407,10 +408,10 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - - remove_directories(fixture.TestWatchedDir); - - checkEventualResultWithTimeout(TestConsumer); + if (DW) { + remove_directories(fixture.TestWatchedDir); + checkEventualResultWithTimeout(TestConsumer); + } } TEST(DirectoryWatcherTest, InvalidatedWatcher) { @@ -427,7 +428,9 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); + if (DW) + return; } // DW is destructed here. checkEventualResultWithTimeout(TestConsumer); } \ No newline at end of file Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp =================================================================== --- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp +++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" #include "llvm/Support/Path.h" #include <CoreServices/CoreServices.h> @@ -205,7 +206,7 @@ FSEventStreamRelease(EventStream); } -std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create( +llvm::Expected<std::unique_ptr<DirectoryWatcher>> clang::DirectoryWatcher::create( StringRef Path, std::function<void(llvm::ArrayRef<DirectoryWatcher::Event>, bool)> Receiver, bool WaitForInitialSync) { @@ -213,12 +214,15 @@ dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL); if (Path.empty()) - return nullptr; + return llvm::make_error<llvm::StringError>( + std::string("Path.empty() error: ") + strerror(errno), + llvm::inconvertibleErrorCode()); auto EventStream = createFSEventStream(Path, Receiver, Queue); - if (!EventStream) { - return nullptr; - } + if (!EventStream) + return llvm::make_error<llvm::StringError>( + std::string("createFSEventStream() error: ") + strerror(errno), + llvm::inconvertibleErrorCode()); std::unique_ptr<DirectoryWatcher> Result = llvm::make_unique<DirectoryWatcherMac>(EventStream, Receiver, Path); Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp =================================================================== --- clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp +++ clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/ScopeExit.h" #include "llvm/Support/AlignOf.h" #include "llvm/Support/Errno.h" +#include "llvm/Support/Error.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Path.h" #include <atomic> @@ -321,16 +322,20 @@ } // namespace -std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create( +llvm::Expected<std::unique_ptr<DirectoryWatcher>> clang::DirectoryWatcher::create( StringRef Path, std::function<void(llvm::ArrayRef<DirectoryWatcher::Event>, bool)> Receiver, bool WaitForInitialSync) { if (Path.empty()) - return nullptr; + return llvm::make_error<llvm::StringError>( + std::string("Path.empty() error: ") + strerror(errno), + llvm::inconvertibleErrorCode()); const int InotifyFD = inotify_init1(IN_CLOEXEC); if (InotifyFD == -1) - return nullptr; + return llvm::make_error<llvm::StringError>( + std::string("inotify_init1() error: ") + strerror(errno), + llvm::inconvertibleErrorCode()); const int InotifyWD = inotify_add_watch( InotifyFD, Path.str().c_str(), @@ -341,12 +346,16 @@ #endif ); if (InotifyWD == -1) - return nullptr; + return llvm::make_error<llvm::StringError>( + std::string("inotify_add_watch() error: ") + strerror(errno), + llvm::inconvertibleErrorCode(); auto InotifyPollingStopper = SemaphorePipe::create(); if (!InotifyPollingStopper) - return nullptr; + return llvm::make_error<llvm::StringError>( + std::string("SemaphorePipe::create() error: ") + strerror(errno), + llvm::inconvertibleErrorCode()); return llvm::make_unique<DirectoryWatcherLinux>( Path, Receiver, WaitForInitialSync, InotifyFD, InotifyWD, Index: clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp =================================================================== --- clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp +++ clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp @@ -11,9 +11,11 @@ using namespace llvm; using namespace clang; -std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create( +llvm::Expected<std::unique_ptr<DirectoryWatcher>> clang::DirectoryWatcher::create( StringRef Path, std::function<void(llvm::ArrayRef<DirectoryWatcher::Event>, bool)> Receiver, bool WaitForInitialSync) { - return nullptr; + return llvm::make_error<llvm::StringError>( + "DirectoryWatcher is not implemented for this platform!", + llvm::inconvertibleErrorCode()); } \ No newline at end of file Index: clang/include/clang/DirectoryWatcher/DirectoryWatcher.h =================================================================== --- clang/include/clang/DirectoryWatcher/DirectoryWatcher.h +++ clang/include/clang/DirectoryWatcher/DirectoryWatcher.h @@ -11,6 +11,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" #include <functional> #include <memory> #include <string> @@ -101,7 +102,7 @@ /// Returns nullptr if \param Path doesn't exist or isn't a directory. /// Returns nullptr if OS kernel API told us we can't start watching. In such /// case it's unclear whether just retrying has any chance to succeeed. - static std::unique_ptr<DirectoryWatcher> + static llvm::Expected<std::unique_ptr<DirectoryWatcher>> create(llvm::StringRef Path, std::function<void(llvm::ArrayRef<DirectoryWatcher::Event> Events, bool IsInitial)>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits