[PATCH] D28334: [clang-tidy] Add -extra-arg and -extra-arg-before to run-clang-tidy.py

2017-01-04 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan created this revision.
ehsan added reviewers: bkramer, alexfh, klimek.
ehsan added a subscriber: cfe-commits.
Herald added a subscriber: JDevlieghere.

These flags allow specifying extra arguments to the tool's command
line which don't appear in the compilation database.


https://reviews.llvm.org/D28334

Files:
  clang-tidy/tool/run-clang-tidy.py


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):
+header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
 (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
 os.close(handle)
 start.append(name)
+  for arg in extra_arg:
+  start.append('-extra-arg=%s' % arg[0])
+  for arg in extra_arg_before:
+  start.append('-extra-arg-before=%s' % arg[0])
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
 name = queue.get()
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
- tmpdir, build_path, args.header_filter)
+ tmpdir, build_path, args.header_filter,
+ args.extra_arg, args.extra_arg_before)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -130,6 +135,14 @@
   'after applying fixes')
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  nargs=1, action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  nargs=1, action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'


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):
+header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
 (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
 os.close(handle)
 start.append(name)
+  for arg in extra_arg:
+  start.append('-extra-arg=%s' % arg[0])
+  for arg in extra_arg_before:
+  start.append('-extra-arg-before=%s' % arg[0])
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
 name = queue.get()
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
- tmpdir, build_path, args.header_filter)
+ tmpdir, build_path, args.header_filter,
+ args.extra_arg, args.extra_arg_before)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -130,6 +135,14 @@
   'after applying fixes')
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  nargs=1, action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  nargs=1, action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28334: [clang-tidy] Add -extra-arg and -extra-arg-before to run-clang-tidy.py

2017-01-18 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan marked an inline comment as done.
ehsan added inline comments.



Comment at: clang-tidy/tool/run-clang-tidy.py:80
+  for arg in extra_arg:
+  start.append('-extra-arg=%s' % arg[0])
+  for arg in extra_arg_before:

alexfh wrote:
> Why arg[0] and not just arg?
With nargs=1, extra_arg would be something like [['foo'], ['bar']] if 
-extra-arg foo -extra-arg bar is passed.  But I realized that there is no good 
reason why I need nargs=1 since action='append' will make the arg parser 
consume one argument, so I'll remove that and simplify this to just arg.


https://reviews.llvm.org/D28334



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28334: [clang-tidy] Add -extra-arg and -extra-arg-before to run-clang-tidy.py

2017-01-18 Thread Ehsan Akhgari via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
ehsan marked an inline comment as done.
Closed by commit rL292415: [clang-tidy] Add -extra-arg and -extra-arg-before to 
run-clang-tidy.py (authored by ehsan).

Changed prior to commit:
  https://reviews.llvm.org/D28334?vs=83165&id=84854#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28334

Files:
  clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/trunk/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):
+header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
 (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
 os.close(handle)
 start.append(name)
+  for arg in extra_arg:
+  start.append('-extra-arg=%s' % arg)
+  for arg in extra_arg_before:
+  start.append('-extra-arg-before=%s' % arg)
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
 name = queue.get()
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
- tmpdir, build_path, args.header_filter)
+ tmpdir, build_path, args.header_filter,
+ args.extra_arg, args.extra_arg_before)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -130,6 +135,14 @@
   'after applying fixes')
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'


Index: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/trunk/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):
+header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
 (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
 os.close(handle)
 start.append(name)
+  for arg in extra_arg:
+  start.append('-extra-arg=%s' % arg)
+  for arg in extra_arg_before:
+  start.append('-extra-arg-before=%s' % arg)
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
 name = queue.get()
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
- tmpdir, build_path, args.header_filter)
+ tmpdir, build_path, args.header_filter,
+ args.extra_arg, args.extra_arg_before)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -130,6 +135,14 @@
   'after applying fixes')
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29661: [clang-tidy] Add -quiet option to suppress extra output

2017-02-07 Thread Ehsan Akhgari via Phabricator via cfe-commits
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-filte

[PATCH] D29699: [clang-tidy] Add -extra-arg and -extra-arg-before to clang-tidy-diff.py

2017-02-07 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan created this revision.
Herald added a subscriber: JDevlieghere.

These flags allow specifying extra arguments to the tool's command
line which don't appear in the compilation database.


https://reviews.llvm.org/D29699

Files:
  clang-tidy/tool/clang-tidy-diff.py


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,14 @@
   help='checks filter, when not specified, use clang-tidy '
   'default',
   default='')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -113,6 +121,10 @@
   if args.checks != '':
 command.append('-checks=' + quote + args.checks + quote)
   command.extend(lines_by_file.keys())
+  for arg in args.extra_arg:
+  command.append('-extra-arg=%s' % arg)
+  for arg in args.extra_arg_before:
+  command.append('-extra-arg-before=%s' % arg)
   command.extend(clang_tidy_args)
 
   sys.exit(subprocess.call(' '.join(command), shell=True))


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,14 @@
   help='checks filter, when not specified, use clang-tidy '
   'default',
   default='')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -113,6 +121,10 @@
   if args.checks != '':
 command.append('-checks=' + quote + args.checks + quote)
   command.extend(lines_by_file.keys())
