[clang-tools-extra] r275051 - [clang-tidy] Pass absolute path to OptionsProvider::getOptions/getRawOptions.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 11 00:47:05 PDT 2016


Author: hokein
Date: Mon Jul 11 02:47:04 2016
New Revision: 275051

URL: http://llvm.org/viewvc/llvm-project?rev=275051&view=rev
Log:
[clang-tidy] Pass absolute path to OptionsProvider::getOptions/getRawOptions.

Summary:
Although there is no guarantee of getOptions/getRawOptions receiving an
absolute path, we try to make it if possible. So FileOptionProvider subclasses
don't have to convert the path to an absolute path.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D22154

Added:
    clang-tools-extra/trunk/test/clang-tidy/list-checks.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp?rev=275051&r1=275050&r2=275051&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp Mon Jul 11 02:47:04 2016
@@ -218,15 +218,6 @@ FileOptionsProvider::FileOptionsProvider
 std::vector<OptionsSource>
 FileOptionsProvider::getRawOptions(StringRef FileName) {
   DEBUG(llvm::dbgs() << "Getting options for file " << FileName << "...\n");
-  SmallString<256> FilePath(FileName);
-
-  if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
-    llvm::errs() << "Can't make absolute path from " << FileName << ": "
-                 << EC.message() << "\n";
-    // FIXME: Figure out what to do.
-  } else {
-    FileName = FilePath;
-  }
 
   std::vector<OptionsSource> RawOptions =
       DefaultOptionsProvider::getRawOptions(FileName);

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=275051&r1=275050&r2=275051&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Jul 11 02:47:04 2016
@@ -313,13 +313,19 @@ static int clangTidyMain(int argc, const
   if (!PathList.empty()) {
     FileName = PathList.front();
   }
-  ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
+
+  SmallString<256> FilePath(FileName);
+  if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
+    llvm::errs() << "Can't make absolute path from " << FileName << ": "
+                 << EC.message() << "\n";
+  }
+  ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
   std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
 
   if (ExplainConfig) {
     //FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
     std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
-        RawOptions = OptionsProvider->getRawOptions(FileName);
+        RawOptions = OptionsProvider->getRawOptions(FilePath);
     for (const std::string &Check : EnabledChecks) {
       for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
         if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {

Added: clang-tools-extra/trunk/test/clang-tidy/list-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/list-checks.cpp?rev=275051&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/list-checks.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/list-checks.cpp Mon Jul 11 02:47:04 2016
@@ -0,0 +1,5 @@
+// REQUIRES: shell
+// RUN: mkdir -p %T/clang-tidy/list-checks/
+// RUN: echo '{Checks: "-*,google-*"}' > %T/clang-tidy/.clang-tidy
+// RUN: cd %T/clang-tidy/list-checks
+// RUN: clang-tidy -list-checks | grep "^ *google-"




More information about the cfe-commits mailing list