Bug 1400283 - check_macroassembler_style.py: flake8 consistency r?nbp draft
authorSylvestre Ledru <sledru@mozilla.com>
Fri, 15 Sep 2017 18:14:41 +0200
changeset 665496 f3f2441e2502b5b15eb103e41a351345ee90ce23
parent 665495 43c36d78d14cd0887b1c640f5c0e0ad2695066bd
child 731809 160ea5474fd8e0ce0a4c1d6b1eca680bbc9865d9
push id80091
push userbmo:sledru@mozilla.com
push dateFri, 15 Sep 2017 16:22:07 +0000
reviewersnbp
bugs1400283
milestone57.0a1
Bug 1400283 - check_macroassembler_style.py: flake8 consistency r?nbp MozReview-Commit-ID: 3J98Ni80BdW
config/check_macroassembler_style.py
--- a/config/check_macroassembler_style.py
+++ b/config/check_macroassembler_style.py
@@ -1,53 +1,54 @@
 # vim: set ts=8 sts=4 et sw=4 tw=99:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-#----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
 # This script checks that SpiderMonkey MacroAssembler methods are properly
 # annotated.
 #
 # The MacroAssembler has one interface for all platforms, but it might have one
 # definition per platform. The code of the MacroAssembler use a macro to
 # annotate the method declarations, in order to delete the function if it is not
 # present on the current platform, and also to locate the files in which the
 # methods are defined.
 #
 # This script scans the MacroAssembler.h header, for method declarations.
 # It also scans MacroAssembler-/arch/.cpp, MacroAssembler-/arch/-inl.h, and
 # MacroAssembler-inl.h for method definitions. The result of both scans are
 # uniformized, and compared, to determine if the MacroAssembler.h header as
 # proper methods annotations.
-#----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
 
 from __future__ import print_function
 
 import difflib
 import os
 import re
 import sys
 
 from mozversioncontrol import get_repository_from_env
 
 
-architecture_independent = set([ 'generic' ])
-all_unsupported_architectures_names = set([ 'mips32', 'mips64', 'mips_shared' ])
-all_architecture_names = set([ 'x86', 'x64', 'arm', 'arm64' ])
-all_shared_architecture_names = set([ 'x86_shared', 'arm', 'arm64' ])
+architecture_independent = set(['generic'])
+all_unsupported_architectures_names = set(['mips32', 'mips64', 'mips_shared'])
+all_architecture_names = set(['x86', 'x64', 'arm', 'arm64'])
+all_shared_architecture_names = set(['x86_shared', 'arm', 'arm64'])
 
 reBeforeArg = "(?<=[(,\s])"
 reArgType = "(?P<type>[\w\s:*&]+)"
 reArgName = "(?P<name>\s\w+)"
 reArgDefault = "(?P<default>(?:\s=[^,)]+)?)"
 reAfterArg = "(?=[,)])"
 reMatchArg = re.compile(reBeforeArg + reArgType + reArgName + reArgDefault + reAfterArg)
 
-def get_normalized_signatures(signature, fileAnnot = None):
+
+def get_normalized_signatures(signature, fileAnnot=None):
     # Remove static
     signature = signature.replace('static', '')
     # Remove semicolon.
     signature = signature.replace(';', ' ')
     # Normalize spaces.
     signature = re.sub(r'\s+', ' ', signature).strip()
     # Match arguments, and keep only the type.
     signature = reMatchArg.sub('\g<type>', signature)
