ehsan created this revision.
Herald added a subscriber: JDevlieghere.

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.


https://reviews.llvm.org/D29661

Files:
  clang-tidy/tool/ClangTidyMain.cpp
  clang-tidy/tool/clang-tidy-diff.py
  clang-tidy/tool/run-clang-tidy.py
  test/clang-tidy/clang-tidy-diff.cpp
  test/clang-tidy/file-filter.cpp
  test/clang-tidy/werrors-diagnostics.cpp
  test/clang-tidy/werrors-plural.cpp
  test/clang-tidy/werrors.cpp

Index: test/clang-tidy/werrors.cpp
===================================================================
--- test/clang-tidy/werrors.cpp
+++ test/clang-tidy/werrors.cpp
@@ -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
Index: test/clang-tidy/werrors-plural.cpp
===================================================================
--- test/clang-tidy/werrors-plural.cpp
+++ test/clang-tidy/werrors-plural.cpp
@@ -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
Index: test/clang-tidy/werrors-diagnostics.cpp
===================================================================
--- test/clang-tidy/werrors-diagnostics.cpp
+++ test/clang-tidy/werrors-diagnostics.cpp
@@ -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
Index: test/clang-tidy/file-filter.cpp
===================================================================
--- test/clang-tidy/file-filter.cpp
+++ test/clang-tidy/file-filter.cpp
@@ -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
Index: test/clang-tidy/clang-tidy-diff.cpp
===================================================================
--- test/clang-tidy/clang-tidy-diff.cpp
+++ test/clang-tidy/clang-tidy-diff.cpp
@@ -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
Index: clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -59,7 +59,7 @@
 
 
 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 @@
   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 @@
     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 @@
                       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'
Index: clang-tidy/tool/clang-tidy-diff.py
===================================================================
--- clang-tidy/tool/clang-tidy-diff.py
+++ clang-tidy/tool/clang-tidy-diff.py
@@ -55,6 +55,8 @@
                       help='checks filter, when not specified, use clang-tidy '
                       'default',
                       default='')
+  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:
@@ -112,6 +114,8 @@
     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())
   command.extend(clang_tidy_args)
 
Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -188,6 +188,15 @@
                                         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,
+check profile data 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 @@
     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 (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;
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D29661: [clang... Ehsan Akhgari via Phabricator via cfe-commits

Reply via email to