[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

hamaji at chromium.org hamaji at chromium.org
Thu Apr 8 00:48:17 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit be97ebb389892105828a7b15339f6462a3382bd8
Author: hamaji at chromium.org <hamaji at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 24 05:31:33 2009 +0000

    2009-12-20  Chris Jerdonek  <chris.jerdonek at gmail.com>
    
            Reviewed by David Levin.
    
            Moved some sections of code in preparation to refactor
            check-webkit-style's argument parser to avoid setting
            global variables.
    
            https://bugs.webkit.org/show_bug.cgi?id=32592
    
            * Scripts/check-webkit-style:
              - Moved _USAGE string to style.py.
              - Addressed FIXME by eliminating dependencies on cpp_style.py.
    
            * Scripts/modules/cpp_style.py:
              - Moved default arguments and style categories to style.py.
              - Moved exit_with_usage(), exit_with_categories(), and
                parse_arguments() to style.py.
              - Removed references in _CppStyleState to the global
                variables now in style.py.
    
            * Scripts/modules/cpp_style_unittest.py:
              - Moved parse_arguments() unit tests to style_unittest.py.
    
            * Scripts/modules/style.py:
              - Added _USAGE string from check-webkit-style.
              - Added default arguments and style categories from cpp_style.py.
              - Added exit_with_usage(), exit_with_categories(), and
                parse_arguments() from cpp_sstyle.py.
    
            * Scripts/modules/style_unittest.py: Added.
              - Added parse_arguments() unit tests from cpp_style_unittest.py.
    
            * Scripts/run-webkit-unittests:
              - Added unit tests from style_unittest.py.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52541 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 023971e..2d2e8c1 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,39 @@
+2009-12-20  Chris Jerdonek  <chris.jerdonek at gmail.com>
+
+        Reviewed by David Levin.
+
+        Moved some sections of code in preparation to refactor
+        check-webkit-style's argument parser to avoid setting
+        global variables.
+
+        https://bugs.webkit.org/show_bug.cgi?id=32592
+
+        * Scripts/check-webkit-style:
+          - Moved _USAGE string to style.py.
+          - Addressed FIXME by eliminating dependencies on cpp_style.py.
+
+        * Scripts/modules/cpp_style.py:
+          - Moved default arguments and style categories to style.py.
+          - Moved exit_with_usage(), exit_with_categories(), and
+            parse_arguments() to style.py.
+          - Removed references in _CppStyleState to the global
+            variables now in style.py.
+
+        * Scripts/modules/cpp_style_unittest.py:
+          - Moved parse_arguments() unit tests to style_unittest.py.
+
+        * Scripts/modules/style.py:
+          - Added _USAGE string from check-webkit-style.
+          - Added default arguments and style categories from cpp_style.py.
+          - Added exit_with_usage(), exit_with_categories(), and
+            parse_arguments() from cpp_sstyle.py.
+
+        * Scripts/modules/style_unittest.py: Added.
+          - Added parse_arguments() unit tests from cpp_style_unittest.py.
+
+        * Scripts/run-webkit-unittests:
+          - Added unit tests from style_unittest.py.
+
 2009-12-23  Eric Seidel  <eric at webkit.org>
 
         Reviewed by Adam Barth.
diff --git a/WebKitTools/Scripts/check-webkit-style b/WebKitTools/Scripts/check-webkit-style
index 96f2c8d..6634854 100755
--- a/WebKitTools/Scripts/check-webkit-style
+++ b/WebKitTools/Scripts/check-webkit-style
@@ -46,76 +46,10 @@ import os
 import os.path
 import sys
 
-import modules.cpp_style as cpp_style
 import modules.style as style
 from modules.scm import detect_scm_system
 
 
-# FIXME: Avoid cpp_style dependency.
-cpp_style._USAGE = """
-Syntax: %(program_name)s [--verbose=#] [--git-commit=<SingleCommit>] [--output=vs7]
-        [--filter=-x,+y,...] [file] ...
-
-  The style guidelines this tries to follow are here:
-    http://webkit.org/coding/coding-style.html
-
-  Every style error is given a confidence score from 1-5, with 5 meaning
-  we are certain of the problem, and 1 meaning it could be a legitimate
-  construct.  This can miss some errors and does not substitute for
-  code review.
-
-  To prevent specific lines from being linted, add a '// NOLINT' comment to the
-  end of the line.
-
-  Linted extensions are .cpp, .c and .h.  Other file types are ignored.
-
-  The file parameter is optional and accepts multiple files.  Leaving
-  out the file parameter applies the check to all files considered changed
-  by your source control management system.
-
-  Flags:
-
-    verbose=#
-      A number 0-5 to restrict errors to certain verbosity levels.
-      Defaults to %(default_verbosity)s.
-
-    git-commit=<SingleCommit>
-      Checks the style of everything from the given commit to the local tree.
-
-    output=vs7
-      The output format, which may be one of
-        emacs : to ease emacs parsing
-        vs7   : compatible with Visual Studio
-      Defaults to "%(default_output_format)s". Other formats are unsupported.
-
-    filter=-x,+y,...
-      A comma-separated list of boolean filter rules used to filter
-      which categories of style guidelines to check.  The script checks
-      a category if the category passes the filter rules, as follows.
-
-      Any webkit category starts out passing.  All filter rules are then
-      evaluated left to right, with later rules taking precedence.  For
-      example, the rule "+foo" passes any category that starts with "foo",
-      and "-foo" fails any such category.  The filter input "-whitespace,
-      +whitespace/braces" fails the category "whitespace/tab" and passes
-      "whitespace/braces".
-
-      Examples: --filter=-whitespace,+whitespace/braces
-                --filter=-whitespace,-runtime/printf,+runtime/printf_format
-                --filter=-,+build/include_what_you_use
-
-      Category names appear in error messages in brackets, for example
-      [whitespace/indent].  To see a list of all categories available to
-      %(program_name)s, along with which are enabled by default, pass
-      the empty filter as follows:
-         --filter=
-""" % {
-    'program_name': os.path.basename(sys.argv[0]),
-    'default_verbosity': cpp_style._DEFAULT_VERBOSITY,
-    'default_output_format': cpp_style._DEFAULT_OUTPUT_FORMAT
-    }
-
-
 def main():
     style.use_webkit_styles()
 
@@ -130,9 +64,9 @@ def main():
                                            'replace')
 
     if files and "--git-commit" in flags:
-        cpp_style.exit_with_usage('It is not possible to check files and a '
-                                  'specific commit at the same time.',
-                                  display_help=True)
+        style.exit_with_usage('It is not possible to check files and a '
+                              'specific commit at the same time.',
+                              display_help=True)
 
     if files:
         for filename in files:
diff --git a/WebKitTools/Scripts/modules/cpp_style.py b/WebKitTools/Scripts/modules/cpp_style.py
index 7361f25..64e3905 100644
--- a/WebKitTools/Scripts/modules/cpp_style.py
+++ b/WebKitTools/Scripts/modules/cpp_style.py
@@ -37,7 +37,6 @@
 """Support for check-webkit-style."""
 
 import codecs
-import getopt
 import math  # for log
 import os
 import os.path
@@ -48,117 +47,9 @@ import sys
 import unicodedata
 
 
-# This is set by check-webkit-style.
 _USAGE = ''
 
 
-# Default options
-_DEFAULT_VERBOSITY = 1
-_DEFAULT_OUTPUT_FORMAT = 'emacs'
-
-
-# FIXME: For style categories we will never want to have, remove them.
-#        For categories for which we want to have similar functionality,
-#        modify the implementation and enable them.
-# FIXME: Add a unit test to ensure the corresponding categories
-#        are elements of _STYLE_CATEGORIES.
-#
-# For unambiguous terminology, we use "filter rule" rather than "filter"
-# for an individual boolean filter flag like "+foo". This allows us to 
-# reserve "filter" for what one gets by collectively applying all of 
-# the filter rules as specified by a --filter flag.
-_WEBKIT_FILTER_RULES = [
-    '-build/endif_comment',
-    '-build/include_what_you_use',  # <string> for std::string
-    '-build/storage_class',  # const static
-    '-legal/copyright',
-    '-readability/multiline_comment',
-    '-readability/braces',  # int foo() {};
-    '-readability/fn_size',
-    '-readability/casting',
-    '-readability/function',
-    '-runtime/arrays',  # variable length array
-    '-runtime/casting',
-    '-runtime/sizeof',
-    '-runtime/explicit',  # explicit
-    '-runtime/virtual',  # virtual dtor
-    '-runtime/printf',
-    '-runtime/threadsafe_fn',
-    '-runtime/rtti',
-    '-whitespace/blank_line',
-    '-whitespace/end_of_line',
-    '-whitespace/labels',
-    ]
-
-
-# We categorize each style rule we print.  Here are the categories.
-# We want an explicit list so we can list them all in cpp_style --filter=.
-# If you add a new error message with a new category, add it to the list
-# here!  cpp_style_unittest.py should tell you if you forget to do this.
-_STYLE_CATEGORIES = [
-    'build/class',
-    'build/deprecated',
-    'build/endif_comment',
-    'build/forward_decl',
-    'build/header_guard',
-    'build/include',
-    'build/include_order',
-    'build/include_what_you_use',
-    'build/namespaces',
-    'build/printf_format',
-    'build/storage_class',
-    'build/using_std',
-    'legal/copyright',
-    'readability/braces',
-    'readability/casting',
-    'readability/check',
-    'readability/comparison_to_zero',
-    'readability/constructors',
-    'readability/control_flow',
-    'readability/fn_size',
-    'readability/function',
-    'readability/multiline_comment',
-    'readability/multiline_string',
-    'readability/naming',
-    'readability/null',
-    'readability/streams',
-    'readability/todo',
-    'readability/utf8',
-    'runtime/arrays',
-    'runtime/casting',
-    'runtime/explicit',
-    'runtime/init',
-    'runtime/int',
-    'runtime/invalid_increment',
-    'runtime/max_min_macros',
-    'runtime/memset',
-    'runtime/printf',
-    'runtime/printf_format',
-    'runtime/references',
-    'runtime/rtti',
-    'runtime/sizeof',
-    'runtime/string',
-    'runtime/threadsafe_fn',
-    'runtime/virtual',
-    'whitespace/blank_line',
-    'whitespace/braces',
-    'whitespace/comma',
-    'whitespace/comments',
-    'whitespace/declaration',
-    'whitespace/end_of_line',
-    'whitespace/ending_newline',
-    'whitespace/indent',
-    'whitespace/labels',
-    'whitespace/line_length',
-    'whitespace/newline',
-    'whitespace/operators',
-    'whitespace/parens',
-    'whitespace/semicolon',
-    'whitespace/tab',
-    'whitespace/todo',
-    ]
-
-
 # The default state of the category filter. This is overrided by the --filter=
 # flag. By default all errors are on, so only add here categories that should be
 # off by default (i.e., categories that must be enabled by the --filter= flags).
@@ -360,7 +251,7 @@ class _CppStyleState(object):
     """Maintains module-wide state.."""
 
     def __init__(self):
-        self.verbose_level = _DEFAULT_VERBOSITY  # global setting.
+        self.verbose_level = 1  # global setting.
         self.error_count = 0    # global count of reported errors
         # filters to apply when emitting error messages
         self.filters = _DEFAULT_FILTER_RULES[:]
@@ -368,7 +259,7 @@ class _CppStyleState(object):
         # output format:
         # "emacs" - format that emacs can parse (default)
         # "vs7" - format that Microsoft Visual Studio 7 can parse
-        self.output_format = _DEFAULT_OUTPUT_FORMAT
+        self.output_format = 'emacs'
 
     def set_output_format(self, output_format):
         """Sets the output format for errors."""
@@ -3163,98 +3054,6 @@ def process_file(filename, error=error):
                   'better to use only a \\n')
 
 
-def exit_with_usage(error_message, display_help=False):
-    """Exit and print a usage string with an optional error message.
-
-    Args:
-      error_message: The optional error message.
-      display_help: Whether to display help output. Suppressing help
-                    output is useful for unit tests.
-    """
-    if display_help:
-        sys.stderr.write(_USAGE)
-    if error_message:
-        sys.exit('\nFATAL ERROR: ' + error_message)
-    else:
-        sys.exit(1)
-
-
-def exit_with_categories(display_help=False):
-    """Exit and print all style categories, along with the default filter.
-
-    These category names appear in error messages.  They can be filtered
-    using the --filter flag.
-
-    Args:
-      display_help: Whether to display help output. Suppressing help
-                    output is useful for unit tests.
-    """
-    if display_help:
-        sys.stderr.write('\nAll categories:\n')
-        for category in sorted(_STYLE_CATEGORIES):
-            sys.stderr.write('    ' + category + '\n')
-
-        sys.stderr.write('\nDefault filter rules**:\n')
-        for filter_rule in sorted(_WEBKIT_FILTER_RULES):
-            sys.stderr.write('    ' + filter_rule + '\n')
-        sys.stderr.write('\n**The command always evaluates the above '
-                         'rules, and before any --filter flag.\n\n')
-
-    sys.exit(0)
-
-
-def parse_arguments(args, additional_flags=[], display_help=False):
-    """Parses the command line arguments.
-
-    This may set the output format and verbosity level as side-effects.
-
-    Args:
-      args: The command line arguments:
-      additional_flags: A list of strings which specifies flags we allow.
-      display_help: Whether to display help output. Suppressing help
-                    output is useful for unit tests.
-
-    Returns:
-      A tuple of (filenames, flags)
-
-      filenames: The list of filenames to lint.
-      flags: The dict of the flag names and the flag values.
-    """
-    flags = ['help', 'output=', 'verbose=', 'filter='] + additional_flags
-    additional_flag_values = {}
-    try:
-        (opts, filenames) = getopt.getopt(args, '', flags)
-    except getopt.GetoptError:
-        exit_with_usage('Invalid arguments.', display_help)
-
-    verbosity = _verbose_level()
-    output_format = _output_format()
-    filters = ''
-
-    for (opt, val) in opts:
-        if opt == '--help':
-            exit_with_usage(None, display_help)
-        elif opt == '--output':
-            if not val in ('emacs', 'vs7'):
-                exit_with_usage('The only allowed output formats are emacs and vs7.',
-                                display_help)
-            output_format = val
-        elif opt == '--verbose':
-            verbosity = int(val)
-        elif opt == '--filter':
-            filters = val
-            if not filters:
-                exit_with_categories(display_help)
-        else:
-            additional_flag_values[opt] = val
-
-    _set_output_format(output_format)
-    _set_verbose_level(verbosity)
-    _set_filters(filters)
-
-    return (filenames, additional_flag_values)
-
-
 def can_handle(filename):
     """Checks if this module supports for the specified file type.
 
diff --git a/WebKitTools/Scripts/modules/cpp_style_unittest.py b/WebKitTools/Scripts/modules/cpp_style_unittest.py
index 2558f18..8b1b17d 100644
--- a/WebKitTools/Scripts/modules/cpp_style_unittest.py
+++ b/WebKitTools/Scripts/modules/cpp_style_unittest.py
@@ -41,13 +41,14 @@ import random
 import re
 import unittest
 import cpp_style
-
+# FIXME: Remove the need to import something from style.
+from style import _STYLE_CATEGORIES
 
 # This class works as an error collector and replaces cpp_style.Error
 # function for the unit tests.  We also verify each category we see
 # is in cpp_style._STYLE_CATEGORIES, to help keep that list up to date.
 class ErrorCollector:
-    _all_style_categories = cpp_style._STYLE_CATEGORIES
+    _all_style_categories = _STYLE_CATEGORIES
     # This a list including all categories seen in any unit test.
     _seen_style_categories = {}
 
@@ -1567,81 +1568,6 @@ class CppStyleTest(CppStyleTestBase):
         self.assert_lint('int a = 5;\t// set a to 5',
                          'Tab found; better to use spaces  [whitespace/tab] [1]')
 
-    def test_parse_arguments(self):
-        old_usage = cpp_style._USAGE
-        old_style_categories = cpp_style._STYLE_CATEGORIES
-        old_webkit_filter_rules = cpp_style._WEBKIT_FILTER_RULES
-        old_output_format = cpp_style._cpp_style_state.output_format
-        old_verbose_level = cpp_style._cpp_style_state.verbose_level
-        old_filters = cpp_style._cpp_style_state.filters
-        try:
-            # Don't print usage during the tests, or filter categories
-            cpp_style._USAGE = ''
-            cpp_style._STYLE_CATEGORIES = []
-            cpp_style._WEBKIT_FILTER_RULES = []
-
-            self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--badopt'])
-            self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--help'])
-            self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--filter='])
-            # This is illegal because all filters must start with + or -
-            self.assertRaises(ValueError, cpp_style.parse_arguments, ['--filter=foo'])
-            self.assertRaises(ValueError, cpp_style.parse_arguments,
-                              ['--filter=+a,b,-c'])
-
-            self.assertEquals((['foo.cpp'], {}), cpp_style.parse_arguments(['foo.cpp']))
-            self.assertEquals(old_output_format, cpp_style._cpp_style_state.output_format)
-            self.assertEquals(old_verbose_level, cpp_style._cpp_style_state.verbose_level)
-
-            self.assertEquals(([], {}), cpp_style.parse_arguments([]))
-            self.assertEquals(([], {}), cpp_style.parse_arguments(['--v=0']))
-
-            self.assertEquals((['foo.cpp'], {}),
-                              cpp_style.parse_arguments(['--v=1', 'foo.cpp']))
-            self.assertEquals(1, cpp_style._cpp_style_state.verbose_level)
-            self.assertEquals((['foo.h'], {}),
-                              cpp_style.parse_arguments(['--v=3', 'foo.h']))
-            self.assertEquals(3, cpp_style._cpp_style_state.verbose_level)
-            self.assertEquals((['foo.cpp'], {}),
-                              cpp_style.parse_arguments(['--verbose=5', 'foo.cpp']))
-            self.assertEquals(5, cpp_style._cpp_style_state.verbose_level)
-            self.assertRaises(ValueError,
-                              cpp_style.parse_arguments, ['--v=f', 'foo.cpp'])
-
-            self.assertEquals((['foo.cpp'], {}),
-                              cpp_style.parse_arguments(['--output=emacs', 'foo.cpp']))
-            self.assertEquals('emacs', cpp_style._cpp_style_state.output_format)
-            self.assertEquals((['foo.h'], {}),
-                              cpp_style.parse_arguments(['--output=vs7', 'foo.h']))
-            self.assertEquals('vs7', cpp_style._cpp_style_state.output_format)
-            self.assertRaises(SystemExit,
-                              cpp_style.parse_arguments, ['--output=blah', 'foo.cpp'])
-
-            filt = '-,+whitespace,-whitespace/indent'
-            self.assertEquals((['foo.h'], {}),
-                              cpp_style.parse_arguments(['--filter='+filt, 'foo.h']))
-            self.assertEquals(['-', '+whitespace', '-whitespace/indent'],
-                              cpp_style._cpp_style_state.filters)
-
-            self.assertEquals((['foo.cpp', 'foo.h'], {}),
-                              cpp_style.parse_arguments(['foo.cpp', 'foo.h']))
-
-            self.assertEquals((['foo.cpp'], {'--foo': ''}),
-                              cpp_style.parse_arguments(['--foo', 'foo.cpp'], ['foo']))
-            self.assertEquals((['foo.cpp'], {'--foo': 'bar'}),
-                              cpp_style.parse_arguments(['--foo=bar', 'foo.cpp'], ['foo=']))
-            self.assertEquals((['foo.cpp'], {}),
-                              cpp_style.parse_arguments(['foo.cpp'], ['foo=']))
-            self.assertRaises(SystemExit,
-                              cpp_style.parse_arguments,
-                              ['--footypo=bar', 'foo.cpp'], ['foo='])
-        finally:
-            cpp_style._USAGE = old_usage
-            cpp_style._STYLE_CATEGORIES = old_style_categories
-            cpp_style._WEBKIT_FILTER_RULES = old_webkit_filter_rules
-            cpp_style._cpp_style_state.output_format = old_output_format
-            cpp_style._cpp_style_state.verbose_level = old_verbose_level
-            cpp_style._cpp_style_state.filters = old_filters
-
     def test_filter(self):
         old_filters = cpp_style._cpp_style_state.filters
         try:
diff --git a/WebKitTools/Scripts/modules/style.py b/WebKitTools/Scripts/modules/style.py
index a64ce0b..58c5163 100644
--- a/WebKitTools/Scripts/modules/style.py
+++ b/WebKitTools/Scripts/modules/style.py
@@ -31,24 +31,281 @@
 # FIXME: Move more code from cpp_style to here.
 # check-webkit-style should not refer cpp_style directly.
 
+import getopt
 import os.path
+import sys
 
-import modules.cpp_style as cpp_style
-import modules.text_style as text_style
-from modules.diff_parser import DiffParser
+import cpp_style
+import text_style
+from diff_parser import DiffParser
+
+
+# Default options
+_DEFAULT_VERBOSITY = 1
+_DEFAULT_OUTPUT_FORMAT = 'emacs'
+
+
+# FIXME: For style categories we will never want to have, remove them.
+#        For categories for which we want to have similar functionality,
+#        modify the implementation and enable them.
+# FIXME: Add a unit test to ensure the corresponding categories
+#        are elements of _STYLE_CATEGORIES.
+#
+# For unambiguous terminology, we use "filter rule" rather than "filter"
+# for an individual boolean filter flag like "+foo". This allows us to 
+# reserve "filter" for what one gets by collectively applying all of 
+# the filter rules as specified by a --filter flag.
+_WEBKIT_FILTER_RULES = [
+    '-build/endif_comment',
+    '-build/include_what_you_use',  # <string> for std::string
+    '-build/storage_class',  # const static
+    '-legal/copyright',
+    '-readability/multiline_comment',
+    '-readability/braces',  # int foo() {};
+    '-readability/fn_size',
+    '-readability/casting',
+    '-readability/function',
+    '-runtime/arrays',  # variable length array
+    '-runtime/casting',
+    '-runtime/sizeof',
+    '-runtime/explicit',  # explicit
+    '-runtime/virtual',  # virtual dtor
+    '-runtime/printf',
+    '-runtime/threadsafe_fn',
+    '-runtime/rtti',
+    '-whitespace/blank_line',
+    '-whitespace/end_of_line',
+    '-whitespace/labels',
+    ]
+
+
+# We categorize each style rule we print.  Here are the categories.
+# We want an explicit list so we can list them all in cpp_style --filter=.
+# If you add a new error message with a new category, add it to the list
+# here!  cpp_style_unittest.py should tell you if you forget to do this.
+_STYLE_CATEGORIES = [
+    'build/class',
+    'build/deprecated',
+    'build/endif_comment',
+    'build/forward_decl',
+    'build/header_guard',
+    'build/include',
+    'build/include_order',
+    'build/include_what_you_use',
+    'build/namespaces',
+    'build/printf_format',
+    'build/storage_class',
+    'build/using_std',
+    'legal/copyright',
+    'readability/braces',
+    'readability/casting',
+    'readability/check',
+    'readability/comparison_to_zero',
+    'readability/constructors',
+    'readability/control_flow',
+    'readability/fn_size',
+    'readability/function',
+    'readability/multiline_comment',
+    'readability/multiline_string',
+    'readability/naming',
+    'readability/null',
+    'readability/streams',
+    'readability/todo',
+    'readability/utf8',
+    'runtime/arrays',
+    'runtime/casting',
+    'runtime/explicit',
+    'runtime/init',
+    'runtime/int',
+    'runtime/invalid_increment',
+    'runtime/max_min_macros',
+    'runtime/memset',
+    'runtime/printf',
+    'runtime/printf_format',
+    'runtime/references',
+    'runtime/rtti',
+    'runtime/sizeof',
+    'runtime/string',
+    'runtime/threadsafe_fn',
+    'runtime/virtual',
+    'whitespace/blank_line',
+    'whitespace/braces',
+    'whitespace/comma',
+    'whitespace/comments',
+    'whitespace/declaration',
+    'whitespace/end_of_line',
+    'whitespace/ending_newline',
+    'whitespace/indent',
+    'whitespace/labels',
+    'whitespace/line_length',
+    'whitespace/newline',
+    'whitespace/operators',
+    'whitespace/parens',
+    'whitespace/semicolon',
+    'whitespace/tab',
+    'whitespace/todo',
+    ]
+
+
+_USAGE = """
+Syntax: %(program_name)s [--verbose=#] [--git-commit=<SingleCommit>] [--output=vs7]
+        [--filter=-x,+y,...] [file] ...
+
+  The style guidelines this tries to follow are here:
+    http://webkit.org/coding/coding-style.html
+
+  Every style error is given a confidence score from 1-5, with 5 meaning
+  we are certain of the problem, and 1 meaning it could be a legitimate
+  construct.  This can miss some errors and does not substitute for
+  code review.
+
+  To prevent specific lines from being linted, add a '// NOLINT' comment to the
+  end of the line.
+
+  Linted extensions are .cpp, .c and .h.  Other file types are ignored.
+
+  The file parameter is optional and accepts multiple files.  Leaving
+  out the file parameter applies the check to all files considered changed
+  by your source control management system.
+
+  Flags:
+
+    verbose=#
+      A number 0-5 to restrict errors to certain verbosity levels.
+      Defaults to %(default_verbosity)s.
+
+    git-commit=<SingleCommit>
+      Checks the style of everything from the given commit to the local tree.
+
+    output=vs7
+      The output format, which may be one of
+        emacs : to ease emacs parsing
+        vs7   : compatible with Visual Studio
+      Defaults to "%(default_output_format)s". Other formats are unsupported.
+
+    filter=-x,+y,...
+      A comma-separated list of boolean filter rules used to filter
+      which categories of style guidelines to check.  The script checks
+      a category if the category passes the filter rules, as follows.
+
+      Any webkit category starts out passing.  All filter rules are then
+      evaluated left to right, with later rules taking precedence.  For
+      example, the rule "+foo" passes any category that starts with "foo",
+      and "-foo" fails any such category.  The filter input "-whitespace,
+      +whitespace/braces" fails the category "whitespace/tab" and passes
+      "whitespace/braces".
+
+      Examples: --filter=-whitespace,+whitespace/braces
+                --filter=-whitespace,-runtime/printf,+runtime/printf_format
+                --filter=-,+build/include_what_you_use
+
+      Category names appear in error messages in brackets, for example
+      [whitespace/indent].  To see a list of all categories available to
+      %(program_name)s, along with which are enabled by default, pass
+      the empty filter as follows:
+         --filter=
+""" % {
+    'program_name': os.path.basename(sys.argv[0]),
+    'default_verbosity': _DEFAULT_VERBOSITY,
+    'default_output_format': _DEFAULT_OUTPUT_FORMAT
+    }
 
 
 def use_webkit_styles():
     """Configures this module for WebKit style."""
-    cpp_style._DEFAULT_FILTER_RULES = cpp_style._WEBKIT_FILTER_RULES
+    cpp_style._DEFAULT_FILTER_RULES = _WEBKIT_FILTER_RULES
+
+
+def exit_with_usage(error_message, display_help=False):
+    """Exit and print a usage string with an optional error message.
+
+    Args:
+      error_message: The optional error message.
+      display_help: Whether to display help output. Suppressing help
+                    output is useful for unit tests.
+    """
+    if display_help:
+        sys.stderr.write(_USAGE)
+    if error_message:
+        sys.exit('\nFATAL ERROR: ' + error_message)
+    else:
+        sys.exit(1)
+
+
+def exit_with_categories(display_help=False):
+    """Exit and print all style categories, along with the default filter.
+
+    These category names appear in error messages.  They can be filtered
+    using the --filter flag.
+
+    Args:
+      display_help: Whether to display help output. Suppressing help
+                    output is useful for unit tests.
+    """
+    if display_help:
+        sys.stderr.write('\nAll categories:\n')
+        for category in sorted(_STYLE_CATEGORIES):
+            sys.stderr.write('    ' + category + '\n')
+
+        sys.stderr.write('\nDefault filter rules**:\n')
+        for filter_rule in sorted(_WEBKIT_FILTER_RULES):
+            sys.stderr.write('    ' + filter_rule + '\n')
+        sys.stderr.write('\n**The command always evaluates the above '
+                         'rules, and before any --filter flag.\n\n')
+
+    sys.exit(0)
 
 
 def parse_arguments(args, additional_flags=[], display_help=False):
     """Parses the command line arguments.
 
-    See cpp_style.parse_arguments() for details.
+    This may set the output format and verbosity level as side-effects.
+
+    Args:
+      args: The command line arguments:
+      additional_flags: A list of strings which specifies flags we allow.
+      display_help: Whether to display help output. Suppressing help
+                    output is useful for unit tests.
+
+    Returns:
+      A tuple of (filenames, flags)
+
+      filenames: The list of filenames to lint.
+      flags: The dict of the flag names and the flag values.
     """
-    return cpp_style.parse_arguments(args, additional_flags, display_help)
+    flags = ['help', 'output=', 'verbose=', 'filter='] + additional_flags
+    additional_flag_values = {}
+    try:
+        (opts, filenames) = getopt.getopt(args, '', flags)
+    except getopt.GetoptError:
+        exit_with_usage('Invalid arguments.', display_help)
+
+    verbosity = _DEFAULT_VERBOSITY
+    output_format = _DEFAULT_OUTPUT_FORMAT
+    filters = ''
+
+    for (opt, val) in opts:
+        if opt == '--help':
+            exit_with_usage(None, display_help)
+        elif opt == '--output':
+            if not val in ('emacs', 'vs7'):
+                exit_with_usage('The only allowed output formats are emacs and vs7.',
+                                display_help)
+            output_format = val
+        elif opt == '--verbose':
+            verbosity = int(val)
+        elif opt == '--filter':
+            filters = val
+            if not filters:
+                exit_with_categories(display_help)
+        else:
+            additional_flag_values[opt] = val
+
+    cpp_style._set_output_format(output_format)
+    cpp_style._set_verbose_level(verbosity)
+    cpp_style._set_filters(filters)
+
+    return (filenames, additional_flag_values)
 
 
 def process_file(filename):
diff --git a/WebKitTools/Scripts/run-webkit-unittests b/WebKitTools/Scripts/run-webkit-unittests
index c4252d2..11f863a 100755
--- a/WebKitTools/Scripts/run-webkit-unittests
+++ b/WebKitTools/Scripts/run-webkit-unittests
@@ -46,6 +46,7 @@ from modules.diff_parser_unittest import *
 from modules.logging_unittest import *
 from modules.multicommandtool_unittest import *
 from modules.queueengine_unittest import *
+from modules.style_unittest import *
 from modules.text_style_unittest import *
 from modules.webkitport_unittest import *
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list