[clang-tools-extra] r294607 - [clang-tidy] Add -quiet option to suppress extra output

Ehsan Akhgari via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 9 10:32:02 PST 2017


Author: ehsan
Date: Thu Feb  9 12:32:02 2017
New Revision: 294607

URL: http://llvm.org/viewvc/llvm-project?rev=294607&view=rev
Log:
[clang-tidy] Add -quiet option to suppress extra output

Summary:
This new flag instructs clang-tidy to not output anything
except for errors and warnings.  This makes it easier to
script clang-tidy to run as part of external build systems.

Reviewers: bkramer, alexfh, klimek

Subscribers: JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D29661

Modified:
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
    clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
    clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
    clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
    clang-tools-extra/trunk/test/clang-tidy/werrors-diagnostics.cpp
    clang-tools-extra/trunk/test/clang-tidy/werrors-plural.cpp
    clang-tools-extra/trunk/test/clang-tidy/werrors.cpp

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=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Thu Feb  9 12:32:02 2017
@@ -188,6 +188,15 @@ code with clang-apply-replacements.
                                         cl::value_desc("filename"),
                                         cl::cat(ClangTidyCategory));
 
+static cl::opt<bool> Quiet("quiet", cl::desc(R"(
+Run clang-tidy in quiet mode.  This suppresses
+printing statistics about ignored warnings and
+warnings treated as errors if the respective
+options are specified.
+)"),
+                           cl::init(false),
+                           cl::cat(ClangTidyCategory));
+
 namespace clang {
 namespace tidy {
 
@@ -406,19 +415,23 @@ static int clangTidyMain(int argc, const
     exportReplacements(FilePath.str(), Errors, OS);
   }
 
-  printStats(Stats);
-  if (DisableFixes)
-    llvm::errs()
-        << "Found compiler errors, but -fix-errors was not specified.\n"
-           "Fixes have NOT been applied.\n\n";
+  if (!Quiet) {
+    printStats(Stats);
+    if (DisableFixes)
+      llvm::errs()
+          << "Found compiler errors, but -fix-errors was not specified.\n"
+             "Fixes have NOT been applied.\n\n";
+  }
 
   if (EnableCheckProfile)
     printProfileData(Profile, llvm::errs());
 
   if (WErrorCount) {
-    StringRef Plural = WErrorCount == 1 ? "" : "s";
-    llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
-                 << Plural << "\n";
+    if (!Quiet) {
+      StringRef Plural = WErrorCount == 1 ? "" : "s";
+      llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
+                   << Plural << "\n";
+    }
     return WErrorCount;
   }
 

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Thu Feb  9 12:32:02 2017
@@ -63,6 +63,8 @@ def main():
                       action='append', default=[],
                       help='Additional argument to prepend to the compiler '
                       'command line.')
+  parser.add_argument('-quiet', action='store_true', default=False,
+                      help='Run clang-tidy in quiet mode')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -120,6 +122,8 @@ def main():
     command.append('-fix')
   if args.checks != '':
     command.append('-checks=' + quote + args.checks + quote)
+  if args.quiet:
+    command.append('-quiet')
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
       command.append('-extra-arg=%s' % arg)

Modified: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py Thu Feb  9 12:32:02 2017
@@ -59,7 +59,7 @@ def find_compilation_database(path):
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-                        header_filter, extra_arg, extra_arg_before):
+                        header_filter, extra_arg, extra_arg_before, quiet):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -81,6 +81,8 @@ def get_tidy_invocation(f, clang_tidy_bi
   for arg in extra_arg_before:
       start.append('-extra-arg-before=%s' % arg)
   start.append('-p=' + build_path)
+  if quiet:
+      start.append('-quiet')
   start.append(f)
   return start
 
@@ -101,7 +103,8 @@ def run_tidy(args, tmpdir, build_path, q
     name = queue.get()
     invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
                                      tmpdir, build_path, args.header_filter,
-                                     args.extra_arg, args.extra_arg_before)
+                                     args.extra_arg, args.extra_arg_before,
+                                     args.quiet)
     sys.stdout.write(' '.join(invocation) + '\n')
     subprocess.call(invocation)
     queue.task_done()
