Title: [180981] trunk/Tools
Revision
180981
Author
ddkil...@apple.com
Date
2015-03-03 18:47:53 -0800 (Tue, 03 Mar 2015)

Log Message

check-webkit-style: Add exception for FrameworkSoftLink.h header order
<http://webkit.org/b/141872>

Reviewed by Alex Christensen.

* Scripts/webkitpy/style/checkers/cpp.py: Remove unneeded
semi-colons in various places and fix whitespace.
(_IncludeState): Add _SOFT_LINK_HEADER and _SOFT_LINK_SECTION
constants.
(_IncludeState.__init__): Add self._visited_soft_link_section
boolean state variable.
(_IncludeState.visited_soft_link_section): Getter for
self._visited_soft_link_section.
(_IncludeState.check_next_include_order): Update state machine
for soft-link headers.  Add check that soft-link headers always
appear last.
(_classify_include): Add check for soft-link header type.
(check_include_line): Return early if there is a soft-link
header error.

* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(OrderOfIncludesTest.test_public_primary_header): Add tests for
including soft-link headers.
(OrderOfIncludesTest.test_classify_include): Add test for
_SOFT_LINK_HEADER type.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (180980 => 180981)


--- trunk/Tools/ChangeLog	2015-03-04 02:37:58 UTC (rev 180980)
+++ trunk/Tools/ChangeLog	2015-03-04 02:47:53 UTC (rev 180981)
@@ -1,3 +1,31 @@
+2015-03-03  David Kilzer  <ddkil...@apple.com>
+
+        check-webkit-style: Add exception for FrameworkSoftLink.h header order
+        <http://webkit.org/b/141872>
+
+        Reviewed by Alex Christensen.
+
+        * Scripts/webkitpy/style/checkers/cpp.py: Remove unneeded
+        semi-colons in various places and fix whitespace.
+        (_IncludeState): Add _SOFT_LINK_HEADER and _SOFT_LINK_SECTION
+        constants.
+        (_IncludeState.__init__): Add self._visited_soft_link_section
+        boolean state variable.
+        (_IncludeState.visited_soft_link_section): Getter for
+        self._visited_soft_link_section.
+        (_IncludeState.check_next_include_order): Update state machine
+        for soft-link headers.  Add check that soft-link headers always
+        appear last.
+        (_classify_include): Add check for soft-link header type.
+        (check_include_line): Return early if there is a soft-link
+        header error.
+
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (OrderOfIncludesTest.test_public_primary_header): Add tests for
+        including soft-link headers.
+        (OrderOfIncludesTest.test_classify_include): Add test for
+        _SOFT_LINK_HEADER type.
+
 2015-03-03  Alexey Proskuryakov  <a...@apple.com>
 
         build.webkit.org/dashboard: Don't repeatedly handle each test type

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (180980 => 180981)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2015-03-04 02:37:58 UTC (rev 180980)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2015-03-04 02:47:53 UTC (rev 180981)
@@ -118,7 +118,8 @@
 _CONFIG_HEADER = 0
 _PRIMARY_HEADER = 1
 _OTHER_HEADER = 2
-_MOC_HEADER = 3
+_SOFT_LINK_HEADER = 3
+_MOC_HEADER = 4
 
 
 # A dictionary of items customize behavior for unit test. For example,
@@ -254,11 +255,13 @@
     _CONFIG_SECTION = 1
     _PRIMARY_SECTION = 2
     _OTHER_SECTION = 3
+    _SOFT_LINK_SECTION = 4
 
     _TYPE_NAMES = {
         _CONFIG_HEADER: 'WebCore config.h',
         _PRIMARY_HEADER: 'header this file implements',
         _OTHER_HEADER: 'other header',
+        _SOFT_LINK_HEADER: '*SoftLink.h header',
         _MOC_HEADER: 'moc file',
         }
     _SECTION_NAMES = {
@@ -266,17 +269,22 @@
         _CONFIG_SECTION: "WebCore config.h.",
         _PRIMARY_SECTION: 'a header this file implements.',
         _OTHER_SECTION: 'other header.',
+        _SOFT_LINK_SECTION: 'soft-link header section.',
         }
 
     def __init__(self):
         dict.__init__(self)
         self._section = self._INITIAL_SECTION
         self._visited_primary_section = False
