Bug 1511258 - Fix ./mach clang-format -a so it doesn't make assumptions about the incoming file name. r=Ehsan
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 30 Nov 2018 04:02:58 +0000
changeset 505350 b9d92fc39034b25e4c8e1215d92e863335f7a018
parent 505349 8a30088cd2b2446add5d4ec4bf2813eecc792b04
child 505351 0e1dbfd1037861318aa39868eb658cc26ed225fc
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1511258
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -2808,31 +2808,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