# HG changeset patch # User Emilio Cobos Alvarez # Date 1543550578 0 # Node ID b9d92fc39034b25e4c8e1215d92e863335f7a018 # Parent a5d88a7f51dfb726a791d308e1821cd344daa7ce Bug 1511258 - Fix ./mach clang-format -a so it doesn't make assumptions about the incoming file name. r=Ehsan I tried to use it to write a git merge driver. Git merge drivers receive garbage names like .merge_file_EE7Nlw. That's clearly not a useful file name to give to _generate_path_list. Instead, give the path name to be assumed, which is actually the right path name to use. Differential Revision: https://phabricator.services.mozilla.com/D13505 diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -2643,31 +2643,31 @@ class StaticAnalysis(MachCommandBase): path_list.append(f_in_dir) else: if f.endswith(extensions): path_list.append(f) return path_list def _run_clang_format_in_console(self, clang_format, paths, assume_filename): - path_list = self._generate_path_list(paths, False) - - if path_list == [] and paths[0].endswith(self._format_include_extensions): + path_list = self._generate_path_list(assume_filename, False) + + if path_list == []: # This means we are dealing with a third party so just return it's content with open(paths[0], 'r') as fin: sys.stdout.write(fin.read().decode('utf8')) return 0 # We use -assume-filename in order to better determine the path for # the .clang-format when it is ran outside of the repo, for example - # by the extemssion hg-formatsource + # by the extension hg-formatsource args = [clang_format, "-assume-filename={}".format(assume_filename[0])] process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - with open(path_list[0], 'r') as fin: + with open(paths[0], 'r') as fin: process.stdin.write(fin.read()) output = process.communicate()[0] process.stdin.close() sys.stdout.write(output.decode('utf8')) return 0 def _run_clang_format_path(self, clang_format, show, paths): # Run clang-format on files or directories directly