-        self.header_types = dict();
+        self._visited_soft_link_section = False
+        self.header_types = dict()
 
     def visited_primary_section(self):
         return self._visited_primary_section
 
+    def visited_soft_link_section(self):
+        return self._visited_soft_link_section
+
     def check_next_include_order(self, header_type, filename, file_is_header, primary_header_exists):
         """Returns a non-empty error message if the next header is out of order.
 
@@ -302,7 +310,7 @@
             return ''
 
         error_message = ''
-        if self._section != self._OTHER_SECTION:
+        if self._section < self._OTHER_SECTION:
             before_error_message = ('Found %s before %s' %
                                     (self._TYPE_NAMES[header_type],
                                      self._SECTION_NAMES[self._section + 1]))
@@ -321,13 +329,22 @@
                 error_message = before_error_message
             self._section = self._PRIMARY_SECTION
             self._visited_primary_section = True
-        else:
-            assert header_type == _OTHER_HEADER
+        elif header_type == _OTHER_HEADER:
             if not file_is_header and self._section < self._PRIMARY_SECTION:
                 if primary_header_exists and not filename.endswith('SoftLink.cpp'):
                     error_message = before_error_message
             self._section = self._OTHER_SECTION
+        else:
+            assert header_type == _SOFT_LINK_HEADER
+            if file_is_header:
+                error_message = '{} should never be included in a header.'.format(
+                    self._TYPE_NAMES[header_type])
+            self._section = self._SOFT_LINK_SECTION
+            self._visited_soft_link_section = True
 
+        if not error_message and self.visited_soft_link_section() and header_type != _SOFT_LINK_HEADER:
+            error_message = '*SoftLink.h header should be included after all other headers.'
+
         return error_message
 
 
@@ -2880,11 +2897,15 @@
     if include == "config.h":
         return _CONFIG_HEADER
 
+    # If the include is named *SoftLink.h, then it's a soft-link header.
+    if include.endswith('SoftLink.h'):
+        return _SOFT_LINK_HEADER
+
     # There cannot be primary includes in header files themselves. Only an
     # include exactly matches the header filename will be is flagged as
     # primary, so that it triggers the "don't include yourself" check.
     if filename.endswith('.h') and filename != include:
-        return _OTHER_HEADER;
+        return _OTHER_HEADER
 
     # If the target file basename starts with the include we're checking
     # then we consider it the primary header.
@@ -2987,6 +3008,11 @@
                                                            file_extension == "h",
                                                            primary_header_exists)
 
+    # Check to make sure *SoftLink.h headers always appear last and never in a header.
+    if error_message and include_state.visited_soft_link_section():
+        error(line_number, 'build/include_order', 4, error_message)
+        return
+
     # Check to make sure we have a blank line after and none before primary header.
     if not error_message and header_type == _PRIMARY_HEADER:
         next_line = clean_lines.raw_lines[line_number + 1]
@@ -3001,15 +3027,15 @@
     # Check to make sure all headers besides config.h and the primary header are
     # alphabetically sorted.
     if not error_message and header_type == _OTHER_HEADER:
-         previous_line_number = line_number - 1;
-         previous_line = clean_lines.lines[previous_line_number]
-         previous_match = _RE_PATTERN_INCLUDE.search(previous_line)
-         while (not previous_match and previous_line_number > 0
-                and not search(r'\A(#if|#ifdef|#ifndef|#else|#elif|#endif)', previous_line)):
-            previous_line_number -= 1;
+        previous_line_number = line_number - 1
+        previous_line = clean_lines.lines[previous_line_number]
+        previous_match = _RE_PATTERN_INCLUDE.search(previous_line)
+        while (not previous_match and previous_line_number > 0
+               and not search(r'\A(#if|#ifdef|#ifndef|#else|#elif|#endif)', previous_line)):
+            previous_line_number -= 1
             previous_line = clean_lines.lines[previous_line_number]
             previous_match = _RE_PATTERN_INCLUDE.search(previous_line)
-         if previous_match:
+        if previous_match:
             previous_header_type = include_state.header_types[previous_line_number]
             if previous_header_type == _OTHER_HEADER:
                 if '<' in previous_line and '"' in line:

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (180980 => 180981)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2015-03-04 02:37:58 UTC (rev 180980)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2015-03-04 02:47:53 UTC (rev 180981)
@@ -2859,6 +2859,74 @@
                                          '#include "a.h"\n',
                                          'Bad include order. Mixing system and custom headers.  [build/include_order] [4]')
 
+        # *SoftLink.h header should never be included in other header files.
+        self.assert_language_rules_check('foo.h',
+                                         '#include "Bar.h"\n'
+                                         '\n'
+                                         '#include "FrameworkSoftLink.h"\n',
+                                         '*SoftLink.h header should never be included in a header.  [build/include_order] [4]')
+
+        # Complain about *SoftLink.h headers that are not last.
+        self.assert_language_rules_check('Foo.cpp',
+                                         '#include "config.h"\n'
+                                         '#include "Foo.h"\n'
+                                         '\n'
+                                         '#include "ALocalHeader.h"\n'
+                                         '#include "FrameworkSoftLink.h"\n'
+                                         '#include <Framework/Bar.h>\n',
+                                         '*SoftLink.h header should be included after all other headers.  [build/include_order] [4]')
+
+        self.assert_language_rules_check('Foo.cpp',
+                                         '#include "config.h"\n'
+                                         '#include "Foo.h"\n'
+                                         '\n'
+                                         '#include "ALocalHeader.h"\n'
+                                         '#include <Framework/Bar.h>\n'
+                                         '\n'
+                                         '#include "FrameworkSoftLink.h"\n'
+                                         '\n'
+                                         '#if PLATFORM(FOO)\n'
+                                         '#include "FooPlatform.h"\n'
+                                         '#endif // PLATFORM(FOO)\n',
+                                         '*SoftLink.h header should be included after all other headers.  [build/include_order] [4]')
+
+        # Don't complain about *SoftLink.h headers that are last.
+        self.assert_language_rules_check('Foo.cpp',
+                                         '#include "config.h"\n'
+                                         '#include "Foo.h"\n'
+                                         '\n'
+                                         '#include "ALocalHeader.h"\n'
+                                         '#include <Framework/Bar.h>\n'
+                                         '\n'
+                                         '#if PLATFORM(FOO)\n'
+                                         '#include "FooPlatform.h"\n'
+                                         '#endif // PLATFORM(FOO)\n'
+                                         '\n'
+                                         '#include "FrameworkSoftLink.h"\n',
+                                         '')
+
+        self.assert_language_rules_check('Foo.cpp',
+                                         '#include "config.h"\n'
+                                         '#include "Foo.h"\n'
+                                         '\n'
+                                         '#include "ALocalHeader.h"\n'
+                                         '#include <Framework/Bar.h>\n'
+                                         '\n'
+                                         '#if PLATFORM(FOO)\n'
+                                         '#include "FooPlatform.h"\n'
+                                         '#endif // PLATFORM(FOO)\n'
+                                         '\n'
+                                         '#include "FrameworkASoftLink.h"\n'
+                                         '#include "FrameworkBSoftLink.h"\n',
+                                         '')
+
+        self.assert_language_rules_check('Foo.cpp',
+                                         '#include "config.h"\n'
+                                         '#include <Framework/Bar.h>\n'
+                                         '\n'
+                                         '#include "FrameworkSoftLink.h"\n',
+                                         '')
+
     def test_check_wtf_includes(self):
         self.assert_language_rules_check('foo.cpp',
                                          '#include "config.h"\n'
@@ -2918,6 +2986,10 @@
                          classify_include('foo.cpp',
                                           'public/foop.h',
                                           True, include_state))
+        self.assertEqual(cpp_style._SOFT_LINK_HEADER,
+                         classify_include('foo.cpp',
+                                          'BarSoftLink.h',
+                                          False, include_state))
         # Tricky example where both includes might be classified as primary.
         self.assert_language_rules_check('ScrollbarThemeWince.cpp',
                                          '#include "config.h"\n'
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to