Changeset 239250 in webkit
- Timestamp:
- Dec 14, 2018 11:51:56 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r239223 r239250 1 2018-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 1 15 2018-12-14 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py
r237826 r239250 1093 1093 'Changing pointer instead of value (or unused value of operator*).') 1094 1094 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 1104 def 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.') 1095 1132 1096 1133 class _ClassInfo(object): … … 3866 3903 check_posix_threading(clean_lines, line, error) 3867 3904 check_invalid_increment(clean_lines, line, error) 3905 check_os_version_checks(filename, clean_lines, line, error) 3868 3906 3869 3907 … … 3955 3993 'build/webcore_export', 3956 3994 'build/wk_api_available', 3995 'build/version_check', 3957 3996 'legal/copyright', 3958 3997 'readability/braces', -
trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
r233054 r239250 5529 5529 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]') 5530 5530 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 5531 5541 def test_other(self): 5532 5542 # FIXME: Implement this.
Note: See TracChangeset
for help on using the changeset viewer.