+  for arg in args.extra_arg:
+  command.append('-extra-arg=%s' % arg)
+  for arg in args.extra_arg_before:
+  command.append('-extra-arg-before=%s' % arg)
   command.extend(clang_tidy_args)
 
   sys.exit(subprocess.call(' '.join(command), shell=True))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29699: [clang-tidy] Add -extra-arg and -extra-arg-before to clang-tidy-diff.py

2017-02-07 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan added a comment.

This is equivalent to https://reviews.llvm.org/D28334 for clang-tidy-diff.py.


https://reviews.llvm.org/D29699



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29699: [clang-tidy] Add -extra-arg and -extra-arg-before to clang-tidy-diff.py

2017-02-08 Thread Ehsan Akhgari via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL294491: [clang-tidy] Add -extra-arg and -extra-arg-before to 
clang-tidy-diff.py (authored by ehsan).

Changed prior to commit:
  https://reviews.llvm.org/D29699?vs=87576&id=87673#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29699

Files:
  clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py


Index: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
@@ -55,6 +55,14 @@
   help='checks filter, when not specified, use clang-tidy '
   'default',
   default='')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -113,6 +121,10 @@
   if args.checks != '':
 command.append('-checks=' + quote + args.checks + quote)
   command.extend(lines_by_file.keys())
+  for arg in args.extra_arg:
+  command.append('-extra-arg=%s' % arg)
+  for arg in args.extra_arg_before:
+  command.append('-extra-arg-before=%s' % arg)
   command.extend(clang_tidy_args)
 
   sys.exit(subprocess.call(' '.join(command), shell=True))


Index: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
@@ -55,6 +55,14 @@
   help='checks filter, when not specified, use clang-tidy '
   'default',
   default='')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+  action='append', default=[],
+  help='Additional argument to append to the compiler '
+  'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+  action='append', default=[],
+  help='Additional argument to prepend to the compiler '
+  'command line.')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -113,6 +121,10 @@
   if args.checks != '':
 command.append('-checks=' + quote + args.checks + quote)
   command.extend(lines_by_file.keys())
+  for arg in args.extra_arg:
+  command.append('-extra-arg=%s' % arg)
+  for arg in args.extra_arg_before:
+  command.append('-extra-arg-before=%s' % arg)
   command.extend(clang_tidy_args)
 
   sys.exit(subprocess.call(' '.join(command), shell=True))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29661: [clang-tidy] Add -quiet option to suppress extra output

2017-02-09 Thread Ehsan Akhgari via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL294607: [clang-tidy] Add -quiet option to suppress extra 
output (authored by ehsan).

Changed prior to commit:
  https://reviews.llvm.org/D29661?vs=87469&id=87842#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29661

Files:
  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

Index: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
+++ clang-tools-extra/trunk/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 
 // 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:
+

[PATCH] D29806: [clang-tidy] Add -path option to clang-tidy-diff.py

2017-02-09 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan created this revision.
Herald added a subscriber: JDevlieghere.

This flag allows specifying a custom path for the compilation
database.  Unfortunately we can't use the -p flag like other
clang-tidy tools because it's already taken.


https://reviews.llvm.org/D29806

Files:
  clang-tidy/tool/clang-tidy-diff.py
  test/clang-tidy/clang-tidy-diff.cpp


Index: test/clang-tidy/clang-tidy-diff.cpp
===
--- test/clang-tidy/clang-tidy-diff.cpp
+++ test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 
%t.cpp", "file": "%t.cpp"}]' > 
%T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff 
-checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | 
FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
Index: clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tidy/tool/clang-tidy-diff.py
+++ clang-tidy/tool/clang-tidy-diff.py
@@ -26,11 +26,23 @@
 
 import argparse
 import json
+import os
 import re
 import subprocess
 import sys
 
 
+def find_compilation_database(path):
+  """Adjusts the directory until a compilation database is found."""
+  result = './'
+  while not os.path.isfile(os.path.join(result, path)):
+if os.path.realpath(result) == '/':
+  print 'Error: could not find compilation database.'
+  sys.exit(1)
+result += '../'
+  return os.path.realpath(result)
+
+
 def main():
   parser = argparse.ArgumentParser(description=
'Run clang-tidy against changed files, and '
@@ -55,6 +67,8 @@
   help='checks filter, when not specified, use clang-tidy '
   'default',
   default='')
