Bug 1391231 - Use the list provided by .clang-format-ignore instead of only thirdpartypath.txt r?gps draft
authorSylvestre Ledru <sledru@mozilla.com>
Thu, 17 Aug 2017 15:22:06 +0200
changeset 648268 243370a84b576c7f5fa302b197940f938ee6c490
parent 648195 6df5a4a0b721eb2890bf274a05d7d17ede8edd41
child 726756 4fcff77810575efe3dcea56583603c06e8abf1eb
push id74679
push userbmo:sledru@mozilla.com
push dateThu, 17 Aug 2017 13:23:33 +0000
reviewersgps
bugs1391231
milestone57.0a1
Bug 1391231 - Use the list provided by .clang-format-ignore instead of only thirdpartypath.txt r?gps MozReview-Commit-ID: CY1fS7Fg1y
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -271,39 +271,44 @@ class FormatProvider(MachCommandBase):
         args = [sys.executable, clang_format_diff, "-p1"]
         if not show:
             args.append("-i")
         cf_process = Popen(args, stdin=diff_process.stdout)
         return cf_process.communicate()[0]
 
     def generate_path_list(self, paths):
         pathToThirdparty = os.path.join(self.topsrcdir,
-                                        "tools",
-                                        "rewriting",
-                                        "ThirdPartyPaths.txt")
-        with open(pathToThirdparty) as f:
-            # Normalize the path (no trailing /)
-            ignored_dir = tuple(d.rstrip('/') for d in f.read().splitlines())
+                                        ".clang-format-ignore")
+        ignored_dir = []
+        for line in open(pathToThirdparty):
+            # Remove comments and empty lines
+            if line.startswith('#') or len(line.strip()) == 0:
+                continue
+            ignored_dir.append(line.rstrip())
 
+        # Generates the list of regexp
+        ignored_dir_re = '(%s)' % '|'.join(ignored_dir)
         extensions = ('.cpp', '.c', '.h')
 
         path_list = []
         for f in paths:
-            if f.startswith(ignored_dir):
+            import re
+            if re.match(ignored_dir_re, f):
+                # Early exit if we have provided an ignored directory
                 print("clang-format: Ignored third party code '{0}'".format(f))
                 continue
 
             if os.path.isdir(f):
                 # Processing a directory, generate the file list
                 for folder, subs, files in os.walk(f):
                     subs.sort()
                     for filename in sorted(files):
                         f_in_dir = os.path.join(folder, filename)
-                        if f_in_dir.endswith(extensions):
-                            # Supported extension
+                        if f_in_dir.endswith(extensions) and not re.match(ignored_dir_re, f_in_dir):
+                            # Supported extension and accepted path
                             path_list.append(f_in_dir)
             else:
                 if f.endswith(extensions):
                     path_list.append(f)
 
         return path_list
 
     def run_clang_format_path(self, clang_format, show, paths):