[llvm-branch-commits] [clang] d93287c - [scan-build] Supprot relative 'file' in cdb.

Haowei Wu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 9 20:13:55 PST 2020


Author: Haowei Wu
Date: 2020-11-09T20:06:20-08:00
New Revision: d93287cac89fd50a105ac4a59c079884b8e53e49

URL: https://github.com/llvm/llvm-project/commit/d93287cac89fd50a105ac4a59c079884b8e53e49
DIFF: https://github.com/llvm/llvm-project/commit/d93287cac89fd50a105ac4a59c079884b8e53e49.diff

LOG: [scan-build] Supprot relative 'file' in cdb.

Excluded folders in scan build is turned to absolute path before
comapre to 'file' in cdb. 'file' in cdb might be a path relative
to 'directory', so we need to turn it to absolute path before
comparison.

Patch by Yu Shan

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

Added: 
    

Modified: 
    clang/tools/scan-build-py/libscanbuild/analyze.py

Removed: 
    


################################################################################
diff  --git a/clang/tools/scan-build-py/libscanbuild/analyze.py b/clang/tools/scan-build-py/libscanbuild/analyze.py
index ffdf7f7c7d61..a4bb499f86c9 100644
--- a/clang/tools/scan-build-py/libscanbuild/analyze.py
+++ b/clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -207,10 +207,14 @@ def write_global_map(arch, mangled_ast_pairs):
 def run_analyzer_parallel(args):
     """ Runs the analyzer against the given compilation database. """
 
-    def exclude(filename):
+    def exclude(filename, directory):
         """ Return true when any excluded directory prefix the filename. """
-        return any(re.match(r'^' + directory, filename)
-                   for directory in args.excludes)
+        if not os.path.isabs(filename):
+            # filename is either absolute or relative to directory. Need to turn
+            # it to absolute since 'args.excludes' are absolute paths.
+            filename = os.path.normpath(os.path.join(directory, filename))
+        return any(re.match(r'^' + exclude_directory, filename)
+                   for exclude_directory in args.excludes)
 
     consts = {
         'clang': args.clang,
@@ -225,7 +229,8 @@ def exclude(filename):
     logging.debug('run analyzer against compilation database')
     with open(args.cdb, 'r') as handle:
         generator = (dict(cmd, **consts)
-                     for cmd in json.load(handle) if not exclude(cmd['file']))
+                     for cmd in json.load(handle) if not exclude(
+                            cmd['file'], cmd['directory']))
         # when verbose output requested execute sequentially
         pool = multiprocessing.Pool(1 if args.verbose > 2 else None)
         for current in pool.imap_unordered(run, generator):


        


More information about the llvm-branch-commits mailing list