@@ -143,6 +146,8 @@ def main():
                       action='append', default=[],
                       help='Additional argument to prepend to the compiler '
                       'command line.')
+  parser.add_argument('-quiet', action='store_true',
+                      help='Run clang-tidy in quiet mode')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'

Modified: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp Thu Feb  9 12:32:02 2017
@@ -1,18 +1,23 @@
 // RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
 // RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
 // RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
 struct A {
   virtual void f() {}
   virtual void g() {}
 };
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 struct B : public A {
   void placeholder_for_f() {}
 // CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this
 // CHECK: [[@LINE-2]]:8: warning: annotate this
+// CHECK-QUIET: [[@LINE-3]]:8: warning: annotate this
   void g() {}
 // CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 };
 // CHECK-SANITY-NOT: Suppressed
 // CHECK: Suppressed 1 warnings (1 due to line filter).
+// CHECK-QUIET-NOT: Suppressed

Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Thu Feb  9 12:32:02 2017
@@ -1,45 +1,73 @@
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-QUIET %s
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2-QUIET %s
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3-QUIET %s
 // FIXME: "-I %S/Inputs/file-filter/system/.." must be redundant.
 //       On Win32, file-filter/system\system-header1.h precedes
 //       file-filter\header*.h due to code order between '/' and '\\'.
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers -quiet %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4-QUIET %s
 
 #include "header1.h"
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 // CHECK2: header1.h:1:12: warning: single-argument constructors must be marked explicit
+// CHECK2-QUIET: header1.h:1:12: warning: single-argument constructors must be marked explicit
 // CHECK3-NOT: warning:
+// CHECK3-QUIET-NOT: warning:
 // CHECK4: header1.h:1:12: warning: single-argument constructors
+// CHECK4-QUIET: header1.h:1:12: warning: single-argument constructors
 
 #include "header2.h"
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 // CHECK2: header2.h:1:12: warning: single-argument constructors
+// CHECK2-QUIET: header2.h:1:12: warning: single-argument constructors
 // CHECK3: header2.h:1:12: warning: single-argument constructors
+// CHECK3-QUIET: header2.h:1:12: warning: single-argument constructors
 // CHECK4: header2.h:1:12: warning: single-argument constructors
+// CHECK4-QUIET: header2.h:1:12: warning: single-argument constructors
 
 #include <system-header.h>
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 // CHECK2-NOT: warning:
+// CHECK2-QUIET-NOT: warning:
 // CHECK3-NOT: warning:
+// CHECK3-QUIET-NOT: warning:
 // CHECK4: system-header.h:1:12: warning: single-argument constructors
+// CHECK4-QUIET: system-header.h:1:12: warning: single-argument constructors
 
 class A { A(int); };
 // CHECK: :[[@LINE-1]]:11: warning: single-argument constructors
-// CHECK2: :[[@LINE-2]]:11: warning: single-argument constructors
-// CHECK3: :[[@LINE-3]]:11: warning: single-argument constructors
-// CHECK4: :[[@LINE-4]]:11: warning: single-argument constructors
+// CHECK-QUIET: :[[@LINE-2]]:11: warning: single-argument constructors
+// CHECK2: :[[@LINE-3]]:11: warning: single-argument constructors
+// CHECK2-QUIET: :[[@LINE-4]]:11: warning: single-argument constructors
+// CHECK3: :[[@LINE-5]]:11: warning: single-argument constructors
+// CHECK3-QUIET: :[[@LINE-6]]:11: warning: single-argument constructors
+// CHECK4: :[[@LINE-7]]:11: warning: single-argument constructors
+// CHECK4-QUIET: :[[@LINE-8]]:11: warning: single-argument constructors
 
 // CHECK-NOT: warning:
+// CHECK-QUIET-NOT: warning:
 // CHECK2-NOT: warning:
+// CHECK2-QUIET-NOT: warning:
 // CHECK3-NOT: warning:
+// CHECK3-QUIET-NOT: warning:
 // CHECK4-NOT: warning:
+// CHECK4-QUIET-NOT: warning:
 
 // CHECK: Suppressed 3 warnings (3 in non-user code)
 // CHECK: Use -header-filter=.* to display errors from all non-system headers.
+// CHECK-QUIET-NOT: Suppressed
 // CHECK2: Suppressed 1 warnings (1 in non-user code)
 // CHECK2: Use -header-filter=.* {{.*}}
+// CHECK2-QUIET-NOT: Suppressed
 // CHECK3: Suppressed 2 warnings (2 in non-user code)
 // CHECK3: Use -header-filter=.* {{.*}}
+// CHECK3-QUIET-NOT: Suppressed
 // CHECK4-NOT: Suppressed {{.*}} warnings
 // CHECK4-NOT: Use -header-filter=.* {{.*}}
+// CHECK4-QUIET-NOT: Suppressed

Modified: clang-tools-extra/trunk/test/clang-tidy/werrors-diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/werrors-diagnostics.cpp?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/werrors-diagnostics.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/werrors-diagnostics.cpp Thu Feb  9 12:32:02 2017
@@ -4,10 +4,15 @@
 // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
 // RUN:   -warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
+// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN:   -warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
 
 void f() { int i; }
 // CHECK-WARN: warning: unused variable 'i' [clang-diagnostic-unused-variable]
 // CHECK-WERR: error: unused variable 'i' [clang-diagnostic-unused-variable,-warnings-as-errors]
+// CHECK-WERR-QUIET: error: unused variable 'i' [clang-diagnostic-unused-variable,-warnings-as-errors]
 
 // CHECK-WARN-NOT: treated as
 // CHECK-WERR: 1 warning treated as error
+// CHECK-WERR-QUIET-NOT: treated as

Modified: clang-tools-extra/trunk/test/clang-tidy/werrors-plural.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/werrors-plural.cpp?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/werrors-plural.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/werrors-plural.cpp Thu Feb  9 12:32:02 2017
@@ -3,16 +3,22 @@
 // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
 // RUN:   -warnings-as-errors='llvm-namespace-comment' -- 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
+// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN:   -warnings-as-errors='llvm-namespace-comment' -quiet -- 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
 
 namespace j {
 }
 // CHECK-WARN: warning: namespace 'j' not terminated with a closing comment [llvm-namespace-comment]
 // CHECK-WERR: error: namespace 'j' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
+// CHECK-WERR-QUIET: error: namespace 'j' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
 
 namespace k {
 }
 // CHECK-WARN: warning: namespace 'k' not terminated with a closing comment [llvm-namespace-comment]
 // CHECK-WERR: error: namespace 'k' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
+// CHECK-WERR-QUIET: error: namespace 'k' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
 
 // CHECK-WARN-NOT: treated as
 // CHECK-WERR: 2 warnings treated as errors
+// CHECK-WERR-QUIET-NOT: treated as

Modified: clang-tools-extra/trunk/test/clang-tidy/werrors.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/werrors.cpp?rev=294607&r1=294606&r2=294607&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/werrors.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/werrors.cpp Thu Feb  9 12:32:02 2017
@@ -1,10 +1,13 @@
 // RUN: clang-tidy %s -checks='-*,llvm-namespace-comment' -- 2>&1 | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:'
 // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment' -warnings-as-errors='llvm-namespace-comment' -- 2>&1 | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
+// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment' -warnings-as-errors='llvm-namespace-comment' -quiet -- 2>&1 | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
 
 namespace i {
 }
 // CHECK-WARN: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment]
 // CHECK-WERR: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
+// CHECK-WERR-QUIET: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
 
 // CHECK-WARN-NOT: treated as
 // CHECK-WERR: 1 warning treated as error
+// CHECK-WERR-QUIET-NOT: treated as




More information about the cfe-commits mailing list