Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py =================================================================== --- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py +++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py @@ -17,9 +17,9 @@ detect clang-tidy regressions in the lines touched by a specific patch. Example usage for git/svn users: - git diff -U0 HEAD^ | clang-tidy-diff.py -p1 + git diff -U0 HEAD^ | clang-tidy-diff.py -strip 1 svn diff --diff-cmd=diff -x-U0 | \ - clang-tidy-diff.py -fix -checks=-*,modernize-use-override + clang-tidy-diff.py -- -fix -checks=-*,modernize-use-override """ @@ -119,12 +119,14 @@ parser = argparse.ArgumentParser(description= 'Run clang-tidy against changed files, and ' 'output diagnostics only for modified ' - 'lines.') + 'lines.' + ' clang-tidy arguments can be passed after a \'--\'.' + ' Ex.: \'git diff -U0 HEAD^ | clang-tidy-diff.py -strip 1 -- -fix -checks=-*,modernize-use-override\'') parser.add_argument('-clang-tidy-binary', metavar='PATH', default='clang-tidy', help='path to clang-tidy binary') - parser.add_argument('-p', metavar='NUM', default=0, - help='strip the smallest prefix containing P slashes') + parser.add_argument('-strip', metavar='NUM', default=0, + help='strip the smallest prefix containing NUM slashes') parser.add_argument('-regex', metavar='PATTERN', default=None, help='custom pattern selecting file paths to check ' '(case sensitive, overrides -iregex)') @@ -136,34 +138,14 @@ help='number of tidy instances to be run in parallel.') parser.add_argument('-timeout', type=int, default=None, help='timeout per each file in seconds.') - parser.add_argument('-fix', action='store_true', default=False, - help='apply suggested fixes') - parser.add_argument('-checks', - help='checks filter, when not specified, use clang-tidy ' - 'default', - default='') - parser.add_argument('-use-color', action='store_true', - help='Use colors in output') - parser.add_argument('-path', dest='build_path', - help='Path used to read a compile command database.') if yaml: parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes', help='Create a yaml file to store suggested fixes in, ' 'which can be applied with clang-apply-replacements.') - 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.') - 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: - clang_tidy_args.extend(argv[argv.index('--'):]) + clang_tidy_args.extend(argv[argv.index('--')+1:]) argv = argv[:argv.index('--')] args = parser.parse_args(argv) @@ -172,7 +154,7 @@ filename = None lines_by_file = {} for line in sys.stdin: - match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line) + match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.strip, line) if match: filename = match.group(2) if filename is None: @@ -217,22 +199,6 @@ # Run a pool of clang-tidy workers. start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout) - # Form the common args list. - common_clang_tidy_args = [] - if args.fix: - common_clang_tidy_args.append('-fix') - if args.checks != '': - common_clang_tidy_args.append('-checks=' + args.checks) - if args.quiet: - common_clang_tidy_args.append('-quiet') - if args.build_path is not None: - common_clang_tidy_args.append('-p=%s' % args.build_path) - if args.use_color: - common_clang_tidy_args.append('--use-color') - for arg in args.extra_arg: - common_clang_tidy_args.append('-extra-arg=%s' % arg) - for arg in args.extra_arg_before: - common_clang_tidy_args.append('-extra-arg-before=%s' % arg) for name in lines_by_file: line_filter_json = json.dumps( @@ -248,7 +214,6 @@ (handle, tmp_name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir) os.close(handle) command.append('-export-fixes=' + tmp_name) - command.extend(common_clang_tidy_args) command.append(name) command.extend(clang_tidy_args) Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -79,6 +79,8 @@ - Generalized the `modernize-use-default-member-init` check to handle non-default constructors. +- `clang-tidy-diff.py` allows using `clang-tidy` flags after `--`. This is a breaking change, check the script help for usage. + New checks ^^^^^^^^^^ Index: clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp +++ clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp @@ -1,11 +1,11 @@ // REQUIRES: shell // 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 +// 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 +// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -- -checks=-*,modernize-use-override -p=%T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s struct A { virtual void f() {} virtual void g() {}