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'])

    repo = get_repository_from_env()

    # Select the appropriate files.
    for filename in repo.get_files_in_working_directory():
        if not filename.startswith('js/src/jit/'):
            continue
        if 'MacroAssembler' not in filename:
            continue

        filename = os.path.join(repo.path, filename)

        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
Пример #2
0
def check_files():
    result = True

    with get_repository_from_env() as repo:
        root = repo.path

        for filename, _ in repo.get_tracked_files_finder().find('**/*.msg'):
            if filename not in ignore_files:
                if not check_single_file(os.path.join(root, filename)):
                    result = False

    return result
Пример #3
0
def check_files():
    result = True

    with get_repository_from_env() as repo:
        root = repo.path

        for filename in repo.get_files_in_working_directory():
            if filename.endswith('.msg'):
                if filename not in ignore_files:
                    if not check_single_file(os.path.join(root, filename)):
                        result = False

    return result
def check_files():
    result = True

    repo = get_repository_from_env()
    root = repo.path

    for filename in repo.get_files_in_working_directory():
        if filename.endswith('.msg'):
            if filename not in ignore_files:
                if not check_single_file(os.path.join(root, filename)):
                    result = False

    return result
Пример #5
0
def check_style(enable_fixup):
    # 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)

    with get_repository_from_env() as repo:
        # Select the appropriate files.
        for filename in repo.get_files_in_working_directory():
            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.
            filepath = os.path.join(repo.path, filename)
            with open(filepath) as f:
                code = read_file(f)

            if enable_fixup:
                code = code.sorted(inclname)
                with open(filepath, 'w') as f:
                    f.write(code.to_source())

            check_file(filename, inclname, file_kind, code, 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_spidermonkey_style.py expected output',
        tofile='check_spidermonkey_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)

    with get_repository_from_env() as repo:
        # Select the appropriate files.
        for filename in repo.get_files_in_working_directory():
            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(repo.path, 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_spidermonkey_style.py expected output',
                                       tofile='check_spidermonkey_style.py actual output')
    ok = True
    for diffline in difflines:
        ok = False
        print(diffline, end='')

    return ok
Пример #7
0
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)

    repo = get_repository_from_env()

    # Select the appropriate files.
    for filename in repo.get_files_in_working_directory():
        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(repo.path, 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)

    return True