[clang-tools-extra] r317468 - [clang-tidy] Support relative paths in run-clang-tidy.py

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 02:36:02 PST 2017


Author: xazax
Date: Mon Nov  6 02:36:02 2017
New Revision: 317468

URL: http://llvm.org/viewvc/llvm-project?rev=317468&view=rev
Log:
[clang-tidy] Support relative paths in run-clang-tidy.py

Unfortunately, these python scripts are not tested currently. I did the testing
manually on LLVM by editing the CMake generated compilation database to
contain relative paths for some of the files. 

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

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

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=317468&r1=317467&r2=317468&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 Mon Nov  6 02:36:02 2017
@@ -68,6 +68,12 @@ def find_compilation_database(path):
   return os.path.realpath(result)
 
 
+def make_absolute(f, directory):
+  if os.path.isabs(f):
+    return f
+  return os.path.normpath(os.path.join(directory, f))
+
+
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
                         header_filter, extra_arg, extra_arg_before, quiet):
   """Gets a command line for clang-tidy."""
@@ -223,7 +229,8 @@ def main():
 
   # Load the database and extract all files.
   database = json.load(open(os.path.join(build_path, db_path)))
-  files = [entry['file'] for entry in database]
+  files = [make_absolute(entry['file'], entry['directory'])
+           for entry in database]
 
   max_task = args.j
   if max_task == 0:




More information about the cfe-commits mailing list