diff options
Diffstat (limited to 'WebKitTools/Scripts/check-webkit-style')
| -rwxr-xr-x | WebKitTools/Scripts/check-webkit-style | 100 |
1 files changed, 69 insertions, 31 deletions
diff --git a/WebKitTools/Scripts/check-webkit-style b/WebKitTools/Scripts/check-webkit-style index 501264b..e29d4b1 100755 --- a/WebKitTools/Scripts/check-webkit-style +++ b/WebKitTools/Scripts/check-webkit-style @@ -43,52 +43,90 @@ same line, but it is far from perfect (in either direction). """ import codecs +import logging import os import os.path import sys +from webkitpy.style_references import detect_checkout import webkitpy.style.checker as checker -from webkitpy.style_references import SimpleScm +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 +_log = logging.getLogger("check-webkit-style") + + +# FIXME: Move this code to style.main. def main(): # Change stderr to write with replacement characters so we don't die # if we try to print something containing non-ASCII characters. - sys.stderr = codecs.StreamReaderWriter(sys.stderr, - codecs.getreader('utf8'), - codecs.getwriter('utf8'), - 'replace') + 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 + + 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) - defaults = checker.webkit_argument_defaults() + configuration = checker.check_webkit_style_configuration(options) - parser = checker.ArgumentParser(defaults) - (files, options) = parser.parse(sys.argv[1:]) + paths = change_directory(checkout_root=checkout_root, paths=paths) - style_checker = checker.StyleChecker(options) + style_processor = StyleProcessor(configuration) - if files: - for filename in files: - style_checker.check_file(filename) + file_reader = TextFileReader(style_processor) + if paths: + file_reader.process_paths(paths) else: - scm = SimpleScm() - - os.chdir(scm.checkout_root()) - - if options.git_commit: - commit = options.git_commit - if '..' in commit: - # FIXME: If the range is a "...", the code should find the common ancestor and - # start there (see git diff --help for information about how ... usually works). - commit = commit[:commit.find('..')] - print >> sys.stderr, "Warning: Ranges are not supported for --git-commit. Checking all changes since %s.\n" % commit - patch = scm.create_patch_since_local_commit(commit) - else: - patch = scm.create_patch() - style_checker.check_patch(patch) - - error_count = style_checker.error_count - sys.stderr.write('Total errors found: %d\n' % error_count) - sys.exit(error_count > 0) + patch = checkout.create_patch(options.git_commit) + 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)) if __name__ == "__main__": |
