def main():
    # Change stderr to write with replacement characters so we don't die
    # if we try to print something containing non-ASCII characters.
    stderr_stream = codecs.StreamReaderWriter(sys.stderr, codecs.getreader("utf8"), codecs.getwriter("utf8"), "replace")
    # Setting an "encoding" attribute on the stream is necessary to
    # prevent the logging module from raising an error.  See
    # the checker.configure_logging() function for more information.
    stderr_stream.encoding = "UTF-8"

    args = sys.argv[1:]

    # Checking for the verbose flag before calling check_webkit_style_parser()
    # lets us enable verbose logging earlier.
    is_verbose = "-v" in args or "--verbose" in args

    checker.configure_logging(stream=stderr_stream, is_verbose=is_verbose)
    _log.debug("Verbose logging enabled.")

    parser = OptionParser()
    parser.add_option(
        "-v", "--verbose", action="store_true", dest="verbose", default=False, help="print status messages to stdout"
    )
    parser.add_option(
        "-d", "--define", action="store", type="string", dest="define", default="", help="specify define to eliminate"
    )

    (options, paths) = parser.parse_args()
    _log.debug("paths: %s, options: %s" % (paths, options))

    cwd = os.path.abspath(os.curdir)

    if not paths:
        _log.error("Give at least one specific path to eliminate define.")
        sys.exit(1)

    checkout_root = None

    paths = change_directory(checkout_root=checkout_root, paths=paths)

    code_eliminator = CodeEliminator(options.define)
    file_reader = TextFileReader(code_eliminator)

    file_reader.process_paths(paths)

    file_count = file_reader.file_count

    _log.info("%d files" % (file_count))
    # We fail when there are no checked files.
    sys.exit((file_count == 0))
Example #2
0
    def main(self):
        args = sys.argv[1:]

        host = Host()
        host.initialize_scm()

        stderr = self._engage_awesome_stderr_hacks()

        # Checking for the verbose flag before calling check_webkit_style_parser()
        # lets us enable verbose logging earlier.
        is_verbose = "-v" in args or "--verbose" in args

        checker.configure_logging(stream=stderr, is_verbose=is_verbose)
        _log.debug("Verbose logging enabled.")

        parser = checker.check_webkit_style_parser()
        (paths, options) = parser.parse(args)

        configuration = checker.check_webkit_style_configuration(options)

        paths = change_directory(host.filesystem,
                                 checkout_root=host.scm().checkout_root,
                                 paths=paths)

        style_processor = StyleProcessor(configuration)
        file_reader = TextFileReader(host.filesystem, style_processor)

        if paths and not options.diff_files:
            file_reader.process_paths(paths)
            file_reader.do_association_check(host.scm().checkout_root)
        else:
            changed_files = paths if options.diff_files else None
            patch = host.scm().create_patch(options.git_commit,
                                            changed_files=changed_files,
                                            git_index=options.git_index)
            patch_checker = PatchReader(file_reader)
            patch_checker.check(patch)

        error_count = style_processor.error_count
        file_count = file_reader.file_count
        delete_only_file_count = file_reader.delete_only_file_count

        _log.info("Total errors found: %d in %d files" %
                  (error_count, file_count))
        # We fail when style errors are found or there are no checked files.
        return error_count > 0 or (file_count == 0
                                   and delete_only_file_count == 0)
Example #3
0
    def main(self):
        args = sys.argv[1:]

        host = Host()
        host.initialize_scm()

        stderr = self._engage_awesome_stderr_hacks()

        # Checking for the verbose flag before calling check_webkit_style_parser()
        # lets us enable verbose logging earlier.
        is_verbose = "-v" in args or "--verbose" in args

        checker.configure_logging(stream=stderr, is_verbose=is_verbose)
        _log.debug("Verbose logging enabled.")

        parser = checker.check_webkit_style_parser()
        (paths, options) = parser.parse(args)

        configuration = checker.check_webkit_style_configuration(options)

        paths = change_directory(host.filesystem, checkout_root=host.scm().checkout_root, paths=paths)

        style_processor = StyleProcessor(configuration)
        file_reader = TextFileReader(host.filesystem, style_processor)

        if paths and not options.diff_files:
            file_reader.process_paths(paths)
        else:
            changed_files = paths if options.diff_files else None
            patch = host.scm().create_patch(options.git_commit, changed_files=changed_files)
            patch_checker = PatchReader(file_reader)
            patch_checker.check(patch)

        error_count = style_processor.error_count
        file_count = file_reader.file_count
        delete_only_file_count = file_reader.delete_only_file_count

        _log.info("Total errors found: %d in %d files" % (error_count, file_count))
        # We fail when style errors are found or there are no checked files.
        return error_count > 0
