From: Eric Liu Date: Thu, 24 Mar 2016 11:25:28 +0000 (+0000) Subject: Revert "Added support for different VFSs in format::getStyle." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0589759dbfe6d07b1998e516aa7a64a907d13e76;p=clang Revert "Added support for different VFSs in format::getStyle." This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264257 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 650da68097..eef651e636 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -16,7 +16,6 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" #include @@ -833,13 +832,11 @@ extern const char *StyleOptionHelpDescription; /// == "file". /// \param[in] FallbackStyle The name of a predefined style used to fallback to /// in case the style can't be determined from \p StyleName. -/// \param[in] FS The underlying file system, in which the file resides. By -/// default, the file system is the real file system. /// /// \returns FormatStyle as specified by ``StyleName``. If no style could be /// determined, the default is LLVM Style (see ``getLLVMStyle()``). FormatStyle getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyle, vfs::FileSystem *FS = nullptr); + StringRef FallbackStyle); } // end namespace format } // end namespace clang diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 6d03b62920..31dc259d4c 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -2099,10 +2099,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { } FormatStyle getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyle, vfs::FileSystem *FS) { - if (!FS) { - FS = vfs::getRealFileSystem().get(); - } + StringRef FallbackStyle) { FormatStyle Style = getLLVMStyle(); Style.Language = getLanguageByFileName(FileName); if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style)) { @@ -2133,35 +2130,28 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName, llvm::sys::fs::make_absolute(Path); for (StringRef Directory = Path; !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { - - auto Status = FS->status(Directory); - if (!Status || - Status->getType() != llvm::sys::fs::file_type::directory_file) { + if (!llvm::sys::fs::is_directory(Directory)) continue; - } - SmallString<128> ConfigFile(Directory); llvm::sys::path::append(ConfigFile, ".clang-format"); DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); + bool IsFile = false; // Ignore errors from is_regular_file: we only need to know if we can read // the file or not. - Status = FS->status(ConfigFile.str()); - bool IsFile = - Status && (Status->getType() == llvm::sys::fs::file_type::regular_file); + llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); + if (!IsFile) { // Try _clang-format too, since dotfiles are not commonly used on Windows. ConfigFile = Directory; llvm::sys::path::append(ConfigFile, "_clang-format"); DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); - Status = FS->status(ConfigFile.str()); - IsFile = Status && - (Status->getType() == llvm::sys::fs::file_type::regular_file); + llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); } if (IsFile) { llvm::ErrorOr> Text = - FS->getBufferForFile(ConfigFile.str()); + llvm::MemoryBuffer::getFile(ConfigFile.c_str()); if (std::error_code EC = Text.getError()) { llvm::errs() << EC.message() << "\n"; break; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 319f63ded5..d2ec4e645c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -14,7 +14,6 @@ #include "clang/Frontend/TextDiagnosticPrinter.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/MemoryBuffer.h" #include "gtest/gtest.h" #define DEBUG_TYPE "format-test" @@ -11200,33 +11199,6 @@ TEST_F(FormatTest, FormatsTableGenCode) { verifyFormat("include \"a.td\"\ninclude \"b.td\"", Style); } -TEST(FormatStyle, GetStyleOfFile) { - vfs::InMemoryFileSystem FS; - // Test 1: format file in the same directory. - ASSERT_TRUE( - FS.addFile("/a/.clang-format", 0, - llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: LLVM"))); - ASSERT_TRUE( - FS.addFile("/a/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;"))); - auto Style1 = getStyle("file", "/a/.clang-format", "Google", &FS); - ASSERT_EQ(Style1, getLLVMStyle()); - - // Test 2: fallback to default. - ASSERT_TRUE( - FS.addFile("/b/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;"))); - auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", &FS); - ASSERT_EQ(Style2, getMozillaStyle()); - - // Test 3: format file in parent directory. - ASSERT_TRUE( - FS.addFile("/c/.clang-format", 0, - llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google"))); - ASSERT_TRUE(FS.addFile("/c/sub/sub/sub/test.cpp", 0, - llvm::MemoryBuffer::getMemBuffer("int i;"))); - auto Style3 = getStyle("file", "/c/sub/sub/sub/test.cpp", "LLVM", &FS); - ASSERT_EQ(Style3, getGoogleStyle()); -} - class ReplacementTest : public ::testing::Test { protected: tooling::Replacement createReplacement(SourceLocation Start, unsigned Length,