Changeset 52232 in webkit


Ignore:
Timestamp:
Dec 16, 2009 9:30:45 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2009-12-16 Kent Tamura <tkent@chromium.org>

Reviewed by David Levin.

check-webkit-style supports for TAB check against text files.
https://bugs.webkit.org/show_bug.cgi?id=32538

  • Scripts/check-webkit-style: Move process_patch() to style.py.
  • Scripts/modules/cpp_style.py: Add can_handle().
  • Scripts/modules/cpp_style_unittest.py: Add tests for can_handle().
  • Scripts/modules/style.py: Added. This is a front-end of cpp_style and text_style. It dispatches files to an appropriate linter.
  • Scripts/modules/text_style.py: Added. This is a linter module for generic text files. It supports only for TAB checking at this moment.
  • Scripts/modules/text_style_unittest.py: Added. Tests for text_style.py.
  • Scripts/run-webkit-unittests: Add text_style_unittest.
Location:
trunk/WebKitTools
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r52228 r52232  
     12009-12-16  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        check-webkit-style supports for TAB check against text files.
     6        https://bugs.webkit.org/show_bug.cgi?id=32538
     7
     8        * Scripts/check-webkit-style:
     9          Move process_patch() to style.py.
     10        * Scripts/modules/cpp_style.py:
     11          Add can_handle().
     12        * Scripts/modules/cpp_style_unittest.py:
     13          Add tests for can_handle().
     14        * Scripts/modules/style.py:
     15          Added. This is a front-end of cpp_style and text_style. It dispatches
     16          files to an appropriate linter.
     17        * Scripts/modules/text_style.py:
     18          Added. This is a linter module for generic text files. It supports
     19          only for TAB checking at this moment.
     20        * Scripts/modules/text_style_unittest.py:
     21          Added. Tests for text_style.py.
     22        * Scripts/run-webkit-unittests:
     23          Add text_style_unittest.
     24
    1252009-12-16  Eric Seidel  <eric@webkit.org>
    226
  • trunk/WebKitTools/Scripts/check-webkit-style

    r52189 r52232  
    2929# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3030
    31 """Does WebKit-lint on C/C++ files.
     31"""Does WebKit-lint on C/C++ or text files.
    3232
    3333The goal of this script is to identify places in the code that *may*
     
    4848
    4949import modules.cpp_style as cpp_style
    50 from modules.diff_parser import DiffParser
     50import modules.style as style
    5151from modules.scm import detect_scm_system
    5252
    5353
     54# FIXME: Avoid cpp_style dependency.
    5455cpp_style._USAGE = """
    5556Syntax: %(program_name)s [--verbose=#] [--git-commit=<SingleCommit>] [--output=vs7]
     
    116117
    117118
    118 def process_patch(patch_string):
    119     """Does lint on a single patch.
     119def main():
     120    style.use_webkit_styles()
    120121
    121     Args:
    122       patch_string: A string of a patch.
    123     """
    124     patch = DiffParser(patch_string.splitlines())
    125     for filename, diff in patch.files.iteritems():
    126         file_extension = os.path.splitext(filename)[1]
    127 
    128         if file_extension in ['.cpp', '.c', '.h']:
    129             line_numbers = set()
    130 
    131             def error_for_patch(filename, line_number, category, confidence, message):
    132                 """Wrapper function of cpp_style.error for patches.
    133 
    134                 This function outputs errors only if the line number
    135                 corresponds to lines which are modified or added.
    136                 """
    137                 if not line_numbers:
    138                     for line in diff.lines:
    139                         # When deleted line is not set, it means that
    140                         # the line is newly added.
    141                         if not line[0]:
    142                             line_numbers.add(line[1])
    143 
    144                 if line_number in line_numbers:
    145                     cpp_style.error(filename, line_number, category, confidence, message)
    146 
    147             cpp_style.process_file(filename, error=error_for_patch)
    148 
    149 
    150 def main():
    151     cpp_style._DEFAULT_FILTER_RULES = cpp_style._WEBKIT_FILTER_RULES
    152 
    153     (files, flags) = cpp_style.parse_arguments(sys.argv[1:], ["git-commit="],
    154                                                display_help=True)
     122    (files, flags) = style.parse_arguments(sys.argv[1:], ["git-commit="],
     123                                           display_help=True)
    155124
    156125    # Change stderr to write with replacement characters so we don't die
     
    168137    if files:
    169138        for filename in files:
    170             cpp_style.process_file(filename)
     139            style.process_file(filename)
    171140
    172141    else:
     
    184153        else:
    185154            patch = scm.create_patch()
    186         process_patch(patch)
     155        style.process_patch(patch)
    187156
    188     sys.stderr.write('Total errors found: %d\n' % cpp_style.error_count())
    189     sys.exit(cpp_style.error_count() > 0)
     157    sys.stderr.write('Total errors found: %d\n' % style.error_count())
     158    sys.exit(style.error_count() > 0)
    190159
    191160
  • trunk/WebKitTools/Scripts/modules/cpp_style.py

    r52189 r52232  
    31593159    # When reading from stdin, the extension is unknown, so no cpp_style tests
    31603160    # should rely on the extension.
    3161     if (filename != '-' and file_extension != 'h' and file_extension != 'cpp'
    3162         and file_extension != 'c'):
     3161    if (filename != '-' and not can_handle(filename)):
    31633162        sys.stderr.write('Ignoring %s; not a .cpp, .c or .h file\n' % filename)
    31643163    else:
     
    32623261
    32633262    return (filenames, additional_flag_values)
     3263
     3264
     3265def can_handle(filename):
     3266    """Checks if this module supports for the specified file type.
     3267
     3268    Args:
     3269      filename: A filename. It may contain directory names.
     3270     """
     3271    return os.path.splitext(filename)[1] in ('.h', '.cpp', '.c')
  • trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py

    r52189 r52232  
    37183718
    37193719
     3720    def test_can_handle(self):
     3721        """Tests for cpp_style.can_handle()."""
     3722        self.assert_(not cpp_style.can_handle(''))
     3723        self.assert_(cpp_style.can_handle('foo.h'))
     3724        self.assert_(not cpp_style.can_handle('foo.hpp'))
     3725        self.assert_(cpp_style.can_handle('foo.c'))
     3726        self.assert_(cpp_style.can_handle('foo.cpp'))
     3727        self.assert_(not cpp_style.can_handle('foo.cc'))
     3728        self.assert_(not cpp_style.can_handle('foo.cxx'))
     3729        self.assert_(not cpp_style.can_handle('foo.C'))
     3730        self.assert_(not cpp_style.can_handle('foo.mm'))
     3731        self.assert_(not cpp_style.can_handle('-'))
     3732
     3733
    37203734def tearDown():
    37213735    """A global check to make sure all error-categories have been tested.
  • trunk/WebKitTools/Scripts/run-webkit-unittests

    r52142 r52232  
    4444from modules.logging_unittest import *
    4545from modules.multicommandtool_unittest import *
     46from modules.text_style_unittest import *
    4647from modules.webkitport_unittest import *
    4748from modules.workqueue_unittest import *
Note: See TracChangeset for help on using the changeset viewer.