Example #4
0
    def setUp(self):
        is_verbose = self.is_verbose

        log_stream = TestLogStream(self)

        # Use a logger other than the root logger or one prefixed with
        # webkit so as not to conflict with test-webkitpy logging.
        logger = logging.getLogger("unittest")

        # Configure the test logger not to pass messages along to the
        # root logger.  This prevents test messages from being
        # propagated to loggers used by test-webkitpy logging (e.g.
        # the root logger).
        logger.propagate = False

        self._handlers = configure_logging(stream=log_stream, logger=logger,
                                           is_verbose=is_verbose)
        self._log = logger
        self._log_stream = log_stream
Example #5
0
    def setUp(self):
        is_verbose = self.is_verbose

        log_stream = TestLogStream(self)

        # Use a logger other than the root logger or one prefixed with
        # webkit so as not to conflict with test-webkitpy logging.
        logger = logging.getLogger("unittest")

        # Configure the test logger not to pass messages along to the
        # root logger.  This prevents test messages from being
        # propagated to loggers used by test-webkitpy logging (e.g.
        # the root logger).
        logger.propagate = False

        self._handlers = configure_logging(stream=log_stream, logger=logger,
                                           is_verbose=is_verbose)
        self._log = logger
        self._log_stream = log_stream
Example #6
0
    def run_style_tests(self, suite_args):

        # TODO: not yet ready
        return True

        # Code based on http://svn.webkit.org/repository/webkit/trunk/Tools/Scripts/check-webkit-style

        thisdir = os.path.dirname(os.path.abspath(__file__))

        args = suite_args
        if not args:
            args = [os.path.abspath(
                os.path.join(thisdir, os.pardir, os.pardir, os.pardir)
            )]
        _log = log

        sys.path.append(os.path.join(thisdir, os.pardir, 'third_party'))

        from webkitpy.style_references import detect_checkout
        import webkitpy.style.checker as checker
        from webkitpy.style.patchreader import PatchReader
        from webkitpy.style.checker import StyleProcessor
        from webkitpy.style.filereader import TextFileReader
        from webkitpy.style.main import change_directory

        # Change stderr to write with replacement characters so we don't die
        # if we try to print something containing non-ASCII characters.
        stderr = codecs.StreamReaderWriter(sys.stderr,
                                           codecs.getreader('utf8'),
                                           codecs.getwriter('utf8'),
                                           'replace')
        # Setting an "encoding" attribute on the stream is necessary to
        # prevent the logging module from raising an error.  See
        # the checker.configure_logging() function for more information.
        stderr.encoding = "UTF-8"

        # FIXME: Change webkitpy.style so that we do not need to overwrite
        #        the global sys.stderr.  This involves updating the code to
        #        accept a stream parameter where necessary, and not calling
        #        sys.stderr explicitly anywhere.
        sys.stderr = stderr

        #SYNTH args = sys.argv[1:]

        # Checking for the verbose flag before calling check_webkit_style_parser()
        # lets us enable verbose logging earlier.
        is_verbose = "-v" in args or "--verbose" in args

        checker.configure_logging(stream=stderr, is_verbose=is_verbose)
        _log.debug("Verbose logging enabled.")

        parser = checker.check_webkit_style_parser()
        (paths, options) = parser.parse(args)

        checkout = detect_checkout()

        if checkout is None:
            if not paths:
                _log.error("WebKit checkout not found: You must run this script "
                           "from within a WebKit checkout if you are not passing "
                           "specific paths to check.")
                sys.exit(1)

            checkout_root = None
            _log.debug("WebKit checkout not found for current directory.")
        else:
            checkout_root = checkout.root_path()
            _log.debug("WebKit checkout found with root: %s" % checkout_root)

        configuration = checker.check_webkit_style_configuration(options)

        paths = change_directory(checkout_root=checkout_root, paths=paths)

        style_processor = StyleProcessor(configuration)

        file_reader = TextFileReader(style_processor)

        if paths and not options.diff_files:
            file_reader.process_paths(paths)
        else:
            changed_files = paths if options.diff_files else None
            patch = checkout.create_patch(options.git_commit, changed_files=changed_files)
            patch_checker = PatchReader(file_reader)
            patch_checker.check(patch)

        error_count = style_processor.error_count
        file_count = file_reader.file_count
        delete_only_file_count = file_reader.delete_only_file_count

        _log.info("Total errors found: %d in %d files"
                  % (error_count, file_count))
        # We fail when style errors are found or there are no checked files.
        #sys.exit(error_count > 0 or (file_count == 0 and delete_only_file_count == 0))
        return not (error_count > 0 or (file_count == 0 and delete_only_file_count == 0))