Bug 1391231 - Use the list provided by .clang-format-ignore instead of only thirdpartypath.txt r?gps
MozReview-Commit-ID: CY1fS7Fg1y
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -4,16 +4,17 @@
from __future__ import absolute_import, unicode_literals
import sys
import os
import stat
import platform
import errno
+import re
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
from mozbuild.base import MachCommandBase, MozbuildObject
@@ -271,39 +272,43 @@ 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):
+ 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):