Changeset 239250 in webkit


Ignore:
Timestamp:
Dec 14, 2018 11:51:56 PM (5 years ago)
Author:
ap@apple.com
Message:

Add a style checker rule for Xcode version macros use
https://bugs.webkit.org/show_bug.cgi?id=192703

Reviewed by Alex Christensen.

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_os_version_checks):
(process_line):
(CppChecker):

  • Scripts/webkitpy/style/checkers/cpp_unittest.py:

(WebKitStyleTest.test_os_version_checks):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r239223 r239250  
     12018-12-14  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Add a style checker rule for Xcode version macros use
     4        https://bugs.webkit.org/show_bug.cgi?id=192703
     5
     6        Reviewed by Alex Christensen.
     7
     8        * Scripts/webkitpy/style/checkers/cpp.py:
     9        (check_os_version_checks):
     10        (process_line):
     11        (CppChecker):
     12        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     13        (WebKitStyleTest.test_os_version_checks):
     14
    1152018-12-14  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r237826 r239250  
    10931093              'Changing pointer instead of value (or unused value of operator*).')
    10941094
     1095
     1096# Matches Xcode *VERSION_MIN_REQUIRED and *VERSION_MAX_ALLOWED macros.
     1097_RE_PATTERN_XCODE_VERSION_MACRO = re.compile(
     1098    r'.+(VERSION_MIN_REQUIRED|VERSION_MAX_ALLOWED)')
     1099
     1100_RE_PATTERN_XCODE_MIN_REQUIRED_MACRO = re.compile(
     1101    r'.+?([A-Z_]+)_VERSION_MIN_REQUIRED [><=]+ (\d+)')
     1102
     1103
     1104def check_os_version_checks(filename, clean_lines, line_number, error):
     1105    """ Checks for mistakes using VERSION_MIN_REQUIRED and VERSION_MAX_ALLOWED macros:
     1106    1. These should only be used centrally to defined named HAVE, USE or ENABLE style macros.
     1107    2. VERSION_MIN_REQUIRED never changes for a minor OS version.
     1108
     1109    These should be centralized in wtf/Platform.h and wtf/FeatureDefines.h.
     1110
     1111    Args:
     1112      filename: Name of the file that is being processed.
     1113      clean_lines: A CleansedLines instance containing the file.
     1114      line_number: The number of the line to check.
     1115      error: The function to call with any errors found.
     1116    """
     1117
     1118    line = clean_lines.elided[line_number]
     1119
     1120    for version_match in _RE_PATTERN_XCODE_MIN_REQUIRED_MACRO.finditer(line):
     1121        os_prefix = version_match.group(1)
     1122        version_number = int(version_match.group(2))
     1123        if os_prefix == '__MAC_OS_X' and version_number % 100 != 0 or os_prefix != '__MAC_OS_X' and version_number % 10000 != 0:
     1124            error(line_number, 'build/version_check', 5, 'Incorrect OS version check. VERSION_MIN_REQUIRED values never include a minor version. You may be looking for a combination of VERSION_MIN_REQUIRED for target OS version check and VERSION_MAX_ALLOWED for SDK check.')
     1125            break
     1126
     1127    if filename == 'Source/WTF/wtf/Platform.h' or filename == 'Source/WTF/wtf/FeatureDefines.h':
     1128        return
     1129
     1130    if _RE_PATTERN_XCODE_VERSION_MACRO.match(line):
     1131        error(line_number, 'build/version_check', 5, 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.')
    10951132
    10961133class _ClassInfo(object):
     
    38663903    check_posix_threading(clean_lines, line, error)
    38673904    check_invalid_increment(clean_lines, line, error)
     3905    check_os_version_checks(filename, clean_lines, line, error)
    38683906
    38693907
     
    39553993        'build/webcore_export',
    39563994        'build/wk_api_available',
     3995        'build/version_check',
    39573996        'legal/copyright',
    39583997        'readability/braces',
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r233054 r239250  
    55295529        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]')
    55305530
     5531    def test_os_version_checks(self):
     5532        self.assert_lint('#if PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000', 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.  [build/version_check] [5]')
     5533        self.assert_lint('#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300', 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.  [build/version_check] [5]')
     5534        self.assert_lint('#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300', '', 'Source/WTF/wtf/Platform.h')
     5535        self.assert_lint('#if PLATFORM(MAC) && __IPHONE_OS_VERSION_MIN_REQUIRED > 120000', '', 'Source/WTF/wtf/Platform.h')
     5536        self.assert_lint('#if PLATFORM(MAC) && __IPHONE_OS_VERSION_MIN_REQUIRED > 120400', 'Incorrect OS version check. VERSION_MIN_REQUIRED values never include a minor version. You may be looking for a combination of VERSION_MIN_REQUIRED for target OS version check and VERSION_MAX_ALLOWED for SDK check.  [build/version_check] [5]', 'Source/WTF/wtf/Platform.h')
     5537        self.assert_lint('#if !TARGET_OS_SIMULATOR && __WATCH_OS_VERSION_MIN_REQUIRED < 50000', 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.  [build/version_check] [5]')
     5538        self.assert_lint('#if (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101304)', ['Incorrect OS version check. VERSION_MIN_REQUIRED values never include a minor version. You may be looking for a combination of VERSION_MIN_REQUIRED for target OS version check and VERSION_MAX_ALLOWED for SDK check.  [build/version_check] [5]', 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.  [build/version_check] [5]'])
     5539        self.assert_lint('#define FOO ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101302 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300))', 'Misplaced OS version check. Please use a named macro in wtf/Platform.h or wtf/FeatureDefines.h.  [build/version_check] [5]')
     5540
    55315541    def test_other(self):
    55325542        # FIXME: Implement this.
Note: See TracChangeset for help on using the changeset viewer.