@@ -83,28 +84,31 @@ def get_normalized_signatures(signature,
 
     if 'inline ' in signature:
         signature = re.sub(r'inline\s+', '', signature)
         inline = True
 
     inlinePrefx = ''
     if inline:
         inlinePrefx = 'inline '
-    signatures =  [
-        { 'arch': a, 'sig': inlinePrefx + signature }
+    signatures = [
+        {'arch': a, 'sig': inlinePrefx + signature}
         for a in archs
     ]
 
     return signatures
 
+
 file_suffixes = set([
     a.replace('_', '-') for a in
     all_architecture_names.union(all_shared_architecture_names)
                           .union(all_unsupported_architectures_names)
 ])
+
+
 def get_file_annotation(filename):
     origFilename = filename
     filename = filename.split('/')[-1]
 
     inline = False
     if filename.endswith('.cpp'):
         filename = filename[:-len('.cpp')]
     elif filename.endswith('-inl.h'):
@@ -119,16 +123,17 @@ def get_file_annotation(filename):
             arch = suffix
             break
 
     return {
         'inline': inline,
         'arch': arch.replace('-', '_')
     }
 
+
 def get_macroassembler_definitions(filename):
     try:
         fileAnnot = get_file_annotation(filename)
     except:
         return []
 
     style_section = False
     code_section = False
@@ -142,17 +147,17 @@ def get_macroassembler_definitions(filen
                 style_section = False
             if not style_section:
                 continue
 
             line = re.sub(r'//.*', '', line)
             if line.startswith('{') or line.strip() == "{}":
                 if 'MacroAssembler::' in lines:
                     signatures.extend(get_normalized_signatures(lines, fileAnnot))
-                if line.strip() != "{}": # Empty declaration, no need to declare
+                if line.strip() != "{}":  # Empty declaration, no need to declare
                     # a new code section
                     code_section = True
                 continue
             if line.startswith('}'):
                 code_section = False
                 lines = ''
                 continue
             if code_section:
@@ -167,16 +172,17 @@ def get_macroassembler_definitions(filen
                 continue
             # Skip variable declarations
             if ')' not in lines:
                 lines = ''
                 continue
 
     return signatures
 
+
 def get_macroassembler_declaration(filename):
     style_section = False
     lines = ''
     signatures = []
     with open(filename) as f:
         for line in f:
             if '//{{{ check_macroassembler_style' in line:
                 style_section = True
@@ -198,23 +204,25 @@ def get_macroassembler_declaration(filen
                 lines = ''
                 continue
 
             signatures.extend(get_normalized_signatures(lines))
             lines = ''
 
     return signatures
 
+
 def append_signatures(d, sigs):
     for s in sigs:
         if s['sig'] not in d:
             d[s['sig']] = []
-        d[s['sig']].append(s['arch']);
+        d[s['sig']].append(s['arch'])
     return d
 
+
 def generate_file_content(signatures):
     output = []
     for s in sorted(signatures.keys()):
         archs = set(sorted(signatures[s]))
         archs -= all_unsupported_architectures_names
         if len(archs.symmetric_difference(architecture_independent)) == 0:
             output.append(s + ';\n')
             if s.startswith('inline'):
@@ -232,16 +240,17 @@ def generate_file_content(signatures):
                 a = a.replace('_', '-')
                 masm = '%s/MacroAssembler-%s' % (a, a)
                 if s.startswith('inline'):
                     output.append('    is defined in %s-inl.h\n' % masm)
                 else:
                     output.append('    is defined in %s.cpp\n' % masm)
     return output
 
+
 def check_style():
     # We read from the header file the signature of each function.
     decls = dict()      # type: dict(signature => ['x86', 'x64'])
 
     # We infer from each file the signature of each MacroAssembler function.
     defs = dict()       # type: dict(signature => ['x86', 'x64'])
 
     with get_repository_from_env() as repo:
@@ -273,15 +282,15 @@ def check_style():
 
 
 def main():
     ok = check_style()
 
     if ok:
         print('TEST-PASS | check_macroassembler_style.py | ok')
     else:
-        print('TEST-UNEXPECTED-FAIL | check_macroassembler_style.py | actual output does not match expected output;  diff is above')
+        print('TEST-UNEXPECTED-FAIL | check_macroassembler_style.py | actual output does not match expected output;  diff is above')  # noqa: E501
 
     sys.exit(0 if ok else 1)
 
 
 if __name__ == '__main__':
     main()