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 14:44:46 +0200
changeset 648262 ba589a9002f7798fb81a14cc8adb2f0310ac5f40
parent 648195 6df5a4a0b721eb2890bf274a05d7d17ede8edd41
child 648263 10028a29ab92472aed31e0bcd78eed387ec85f19
push id74673
push userbmo:sledru@mozilla.com
push dateThu, 17 Aug 2017 12:45:24 +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,28 +271,32 @@ 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):
                 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):