Changeset 83977 in webkit


Ignore:
Timestamp:
Apr 15, 2011 8:39:46 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-15 Dmitry Lomov <dslomov@google.com>

Reviewed by David Levin.

check-webkit-style shouldn't complain about not including a primary header file
if none exists
https://bugs.webkit.org/show_bug.cgi?id=39514

  • Scripts/webkitpy/style/checkers/cpp.py:
  • Scripts/webkitpy/style/checkers/cpp_unittest.py:
Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r83956 r83977  
     12011-04-15  Dmitry Lomov  <dslomov@google.com>
     2
     3        Reviewed by David Levin.
     4
     5        check-webkit-style shouldn't complain about not including a primary header file
     6        if none exists
     7        https://bugs.webkit.org/show_bug.cgi?id=39514
     8
     9        * Scripts/webkitpy/style/checkers/cpp.py:
     10        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     11
    1122011-04-15  Eric Seidel  <eric@webkit.org>
    213
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r79787 r83977  
    313313        return self._visited_primary_section
    314314
    315     def check_next_include_order(self, header_type, file_is_header):
     315    def check_next_include_order(self, header_type, file_is_header, primary_header_exists):
    316316        """Returns a non-empty error message if the next header is out of order.
    317317
     
    358358            assert header_type == _OTHER_HEADER
    359359            if not file_is_header and self._section < self._PRIMARY_SECTION:
    360                 error_message = before_error_message
     360                if primary_header_exists:
     361                    error_message = before_error_message
    361362            self._section = self._OTHER_SECTION
    362363
     
    25982599
    25992600
     2601def _does_primary_header_exist(filename):
     2602    """Return a primary header file name for a file, or empty string
     2603    if the file is not source file or primary header does not exist.
     2604    """
     2605    fileinfo = FileInfo(filename)
     2606    if not fileinfo.is_source():
     2607        return False
     2608    primary_header = fileinfo.no_extension() + ".h"
     2609    return os.path.isfile(primary_header)
     2610
     2611
    26002612def check_include_line(filename, file_extension, clean_lines, line_number, include_state, error):
    26012613    """Check rules that are applicable to #include lines.
     
    26472659
    26482660    header_type = _classify_include(filename, include, is_system, include_state)
     2661    primary_header_exists = _does_primary_header_exist(filename)
    26492662    include_state.header_types[line_number] = header_type
    26502663
     
    26582671    # The include_state object keeps track of the last type seen
    26592672    # and complains if the header types are out of order or missing.
    2660     error_message = include_state.check_next_include_order(header_type, file_extension == "h")
     2673    error_message = include_state.check_next_include_order(header_type,
     2674                                                           file_extension == "h",
     2675                                                           primary_header_exists)
    26612676
    26622677    # Check to make sure we have a blank line after primary header.
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r79787 r83977  
    24532453        # Cheat os.path.abspath called in FileInfo class.
    24542454        self.os_path_abspath_orig = os.path.abspath
     2455        self.os_path_isfile_orig = os.path.isfile
    24552456        os.path.abspath = lambda value: value
    24562457
    24572458    def tearDown(self):
    24582459        os.path.abspath = self.os_path_abspath_orig
     2460        os.path.isfile = self.os_path_isfile_orig
    24592461
    24602462    def test_check_next_include_order__no_config(self):
    24612463        self.assertEqual('Header file should not contain WebCore config.h.',
    2462                          self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True))
     2464                         self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True, True))
    24632465
    24642466    def test_check_next_include_order__no_self(self):
    24652467        self.assertEqual('Header file should not contain itself.',
    2466                          self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True))
     2468                         self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True, True))
    24672469        # Test actual code to make sure that header types are correctly assigned.
    24682470        self.assert_language_rules_check('Foo.h',
     
    24762478    def test_check_next_include_order__likely_then_config(self):
    24772479        self.assertEqual('Found header this file implements before WebCore config.h.',
    2478                          self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False))
     2480                         self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True))
    24792481        self.assertEqual('Found WebCore config.h after a header this file implements.',
    2480                          self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
     2482                         self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
    24812483
    24822484    def test_check_next_include_order__other_then_config(self):
    24832485        self.assertEqual('Found other header before WebCore config.h.',
    2484                          self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False))
     2486                         self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True))
    24852487        self.assertEqual('Found WebCore config.h after other header.',
    2486                          self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
     2488                         self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
    24872489
    24882490    def test_check_next_include_order__config_then_other_then_likely(self):
    2489         self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
     2491        self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
    24902492        self.assertEqual('Found other header before a header this file implements.',
    2491                          self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False))
     2493                         self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True))
    24922494        self.assertEqual('Found header this file implements after other header.',
    2493                          self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False))
     2495                         self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True))
    24942496
    24952497    def test_check_alphabetical_include_order(self):
     
    25862588                                         '#include "g.h"\n',
    25872589                                         '"foo.h" already included at foo.cpp:2  [build/include] [4]')
     2590
     2591    def test_primary_header(self):
     2592        # File with non-existing primary header should not produce errors.
     2593        self.assert_language_rules_check('foo.cpp',
     2594                                         '#include "config.h"\n'
     2595                                         '\n'
     2596                                         '#include "bar.h"\n',
     2597                                         '')
     2598        # Pretend that header files exist.
     2599        os.path.isfile = lambda filename: True
     2600        # Missing include for existing primary header -> error.
     2601        self.assert_language_rules_check('foo.cpp',
     2602                                         '#include "config.h"\n'
     2603                                         '\n'
     2604                                         '#include "bar.h"\n',
     2605                                         'Found other header before a header this file implements. '
     2606                                         'Should be: config.h, primary header, blank line, and then '
     2607                                         'alphabetically sorted.  [build/include_order] [4]')
     2608        # Having include for existing primary header -> no error.
     2609        self.assert_language_rules_check('foo.cpp',
     2610                                         '#include "config.h"\n'
     2611                                         '#include "foo.h"\n'
     2612                                         '\n'
     2613                                         '#include "bar.h"\n',
     2614                                         '')
     2615
     2616        os.path.isfile = self.os_path_isfile_orig
     2617
    25882618
    25892619    def test_check_wtf_includes(self):
Note: See TracChangeset for help on using the changeset viewer.