Title: [226618] trunk/Tools
Revision
226618
Author
fred.w...@free.fr
Date
2018-01-09 01:05:34 -0800 (Tue, 09 Jan 2018)

Log Message

check-webkit-style: Verify syntax for WK_API_AVAILABLE
https://bugs.webkit.org/show_bug.cgi?id=181394

Patch by Frederic Wang <fw...@igalia.com.fr> on 2018-01-09
Reviewed by Darin Adler.

A common syntax error for WK_API_AVAILABLE is to write ios(WK_MAC_TBA)
as the second parameter instead of ios(WK_IOS_TBA). This generally
builds for iOS on EWS but not when using the public SDK. See r224057,
r223207 and r226211 for example. This patch adds a basic style check
for that macro to prevent this kind of mistake.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_min_versions_of_wk_api_available): New function to verify the parameters of WX_API_AVAILABLE.
(check_style): Run new style check.
(CppChecker): Add build type for the new style check.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_min_versions_of_wk_api_available): Add tests for the new style check.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (226617 => 226618)


--- trunk/Tools/ChangeLog	2018-01-09 08:34:34 UTC (rev 226617)
+++ trunk/Tools/ChangeLog	2018-01-09 09:05:34 UTC (rev 226618)
@@ -1,3 +1,23 @@
+2018-01-09  Frederic Wang  <fw...@igalia.com.fr>
+
+        check-webkit-style: Verify syntax for WK_API_AVAILABLE
+        https://bugs.webkit.org/show_bug.cgi?id=181394
+
+        Reviewed by Darin Adler.
+
+        A common syntax error for WK_API_AVAILABLE is to write ios(WK_MAC_TBA)
+        as the second parameter instead of ios(WK_IOS_TBA). This generally
+        builds for iOS on EWS but not when using the public SDK. See r224057,
+        r223207 and r226211 for example. This patch adds a basic style check
+        for that macro to prevent this kind of mistake.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_min_versions_of_wk_api_available): New function to verify the parameters of WX_API_AVAILABLE.
+        (check_style): Run new style check.
+        (CppChecker): Add build type for the new style check.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_min_versions_of_wk_api_available): Add tests for the new style check.
+
 2018-01-08  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [Attachment Support] Expose HTMLAttachmentElement.uniqueIdentifier to bindings

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2018-01-09 08:34:34 UTC (rev 226617)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2018-01-09 09:05:34 UTC (rev 226618)
@@ -2767,6 +2767,27 @@
     return len(line)
 
 
+def check_min_versions_of_wk_api_available(clean_lines, line_number, error):
+    """Checks the min version numbers of WK_API_AVAILABLE
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      error: The function to call with any errors found.
+    """
+
+    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
+
+    wk_api_available = search(r'WK_API_AVAILABLE\(macosx\(([^\)]+)\), ios\(([^\)]+)\)\)', line)
+    if wk_api_available:
+        macosxMinVersion = wk_api_available.group(1)
+        if not match(r'^([\d\.]+|WK_MAC_TBA)$', macosxMinVersion):
+            error(line_number, 'build/wk_api_available', 5, '%s is neither a version number nor WK_MAC_TBA' % macosxMinVersion)
+
+        iosMinVersion = wk_api_available.group(2)
+        if not match(r'^([\d\.]+|WK_IOS_TBA)$', iosMinVersion):
+            error(line_number, 'build/wk_api_available', 5, '%s is neither a version number nor WK_IOS_TBA' % iosMinVersion)
+
 def check_style(clean_lines, line_number, file_extension, class_state, file_state, enum_state, error):
     """Checks rules from the 'C++ style rules' section of cppguide.html.
 
@@ -2842,6 +2863,7 @@
     check_soft_link_class_alloc(clean_lines, line_number, error)
     check_indentation_amount(clean_lines, line_number, error)
     check_enum_casing(clean_lines, line_number, enum_state, error)
+    check_min_versions_of_wk_api_available(clean_lines, line_number, error)
 
 
 _RE_PATTERN_INCLUDE_NEW_STYLE = re.compile(r'#(?:include|import) +"[^/]+\.h"')
@@ -3892,6 +3914,7 @@
         'build/using_std',
         'build/using_namespace',
         'build/cpp_comment',
+        'build/wk_api_available',
         'legal/copyright',
         'readability/braces',
         'readability/casting',

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2018-01-09 08:34:34 UTC (rev 226617)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2018-01-09 09:05:34 UTC (rev 226618)
@@ -5433,6 +5433,12 @@
         self.assert_lint('o = foo(b ? bar() : baz());', '')
         self.assert_lint('MYMACRO(a ? b() : c);', '')
 
+    def test_min_versions_of_wk_api_available(self):
+        self.assert_lint('WK_API_AVAILABLE(macosx(1.2.3), ios(3.4.5))', '')  # version numbers are OK.
+        self.assert_lint('WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))', '')  # WK_MAC_TBA and WK_IOS_TBA are OK.
+        self.assert_lint('WK_API_AVAILABLE(macosx(WK_IOS_TBA), ios(3.4.5))', 'WK_IOS_TBA is neither a version number nor WK_MAC_TBA  [build/wk_api_available] [5]')
+        self.assert_lint('WK_API_AVAILABLE(macosx(1.2.3), ios(WK_MAC_TBA))', 'WK_MAC_TBA is neither a version number nor WK_IOS_TBA  [build/wk_api_available] [5]')
+
     def test_other(self):
         # FIXME: Implement this.
         pass
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to