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']) # Select the appropriate files. for filename in get_all_toplevel_filenames(): if not filename.startswith('js/src/jit/'): continue if 'MacroAssembler' not in filename: continue if filename.endswith('MacroAssembler.h'): decls = append_signatures(decls, get_macroassembler_declaration(filename)) else: defs = append_signatures(defs, get_macroassembler_definitions(filename)) # Compare declarations and definitions output. difflines = difflib.unified_diff(generate_file_content(decls), generate_file_content(defs), fromfile='check_macroassembler_style.py declared syntax', tofile='check_macroassembler_style.py found definitions') ok = True for diffline in difflines: ok = False print(diffline, end='') return ok
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']) # Select the appropriate files. for filename in get_all_toplevel_filenames(): if not filename.startswith('js/src/jit/'): continue if 'MacroAssembler' not in filename: continue if filename.endswith('MacroAssembler.h'): decls = append_signatures(decls, get_macroassembler_declaration(filename)) else: defs = append_signatures(defs, get_macroassembler_definitions(filename)) # Compare declarations and definitions output. difflines = difflib.unified_diff( generate_file_content(decls), generate_file_content(defs), fromfile='check_macroassembler_style.py declared syntax', tofile='check_macroassembler_style.py found definitions') ok = True for diffline in difflines: ok = False print(diffline, end='') return ok
def check_files(): result = True for filename in get_all_toplevel_filenames(): if filename.endswith('.msg'): if filename not in ignore_files: if not check_single_file(filename): result = False return result
def check_style(): # We deal with two kinds of name. # - A "filename" is a full path to a file from the repository root. # - An "inclname" is how a file is referred to in a #include statement. # # Examples (filename -> inclname) # - "mfbt/Attributes.h" -> "mozilla/Attributes.h" # - "mfbt/decimal/Decimal.h -> "mozilla/Decimal.h" # - "js/public/Vector.h" -> "js/Vector.h" # - "js/src/vm/String.h" -> "vm/String.h" mfbt_inclnames = set() # type: set(inclname) mozalloc_inclnames = set() # type: set(inclname) js_names = dict() # type: dict(filename, inclname) # Select the appropriate files. for filename in get_all_toplevel_filenames(): if filename.startswith('mfbt/') and filename.endswith('.h'): inclname = 'mozilla/' + filename.split('/')[-1] mfbt_inclnames.add(inclname) if filename.startswith('memory/mozalloc/') and filename.endswith('.h'): inclname = 'mozilla/' + filename.split('/')[-1] mozalloc_inclnames.add(inclname) if filename.startswith('js/public/') and filename.endswith('.h'): inclname = 'js/' + filename[len('js/public/'):] js_names[filename] = inclname if filename.startswith('js/src/') and \ not filename.startswith(tuple(ignored_js_src_dirs)) and \ filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')): inclname = filename[len('js/src/'):] js_names[filename] = inclname all_inclnames = mfbt_inclnames | mozalloc_inclnames | set(js_names.values()) edges = dict() # type: dict(inclname, set(inclname)) # We don't care what's inside the MFBT and MOZALLOC files, but because they # are #included from JS files we have to add them to the inclusion graph. for inclname in mfbt_inclnames | mozalloc_inclnames: edges[inclname] = set() # Process all the JS files. for filename in js_names.keys(): inclname = js_names[filename] file_kind = FileKind.get(filename) if file_kind == FileKind.C or file_kind == FileKind.CPP or \ file_kind == FileKind.H or file_kind == FileKind.INL_H: included_h_inclnames = set() # type: set(inclname) # This script is run in js/src/, so prepend '../../' to get to the root of the Mozilla # source tree. with open(os.path.join('../..', filename)) as f: do_file(filename, inclname, file_kind, f, all_inclnames, included_h_inclnames) edges[inclname] = included_h_inclnames find_cycles(all_inclnames, edges) # Compare expected and actual output. difflines = difflib.unified_diff(expected_output, actual_output, fromfile='check_spider_monkey_style.py expected output', tofile='check_spider_monkey_style.py actual output') ok = True for diffline in difflines: ok = False print(diffline, end='') return ok
def check_style(): # We deal with two kinds of name. # - A "filename" is a full path to a file from the repository root. # - An "inclname" is how a file is referred to in a #include statement. # # Examples (filename -> inclname) # - "mfbt/Attributes.h" -> "mozilla/Attributes.h" # - "mfbt/decimal/Decimal.h -> "mozilla/Decimal.h" # - "mozglue/misc/TimeStamp.h -> "mozilla/TimeStamp.h" # - "memory/mozalloc/mozalloc.h -> "mozilla/mozalloc.h" # - "js/public/Vector.h" -> "js/Vector.h" # - "js/src/vm/String.h" -> "vm/String.h" non_js_dirnames = ('mfbt/', 'memory/mozalloc/', 'mozglue/' ) # type: tuple(str) non_js_inclnames = set() # type: set(inclname) js_names = dict() # type: dict(filename, inclname) # Select the appropriate files. for filename in get_all_toplevel_filenames(): for non_js_dir in non_js_dirnames: if filename.startswith(non_js_dir) and filename.endswith('.h'): inclname = 'mozilla/' + filename.split('/')[-1] non_js_inclnames.add(inclname) if filename.startswith('js/public/') and filename.endswith('.h'): inclname = 'js/' + filename[len('js/public/'):] js_names[filename] = inclname if filename.startswith('js/src/') and \ not filename.startswith(tuple(ignored_js_src_dirs)) and \ filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')): inclname = filename[len('js/src/'):] js_names[filename] = inclname all_inclnames = non_js_inclnames | set(js_names.values()) edges = dict() # type: dict(inclname, set(inclname)) # We don't care what's inside the MFBT and MOZALLOC files, but because they # are #included from JS files we have to add them to the inclusion graph. for inclname in non_js_inclnames: edges[inclname] = set() # Process all the JS files. for filename in js_names.keys(): inclname = js_names[filename] file_kind = FileKind.get(filename) if file_kind == FileKind.C or file_kind == FileKind.CPP or \ file_kind == FileKind.H or file_kind == FileKind.INL_H: included_h_inclnames = set() # type: set(inclname) # This script is run in js/src/, so prepend '../../' to get to the root of the Mozilla # source tree. with open(os.path.join('../..', filename)) as f: do_file(filename, inclname, file_kind, f, all_inclnames, included_h_inclnames) edges[inclname] = included_h_inclnames find_cycles(all_inclnames, edges) # Compare expected and actual output. difflines = difflib.unified_diff( expected_output, actual_output, fromfile='check_spider_monkey_style.py expected output', tofile='check_spider_monkey_style.py actual output') ok = True for diffline in difflines: ok = False print(diffline, end='') return ok