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

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 17 04:23:04 PST 2017


alexfh added a comment.

In https://reviews.llvm.org/D29806#673489, @ehsan wrote:

> 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.


I meant adding -p flag to the script and forwarding it to clang-tidy the same way as -quiet, -checks, etc. But there's already -p flag with a different meaning, so calling the new flag -path makes sense. I would still just forward it, if it's present.

>> 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.

I see. I guess, this is needed as an optimization or something like that. Not useful for clang-tidy-diff.py.



================
Comment at: clang-tidy/tool/clang-tidy-diff.py:35-45
+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)
----------------
Let's remove this.


================
Comment at: clang-tidy/tool/clang-tidy-diff.py:90-97
+  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)
----------------
Let's remove this.


================
Comment at: clang-tidy/tool/clang-tidy-diff.py:149
     command.append('-quiet')
+  command.append('-p=%s' % build_path)
   command.extend(lines_by_file.keys())
----------------
Let's only add this flag when `args.build_path is not None`.


https://reviews.llvm.org/D29806





More information about the cfe-commits mailing list