2010-12-17 David Levin <levin@chromium.org>
authorlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2010 13:15:23 +0000 (13:15 +0000)
committerlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2010 13:15:23 +0000 (13:15 +0000)
        Reviewed by Eric Seidel.

        check-webkit-style should understand WTF #include guards
        https://bugs.webkit.org/show_bug.cgi?id=44911

        * Scripts/webkitpy/style/checkers/cpp.py:
        (get_header_guard_cpp_variable): modify to suggest the WTF style
        of header guard when appropriate.
        (check_for_header_guard): handle multiple return values from
        get_header_guard_cpp_variable
        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
        (CppStyleTest.test_build_header_guard): Added tests for the WTF
        header style.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74255 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py

index 74f128b..4db83d7 100644 (file)
@@ -1,3 +1,19 @@
+2010-12-17  David Levin  <levin@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        check-webkit-style should understand WTF #include guards
+        https://bugs.webkit.org/show_bug.cgi?id=44911
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (get_header_guard_cpp_variable): modify to suggest the WTF style
+        of header guard when appropriate.
+        (check_for_header_guard): handle multiple return values from
+        get_header_guard_cpp_variable
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (CppStyleTest.test_build_header_guard): Added tests for the WTF
+        header style.
+
 2010-12-16  David Levin  <levin@chromium.org>
 
         Reviewed by Eric Seidel.
index 42918d9..e841029 100644 (file)
@@ -695,7 +695,14 @@ def get_header_guard_cpp_variable(filename):
     # flymake.
     filename = re.sub(r'_flymake\.h$', '.h', filename)
 
-    return sub(r'[-.\s]', '_', os.path.basename(filename))
+    standard_name = sub(r'[-.\s]', '_', os.path.basename(filename))
+
+    # Files under WTF typically have header guards that start with WTF_.
+    if filename.find('/wtf/'):
+        special_name = "WTF_" + standard_name
+    else:
+        special_name = standard_name
+    return (special_name, standard_name)
 
 
 def check_for_header_guard(filename, lines, error):
@@ -731,13 +738,13 @@ def check_for_header_guard(filename, lines, error):
     if not ifndef or not define or ifndef != define:
         error(0, 'build/header_guard', 5,
               'No #ifndef header guard found, suggested CPP variable is: %s' %
-              cppvar)
+              cppvar[0])
         return
 
     # The guard should be File_h.
-    if ifndef != cppvar:
+    if ifndef not in cppvar:
         error(ifndef_line_number, 'build/header_guard', 5,
-              '#ifndef header guard has wrong style, please use: %s' % cppvar)
+              '#ifndef header guard has wrong style, please use: %s' % cppvar[0])
 
 
 def check_for_unicode_replacement_characters(lines, error):
index e789f57..cdbc672 100644 (file)
@@ -1741,6 +1741,35 @@ class CppStyleTest(CppStyleTestBase):
                 '  [build/header_guard] [5]' % expected_guard),
             error_collector.result_list())
 
+        # Allow the WTF_ prefix for files in that directory.
+        header_guard_filter = FilterConfiguration(('-', '+build/header_guard'))
+        error_collector = ErrorCollector(self.assert_, header_guard_filter)
+        self.process_file_data('JavaScriptCore/wtf/TestName.h', 'h',
+                               ['#ifndef WTF_TestName_h', '#define WTF_TestName_h'],
+                               error_collector)
+        self.assertEquals(0, len(error_collector.result_list()),
+                          error_collector.result_list())
+
+        # Also allow the non WTF_ prefix for files in that directory.
+        error_collector = ErrorCollector(self.assert_, header_guard_filter)
+        self.process_file_data('JavaScriptCore/wtf/TestName.h', 'h',
+                               ['#ifndef TestName_h', '#define TestName_h'],
+                               error_collector)
+        self.assertEquals(0, len(error_collector.result_list()),
+                          error_collector.result_list())
+
+        # Verify that we suggest the WTF prefix version.
+        error_collector = ErrorCollector(self.assert_, header_guard_filter)
+        self.process_file_data('JavaScriptCore/wtf/TestName.h', 'h',
+                               ['#ifndef BAD_TestName_h', '#define BAD_TestName_h'],
+                               error_collector)
+        self.assertEquals(
+            1,
+            error_collector.result_list().count(
+                '#ifndef header guard has wrong style, please use: WTF_TestName_h'
+                '  [build/header_guard] [5]'),
+            error_collector.result_list())
+
     def test_build_printf_format(self):
         self.assert_lint(
             r'printf("\%%d", value);',