+  parser.add_argument('-path', dest='build_path',
+  help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
   action='append', default=[],
   help='Additional argument to append to the compiler '
@@ -73,6 +87,14 @@
 
   args = parser.parse_args(argv)
 
+  db_path = 'compile_commands.json'
+
+  if args.build_path is not None:
+build_path = args.build_path
+  else:
+# Find our database
+build_path = find_compilation_database(db_path)
+
   # Extract changed lines for each file.
   filename = None
   lines_by_file = {}
@@ -124,6 +146,7 @@
 command.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
 command.append('-quiet')
+  command.append('-p=%s' % build_path)
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
   command.append('-extra-arg=%s' % arg)


Index: test/clang-tidy/clang-tidy-diff.cpp
===
--- test/clang-tidy/clang-tidy-diff.cpp
+++ test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
Index: clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tidy/tool/clang-tidy-diff.py
+++ clang-tidy/tool/clang-tidy-diff.py
@@ -26,11 +26,23 @@
 
 import argparse
 import json
+import os
 import re
 import subprocess
 import sys
 
 
+def find_compilation_database(path):
+  """Adjusts the directory until a compilation database is found."""
+  result = './'
+  while not os.path.isfile(os.path.join(result, path)):
+if os.path.realpath(result) == '/':
+  print 'Error: could not find compilation database.'
+  sys.exit(1)
+result += '../'
+  return os.path.realpath(result)
+
+
 def main():
   parser = argpa

[PATCH] D29806: [clang-tidy] Add -path option to clang-tidy-diff.py

2017-02-10 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan added a comment.

In https://reviews.llvm.org/D29806#673329, @alexfh wrote:

> What's your use case? Can it be addressed by just forwarding the -p flag to 
> clang-tidy?


I just need to pass the full path to the compilation DB to clang-tidy.  The 
problem is that invoking `clang-tidy-diff.py -- -p PATH` will run `clang-tidy 
-- -p PATH`, in order words adding -p to the compiler command line, not 
clang-tidy's.

> The script shouldn't know anything about implementation details of the 
> compilation database being used (since it can be something other than JSON 
> compilation database).

I copied the code to look for the DB verbatim from run-clang-tidy.py.  I 
personally don't need the search logic, and just tried to keep this consistent 
with run-clang-tidy.py.  I'd be happy to remove the search logic if you prefer 
that.


https://reviews.llvm.org/D29806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29806: [clang-tidy] Add -path option to clang-tidy-diff.py

2017-02-16 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan added a comment.

Gentle ping.  :-)


https://reviews.llvm.org/D29806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29806: [clang-tidy] Add -path option to clang-tidy-diff.py

2017-02-17 Thread Ehsan Akhgari via Phabricator via cfe-commits
ehsan updated this revision to Diff 88879.
ehsan added a comment.

Addressed the review comments.


https://reviews.llvm.org/D29806

Files:
  clang-tidy/tool/clang-tidy-diff.py
  test/clang-tidy/clang-tidy-diff.cpp


Index: test/clang-tidy/clang-tidy-diff.cpp
===
--- test/clang-tidy/clang-tidy-diff.cpp
+++ test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 
%t.cpp", "file": "%t.cpp"}]' > 
%T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff 
-checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | 
FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
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('-path', dest='build_path',
+  help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
   action='append', default=[],
   help='Additional argument to append to the compiler '
@@ -124,6 +126,8 @@
 command.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
 command.append('-quiet')
+  if args.build_path is not None:
+command.append('-p=%s' % args.build_path)
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
   command.append('-extra-arg=%s' % arg)


Index: test/clang-tidy/clang-tidy-diff.cpp
===
--- test/clang-tidy/clang-tidy-diff.cpp
+++ test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
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('-path', dest='build_path',
+  help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
   action='append', default=[],
   help='Additional argument to append to the compiler '
@@ -124,6 +126,8 @@
 command.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
 command.append('-quiet')
+  if args.build_path is not None:
+command.append('-p=%s' % args.build_path)
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
   command.append('-extra-arg=%s' % arg)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29806: [clang-tidy] Add -path option to clang-tidy-diff.py

2017-02-17 Thread Ehsan Akhgari via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295482: [clang-tidy] Add -path option to clang-tidy-diff.py 
(authored by ehsan).

Changed prior to commit:
  https://reviews.llvm.org/D29806?vs=88879&id=88959#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29806

Files:
  clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
  clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 
%t.cpp", "file": "%t.cpp"}]' > 
%T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff 
-checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | 
FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
Index: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/trunk/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('-path', dest='build_path',
+  help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
   action='append', default=[],
   help='Additional argument to append to the compiler '
@@ -124,6 +126,8 @@
 command.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
 command.append('-quiet')
+  if args.build_path is not None:
+command.append('-p=%s' % args.build_path)
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
   command.append('-extra-arg=%s' % arg)


Index: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
@@ -2,6 +2,9 @@
 // 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
+// RUN: mkdir -p %T/compilation-database-test/
+// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
Index: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/trunk/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('-path', dest='build_path',
+  help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
   action='append', default=[],
   help='Additional argument to append to the compiler '
@@ -124,6 +126,8 @@
 command.append('-checks=' + quote + args.checks + quote)
   if args.quiet:
 command.append('-quiet')
+  if args.build_path is not None:
+command.append('-p=%s' % args.build_path)
   command.extend(lines_by_file.keys())
   for arg in args.extra_arg:
   command.append('-extra-arg=%s' % arg)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits