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

tkent at chromium.org tkent at chromium.org
Thu Apr 8 00:38:11 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit cfd094c8f1f73e5601d62ede48e328b91ce12338
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Dec 16 07:54:20 2009 +0000

    2009-12-15  Chris Jerdonek  <chris.jerdonek at gmail.com>
    
            Reviewed by David Levin.
    
            Code clean-up in check-webkit-style as described below.
            The only functional changes are minor improvements to the
            script's help output.
    
            https://bugs.webkit.org/show_bug.cgi?id=32487
    
            * Scripts/check-webkit-style:
              - Added the module docstring from cpp_style.py.
              - Improved wording of the --help output and added some of the
                default values as substitution strings.
              - Called cpp_style.exit_with_usage instead of sys.stderr.write
                in main function.
              - Made changes caused by changes to cpp_style.py.
    
            * Scripts/modules/cpp_style.py:
              - Removed module docstring, as well as redundant _USAGE string
                and main() function obsoleted by check-webkit-style.
              - Moved specification of default script values from within a
                function definition to global variables.
              - Moved the default webkit filter rules to be near the other
                global variables.
              - Renamed "FILTER" global variables to "FILTER_RULES" to
                establish unambiguous terminology.
              - Renamed _ERROR_CATEGORIES to _STYLE_CATEGORIES.
              - Changed _STYLE_CATEGORIES from a string to a list.
              - Added default webkit filter rules to --filter= output.
              - Renamed "print_" methods to "exit_with_" since they exist
                and added a temporary display_help parameter.
              - Added a temporary display_help parameter to parse_arguments.
    
            * Scripts/modules/cpp_style_unittest.py:
              - Made changes caused by changes to cpp_style.py.
              - Lower-cased ErrorCollector's ERROR_CATEGORIES instance
                variables since they are not global.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52189 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 2a3cdfa..d58c5ca 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,42 @@
+2009-12-15  Chris Jerdonek  <chris.jerdonek at gmail.com>
+
+        Reviewed by David Levin.
+
+        Code clean-up in check-webkit-style as described below.
+        The only functional changes are minor improvements to the
+        script's help output.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=32487
+
+        * Scripts/check-webkit-style:
+          - Added the module docstring from cpp_style.py.
+          - Improved wording of the --help output and added some of the
+            default values as substitution strings.
+          - Called cpp_style.exit_with_usage instead of sys.stderr.write
+            in main function.
+          - Made changes caused by changes to cpp_style.py.
+
+        * Scripts/modules/cpp_style.py:
+          - Removed module docstring, as well as redundant _USAGE string
+            and main() function obsoleted by check-webkit-style.
+          - Moved specification of default script values from within a
+            function definition to global variables.
+          - Moved the default webkit filter rules to be near the other
+            global variables.
+          - Renamed "FILTER" global variables to "FILTER_RULES" to
+            establish unambiguous terminology.
+          - Renamed _ERROR_CATEGORIES to _STYLE_CATEGORIES.
+          - Changed _STYLE_CATEGORIES from a string to a list.
+          - Added default webkit filter rules to --filter= output.
+          - Renamed "print_" methods to "exit_with_" since they exist
+            and added a temporary display_help parameter.
+          - Added a temporary display_help parameter to parse_arguments.
+
+        * Scripts/modules/cpp_style_unittest.py:
+          - Made changes caused by changes to cpp_style.py.
+          - Lower-cased ErrorCollector's ERROR_CATEGORIES instance 
+            variables since they are not global.
+
 2009-12-15  Adam Barth  <abarth at webkit.org>
 
         Unreviewed fix for the style-queue.
diff --git a/WebKitTools/Scripts/check-webkit-style b/WebKitTools/Scripts/check-webkit-style
index 5709cf0..dceca2a 100755
--- a/WebKitTools/Scripts/check-webkit-style
+++ b/WebKitTools/Scripts/check-webkit-style
@@ -28,7 +28,18 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-"""Script to run the linter for source code of WebKit."""
+"""Does WebKit-lint on C/C++ files.
+
+The goal of this script is to identify places in the code that *may*
+be in non-compliance with WebKit style.  It does not attempt to fix
+up these problems -- the point is to educate.  It does also not
+attempt to find all problems, or to ensure that everything it does
+find is legitimately a problem.
+
+In particular, we can get very confused by /* and // inside strings!
+We do a small hack, which is to ignore //'s with "'s after them on the
+same line, but it is far from perfect (in either direction).
+"""
 
 import codecs
 import os
@@ -40,54 +51,68 @@ from modules.diff_parser import DiffParser
 from modules.scm import detect_scm_system
 
 
-# Override the usage of the lint tool.
 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 those in
+  The style guidelines this tries to follow are here:
     http://webkit.org/coding/coding-style.html
 
-  Every problem 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 will miss some errors, and is not a substitute for a code review.
+  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 will be ignored.
+  Linted extensions are .cpp, .c and .h.  Other file types are ignored.
 
-  The file parameter is optional and multiple files to scan be passed in.
-  Leaving out the file parameter will apply the check to the files changed
-  according to the scm system.
+  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=#
-      Specify a number 0-5 to restrict errors to certain verbosity levels.
+      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
-      By default, the output is formatted to ease emacs parsing.  Visual Studio
-      compatible output (vs7) may also be used.  Other formats are unsupported.
+      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,...
-      Specify a comma-separated list of category-filters to apply: only
-      error messages whose category names pass the filters will be printed.
-      (Category names are printed with the message and look like
-      "[whitespace/indent]".)  Filters are evaluated left to right.
-      "-FOO" and "FOO" means "do not print categories that start with FOO".
-      "+FOO" means "do print categories that start with FOO".
+      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=-whitespace,-runtime/printf,+runtime/printf_format
                 --filter=-,+build/include_what_you_use
 
-      To see a list of all the categories used in %(program_name)s, pass no arg:
+      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])}
+""" % {
+    'program_name': os.path.basename(sys.argv[0]),
+    'default_verbosity': cpp_style._DEFAULT_VERBOSITY,
+    'default_output_format': cpp_style._DEFAULT_OUTPUT_FORMAT
+    }
 
 
 def process_patch(patch_string):
@@ -123,9 +148,10 @@ def process_patch(patch_string):
 
 
 def main():
-    cpp_style.use_webkit_styles()
+    cpp_style._DEFAULT_FILTER_RULES = cpp_style._WEBKIT_FILTER_RULES
 
-    (files, flags) = cpp_style.parse_arguments(sys.argv[1:], ["git-commit="])
+    (files, flags) = cpp_style.parse_arguments(sys.argv[1:], ["git-commit="],
+                                               display_help=True)
 
     # Change stderr to write with replacement characters so we don't die
     # if we try to print something containing non-ASCII characters.
@@ -135,9 +161,9 @@ def main():
                                            'replace')
 
     if files and "--git-commit" in flags:
-        sys.stderr.write("ERROR: It is not possible to check files "
-                          "and a specific commit at the same time.\n" + cpp_style._USAGE)
-        sys.exit(1)
+        cpp_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:
@@ -154,9 +180,10 @@ def main():
                 # 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
-            process_patch(scm.create_patch_since_local_commit(commit))
+            patch = scm.create_patch_since_local_commit(commit)
         else:
-            process_patch(scm.create_patch())
+            patch = scm.create_patch()
+        process_patch(patch)
 
     sys.stderr.write('Total errors found: %d\n' % cpp_style.error_count())
     sys.exit(cpp_style.error_count() > 0)
diff --git a/WebKitTools/Scripts/modules/cpp_style.py b/WebKitTools/Scripts/modules/cpp_style.py
index f268610..dc9d874 100644
--- a/WebKitTools/Scripts/modules/cpp_style.py
+++ b/WebKitTools/Scripts/modules/cpp_style.py
@@ -34,18 +34,7 @@
 # This is the modified version of Google's cpplint. The original code is
 # http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py
 
-"""Does WebKit-lint on c++ files.
-
-The goal of this script is to identify places in the code that *may*
-be in non-compliance with WebKit style.  It does not attempt to fix
-up these problems -- the point is to educate.  It does also not
-attempt to find all problems, or to ensure that everything it does
-find is legitimately a problem.
-
-In particular, we can get very confused by /* and // inside strings!
-We do a small hack, which is to ignore //'s with "'s after them on the
-same line, but it is far from perfect (in either direction).
-"""
+"""Support for check-webkit-style."""
 
 import codecs
 import getopt
@@ -59,121 +48,124 @@ import sys
 import unicodedata
 
 
-_USAGE = """
-Syntax: %(program_name)s [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
-        <file> [file] ...
-
-  The style guidelines this tries to follow are those in
-    http://webkit.org/coding/coding-style.html
-
-  Every problem 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 will miss some errors, and is not a substitute for a code review.
+# This is set by check-webkit-style.
+_USAGE = ''
 
-  To prevent specific lines from being linted, add a '// NOLINT' comment to the
-  end of the line.
 
-  The files passed in will be linted; at least one file must be provided.
-  Linted extensions are .cpp, .c and .h.  Other file types will be ignored.
+# Default options
+_DEFAULT_VERBOSITY = 1
+_DEFAULT_OUTPUT_FORMAT = 'emacs'
 
-  Flags:
 
-    output=vs7
-      By default, the output is formatted to ease emacs parsing.  Visual Studio
-      compatible output (vs7) may also be used.  Other formats are unsupported.
-
-    verbose=#
-      Specify a number 0-5 to restrict errors to certain verbosity levels.
-
-    filter=-x,+y,...
-      Specify a comma-separated list of category-filters to apply: only
-      error messages whose category names pass the filters will be printed.
-      (Category names are printed with the message and look like
-      "[whitespace/indent]".)  Filters are evaluated left to right.
-      "-FOO" and "FOO" means "do not print categories that start with FOO".
-      "+FOO" means "do print categories that start with FOO".
-
-      Examples: --filter=-whitespace,+whitespace/braces
-                --filter=whitespace,runtime/printf,+runtime/printf_format
-                --filter=-,+build/include_what_you_use
+# 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/header_guard',
+    '-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/comments',
+    '-whitespace/end_of_line',
+    '-whitespace/labels',
+    ]
 
-      To see a list of all the categories used in %(program_name)s, pass no arg:
-         --filter=
-""" % {'program_name': sys.argv[0]}
 
-# We categorize each error message we print.  Here are the categories.
+# 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.
-# \ used for clearer layout -- pylint: disable-msg=C6013
-_ERROR_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/int
-    runtime/init
-    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
-'''
+_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).
 # All entries here should start with a '-' or '+', as in the --filter= flag.
-_DEFAULT_FILTERS = []
+_DEFAULT_FILTER_RULES = []
 
 # Headers that we consider STL headers.
 _STL_HEADERS = frozenset([
@@ -370,15 +362,15 @@ class _CppStyleState(object):
     """Maintains module-wide state.."""
 
     def __init__(self):
-        self.verbose_level = 1  # global setting.
+        self.verbose_level = _DEFAULT_VERBOSITY  # global setting.
         self.error_count = 0    # global count of reported errors
         # filters to apply when emitting error messages
-        self.filters = _DEFAULT_FILTERS[:]
+        self.filters = _DEFAULT_FILTER_RULES[:]
 
         # output format:
         # "emacs" - format that emacs can parse (default)
         # "vs7" - format that Microsoft Visual Studio 7 can parse
-        self.output_format = 'emacs'
+        self.output_format = _DEFAULT_OUTPUT_FORMAT
 
     def set_output_format(self, output_format):
         """Sets the output format for errors."""
@@ -405,7 +397,7 @@ class _CppStyleState(object):
                       E.g. "-,+whitespace,-whitespace/indent,whitespace/badfilter"
         """
         # Default filters always have less priority than the flag ones.
-        self.filters = _DEFAULT_FILTERS[:]
+        self.filters = _DEFAULT_FILTER_RULES[:]
         for filter in filters.split(','):
             clean_filter = filter.strip()
             if clean_filter:
@@ -3179,29 +3171,47 @@ def process_file(filename, error=error):
                   'better to use only a \\n')
 
 
-def print_usage(message):
-    """Prints a brief usage string and exits, optionally with an error message.
+def exit_with_usage(error_message, display_help=False):
+    """Exit and print a usage string with an optional error message.
 
     Args:
-      message: The optional error message.
+      error_message: The optional error message.
+      display_help: Whether to display help output. Suppressing help
+                    output is useful for unit tests.
     """
-    sys.stderr.write(_USAGE)
-    if message:
-        sys.exit('\nFATAL ERROR: ' + message)
+    if display_help:
+        sys.stderr.write(_USAGE)
+    if error_message:
+        sys.exit('\nFATAL ERROR: ' + error_message)
     else:
         sys.exit(1)
 
 
-def print_categories():
-    """Prints a list of all the error-categories used by error messages.
+def exit_with_categories(display_help=False):
+    """Exit and print all style categories, along with the default filter.
 
-    These are the categories used to filter messages via --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.
     """
-    sys.stderr.write(_ERROR_CATEGORIES)
+    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=[]):
+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.
@@ -3209,6 +3219,8 @@ def parse_arguments(args, additional_flags=[]):
     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)
@@ -3221,7 +3233,7 @@ def parse_arguments(args, additional_flags=[]):
     try:
         (opts, filenames) = getopt.getopt(args, '', flags)
     except getopt.GetoptError:
-        print_usage('Invalid arguments.')
+        exit_with_usage('Invalid arguments.', display_help)
 
     verbosity = _verbose_level()
     output_format = _output_format()
@@ -3229,17 +3241,18 @@ def parse_arguments(args, additional_flags=[]):
 
     for (opt, val) in opts:
         if opt == '--help':
-            print_usage(None)
+            exit_with_usage(None, display_help)
         elif opt == '--output':
             if not val in ('emacs', 'vs7'):
-                print_usage('The only allowed output formats are emacs and 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:
-                print_categories()
+                exit_with_categories(display_help)
         else:
             additional_flag_values[opt] = val
 
@@ -3248,71 +3261,3 @@ def parse_arguments(args, additional_flags=[]):
     _set_filters(filters)
 
     return (filenames, additional_flag_values)
-
-
-def use_webkit_styles():
-    """Disables some features which are not suitable for WebKit."""
-    # FIXME: For filters we will never want to have, remove them.
-    #        For filters we want to have similar functionalities,
-    #        modify the implementation and enable them.
-    global _DEFAULT_FILTERS
-    _DEFAULT_FILTERS = [
-        '-whitespace/end_of_line',
-        '-whitespace/comments',
-        '-whitespace/blank_line',
-        '-runtime/explicit',  # explicit
-        '-runtime/virtual',  # virtual dtor
-        '-runtime/printf',
-        '-runtime/threadsafe_fn',
-        '-runtime/rtti',
-        '-build/include_what_you_use',  # <string> for std::string
-        '-legal/copyright',
-        '-readability/multiline_comment',
-        '-readability/braces',  # int foo() {};
-        '-readability/fn_size',
-        '-build/storage_class',  # const static
-        '-build/endif_comment',
-        '-whitespace/labels',
-        '-runtime/arrays',  # variable length array
-        '-build/header_guard',
-        '-readability/casting',
-        '-readability/function',
-        '-runtime/casting',
-        '-runtime/sizeof',
-    ]
-
-
-def main():
-    sys.stderr.write(
-        '''********************* WARNING WARNING WARNING *********************
-
-This tool is in the process of development and may give inaccurate
-results at present.  Please file bugs (and/or patches) for things
-that you notice that it flags incorrectly.
-
-********************* WARNING WARNING WARNING *********************
-
-''')
-
-    use_webkit_styles()
-
-    (filenames, flags) = parse_arguments(sys.argv[1:])
-    if not filenames:
-        print_usage('No files were specified.')
-
-    # 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')
-
-    _cpp_style_state.reset_error_count()
-    for filename in filenames:
-        process_file(filename)
-    sys.stderr.write('Total errors found: %d\n' % _cpp_style_state.error_count)
-    sys.exit(_cpp_style_state.error_count > 0)
-
-
-if __name__ == '__main__':
-    main()
diff --git a/WebKitTools/Scripts/modules/cpp_style_unittest.py b/WebKitTools/Scripts/modules/cpp_style_unittest.py
index 41c888c..1acfc60 100644
--- a/WebKitTools/Scripts/modules/cpp_style_unittest.py
+++ b/WebKitTools/Scripts/modules/cpp_style_unittest.py
@@ -45,12 +45,11 @@ import cpp_style
 
 # 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._ERROR_CATEGORIES, to help keep that list up to date.
+# is in cpp_style._STYLE_CATEGORIES, to help keep that list up to date.
 class ErrorCollector:
-    # These are a global list, covering all categories seen ever.
-    _ERROR_CATEGORIES = [x.strip()    # get rid of leading whitespace
-                         for x in cpp_style._ERROR_CATEGORIES.split()]
-    _SEEN_ERROR_CATEGORIES = {}
+    _all_style_categories = cpp_style._STYLE_CATEGORIES
+    # This a list including all categories seen in any unit test.
+    _seen_style_categories = {}
 
     def __init__(self, assert_fn):
         """assert_fn: a function to call when we notice a problem."""
@@ -59,10 +58,10 @@ class ErrorCollector:
 
     def __call__(self, unused_filename, unused_linenum,
                  category, confidence, message):
-        self._assert_fn(category in self._ERROR_CATEGORIES,
+        self._assert_fn(category in self._all_style_categories,
                         'Message "%s" has category "%s",'
-                        ' which is not in _ERROR_CATEGORIES' % (message, category))
-        self._SEEN_ERROR_CATEGORIES[category] = 1
+                        ' which is not in _STYLE_CATEGORIES' % (message, category))
+        self._seen_style_categories[category] = 1
         if cpp_style._should_print_error(category, confidence):
             self._errors.append('%s  [%s] [%d]' % (message, category, confidence))
 
@@ -76,16 +75,16 @@ class ErrorCollector:
         return self._errors
 
     def verify_all_categories_are_seen(self):
-        """Fails if there's a category in _ERROR_CATEGORIES - _SEEN_ERROR_CATEGORIES.
+        """Fails if there's a category in _all_style_categories - _seen_style_categories.
 
         This should only be called after all tests are run, so
-        _SEEN_ERROR_CATEGORIES has had a chance to fully populate.  Since
+        _seen_style_categories has had a chance to fully populate.  Since
         this isn't called from within the normal unittest framework, we
         can't use the normal unittest assert macros.  Instead we just exit
         when we see an error.  Good thing this test is always run last!
         """
-        for category in self._ERROR_CATEGORIES:
-            if category not in self._SEEN_ERROR_CATEGORIES:
+        for category in self._all_style_categories:
+            if category not in self._seen_style_categories:
                 import sys
                 sys.exit('FATAL ERROR: There are no tests for category "%s"' % category)
 
@@ -1567,14 +1566,16 @@ class CppStyleTest(CppStyleTestBase):
 
     def test_parse_arguments(self):
         old_usage = cpp_style._USAGE
-        old_error_categories = cpp_style._ERROR_CATEGORIES
+        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._ERROR_CATEGORIES = ''
+            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'])
@@ -1632,7 +1633,8 @@ class CppStyleTest(CppStyleTestBase):
                               ['--footypo=bar', 'foo.cpp'], ['foo='])
         finally:
             cpp_style._USAGE = old_usage
-            cpp_style._ERROR_CATEGORIES = old_error_categories
+            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
@@ -1651,9 +1653,9 @@ class CppStyleTest(CppStyleTestBase):
             cpp_style._cpp_style_state.filters = old_filters
 
     def test_default_filter(self):
-        default_filters = cpp_style._DEFAULT_FILTERS
+        default_filter_rules = cpp_style._DEFAULT_FILTER_RULES
         old_filters = cpp_style._cpp_style_state.filters
-        cpp_style._DEFAULT_FILTERS = [ '-whitespace' ]
+        cpp_style._DEFAULT_FILTER_RULES = [ '-whitespace' ]
         try:
             # Reset filters
             cpp_style._cpp_style_state.set_filters('')
@@ -1666,7 +1668,7 @@ class CppStyleTest(CppStyleTestBase):
             self.assert_lint(' weird opening space', '')
         finally:
             cpp_style._cpp_style_state.filters = old_filters
-            cpp_style._DEFAULT_FILTERS = default_filters
+            cpp_style._DEFAULT_FILTER_RULES = default_filter_rules
 
     def test_unnamed_namespaces_in_headers(self):
         self.assert_language_rules_check(

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list