Modified: trunk/Tools/ChangeLog (149634 => 149635)
--- trunk/Tools/ChangeLog 2013-05-06 20:28:31 UTC (rev 149634)
+++ trunk/Tools/ChangeLog 2013-05-06 20:32:51 UTC (rev 149635)
@@ -1,3 +1,23 @@
+2013-05-06 Jessie Berlin <[email protected]>
+
+ check-webkit-style should complain about a layering violation if platform-specific guards are
+ used in WebCore outside of the platform directory
+ https://bugs.webkit.org/show_bug.cgi?id=115567
+
+ Reviewed by Benjamin Poulain.
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (check_for_webcore_platform_layering_violation):
+ If the file is in WebCore but not in platform and contains #if PLATFORM(SOMETHING), emit an error.
+ (process_line):
+ Add the check_for_webcore_platform_layering_violation.
+ (CppChecker):
+ List the new check.
+
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (CppStyleTest.test_webcore_platform_layering_violation):
+ Add tests.
+
2013-05-06 David Kilzer <[email protected]>
webkit-patch: fix 'upload' command with Bugzilla 4.2.5
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (149634 => 149635)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2013-05-06 20:28:31 UTC (rev 149634)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2013-05-06 20:32:51 UTC (rev 149635)
@@ -1113,6 +1113,19 @@
'Changing pointer instead of value (or unused value of operator*).')
+def check_for_webcore_platform_layering_violation(filename, clean_lines, line_number, error):
+ """Checks for platform-specific code inside WebCore outside of the platform layer."""
+ directory = FileInfo(filename).split()[0]
+ if not match(r'Source/WebCore', directory):
+ return
+ if match(r'Source/WebCore/platform', directory):
+ return
+ line = clean_lines.elided[line_number]
+ if match(r'\s*#\s*if\s*PLATFORM\s*\(', line):
+ error(line_number, 'build/webcore_platform_layering_violation', 5,
+ 'Do not add platform specific code in WebCore outside of platform.')
+
+
class _ClassInfo(object):
"""Stores information about a class."""
@@ -3561,6 +3574,7 @@
check_for_non_standard_constructs(clean_lines, line, class_state, error)
check_posix_threading(clean_lines, line, error)
check_invalid_increment(clean_lines, line, error)
+ check_for_webcore_platform_layering_violation(filename, clean_lines, line, error)
def _process_lines(filename, file_extension, lines, error, min_confidence):
@@ -3627,6 +3641,7 @@
'build/printf_format',
'build/storage_class',
'build/using_std',
+ 'build/webcore_platform_layering_violation',
'legal/copyright',
'readability/braces',
'readability/casting',
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (149634 => 149635)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2013-05-06 20:28:31 UTC (rev 149634)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2013-05-06 20:32:51 UTC (rev 149635)
@@ -2448,6 +2448,26 @@
self.assert_lint('long int a : 30;', errmsg)
self.assert_lint('int a = 1 ? 0 : 30;', '')
+ def test_webcore_platform_layering_violation(self):
+ errmsg = ('Do not add platform specific code in WebCore outside of platform. [build/webcore_platform_layering_violation] [5]')
+
+ error_collector = ErrorCollector(self.assertTrue)
+ self.process_file_data('Source/WebCore/loader/NavigationAction.cpp', 'cpp', ['#if PLATFORM(MAC)', '#endif'], error_collector)
+ self.assertEqual(1, error_collector.result_list().count(errmsg))
+
+ error_collector = ErrorCollector(self.assertTrue)
+ self.process_file_data('Source/WebCore/platform/PlatformEvent.cpp', 'cpp', ['#if PLATFORM(MAC)', '#endif'], error_collector)
+ self.assertEqual(0, error_collector.result_list().count(errmsg))
+
+ error_collector = ErrorCollector(self.assertTrue)
+ self.process_file_data('Source/WebCore/loader/NavigationAction.cpp', 'cpp', ['#if PLATFORM ( MAC )', '#endif'], error_collector)
+ self.assertEqual(1, error_collector.result_list().count(errmsg))
+
+ error_collector = ErrorCollector(self.assertTrue)
+ self.process_file_data('Source/WebCore/loader/NavigationAction.cpp', 'cpp', ['// #if PLATFORM(MAC)', '#endif'], error_collector)
+ self.assertEqual(0, error_collector.result_list().count(errmsg))
+
+
class CleansedLinesTest(unittest.TestCase):
def test_init(self):
lines = ['Line 1',