Changeset 83977 in webkit
- Timestamp:
- Apr 15, 2011 8:39:46 AM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r83956 r83977 1 2011-04-15 Dmitry Lomov <dslomov@google.com> 2 3 Reviewed by David Levin. 4 5 check-webkit-style shouldn't complain about not including a primary header file 6 if none exists 7 https://bugs.webkit.org/show_bug.cgi?id=39514 8 9 * Scripts/webkitpy/style/checkers/cpp.py: 10 * Scripts/webkitpy/style/checkers/cpp_unittest.py: 11 1 12 2011-04-15 Eric Seidel <eric@webkit.org> 2 13 -
trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py
r79787 r83977 313 313 return self._visited_primary_section 314 314 315 def check_next_include_order(self, header_type, file_is_header ):315 def check_next_include_order(self, header_type, file_is_header, primary_header_exists): 316 316 """Returns a non-empty error message if the next header is out of order. 317 317 … … 358 358 assert header_type == _OTHER_HEADER 359 359 if not file_is_header and self._section < self._PRIMARY_SECTION: 360 error_message = before_error_message 360 if primary_header_exists: 361 error_message = before_error_message 361 362 self._section = self._OTHER_SECTION 362 363 … … 2598 2599 2599 2600 2601 def _does_primary_header_exist(filename): 2602 """Return a primary header file name for a file, or empty string 2603 if the file is not source file or primary header does not exist. 2604 """ 2605 fileinfo = FileInfo(filename) 2606 if not fileinfo.is_source(): 2607 return False 2608 primary_header = fileinfo.no_extension() + ".h" 2609 return os.path.isfile(primary_header) 2610 2611 2600 2612 def check_include_line(filename, file_extension, clean_lines, line_number, include_state, error): 2601 2613 """Check rules that are applicable to #include lines. … … 2647 2659 2648 2660 header_type = _classify_include(filename, include, is_system, include_state) 2661 primary_header_exists = _does_primary_header_exist(filename) 2649 2662 include_state.header_types[line_number] = header_type 2650 2663 … … 2658 2671 # The include_state object keeps track of the last type seen 2659 2672 # and complains if the header types are out of order or missing. 2660 error_message = include_state.check_next_include_order(header_type, file_extension == "h") 2673 error_message = include_state.check_next_include_order(header_type, 2674 file_extension == "h", 2675 primary_header_exists) 2661 2676 2662 2677 # Check to make sure we have a blank line after primary header. -
trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
r79787 r83977 2453 2453 # Cheat os.path.abspath called in FileInfo class. 2454 2454 self.os_path_abspath_orig = os.path.abspath 2455 self.os_path_isfile_orig = os.path.isfile 2455 2456 os.path.abspath = lambda value: value 2456 2457 2457 2458 def tearDown(self): 2458 2459 os.path.abspath = self.os_path_abspath_orig 2460 os.path.isfile = self.os_path_isfile_orig 2459 2461 2460 2462 def test_check_next_include_order__no_config(self): 2461 2463 self.assertEqual('Header file should not contain WebCore config.h.', 2462 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True ))2464 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True, True)) 2463 2465 2464 2466 def test_check_next_include_order__no_self(self): 2465 2467 self.assertEqual('Header file should not contain itself.', 2466 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True ))2468 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True, True)) 2467 2469 # Test actual code to make sure that header types are correctly assigned. 2468 2470 self.assert_language_rules_check('Foo.h', … … 2476 2478 def test_check_next_include_order__likely_then_config(self): 2477 2479 self.assertEqual('Found header this file implements before WebCore config.h.', 2478 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False ))2480 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True)) 2479 2481 self.assertEqual('Found WebCore config.h after a header this file implements.', 2480 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False ))2482 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True)) 2481 2483 2482 2484 def test_check_next_include_order__other_then_config(self): 2483 2485 self.assertEqual('Found other header before WebCore config.h.', 2484 self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False ))2486 self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True)) 2485 2487 self.assertEqual('Found WebCore config.h after other header.', 2486 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False ))2488 self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True)) 2487 2489 2488 2490 def test_check_next_include_order__config_then_other_then_likely(self): 2489 self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False ))2491 self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True)) 2490 2492 self.assertEqual('Found other header before a header this file implements.', 2491 self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False ))2493 self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True)) 2492 2494 self.assertEqual('Found header this file implements after other header.', 2493 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False ))2495 self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True)) 2494 2496 2495 2497 def test_check_alphabetical_include_order(self): … … 2586 2588 '#include "g.h"\n', 2587 2589 '"foo.h" already included at foo.cpp:2 [build/include] [4]') 2590 2591 def test_primary_header(self): 2592 # File with non-existing primary header should not produce errors. 2593 self.assert_language_rules_check('foo.cpp', 2594 '#include "config.h"\n' 2595 '\n' 2596 '#include "bar.h"\n', 2597 '') 2598 # Pretend that header files exist. 2599 os.path.isfile = lambda filename: True 2600 # Missing include for existing primary header -> error. 2601 self.assert_language_rules_check('foo.cpp', 2602 '#include "config.h"\n' 2603 '\n' 2604 '#include "bar.h"\n', 2605 'Found other header before a header this file implements. ' 2606 'Should be: config.h, primary header, blank line, and then ' 2607 'alphabetically sorted. [build/include_order] [4]') 2608 # Having include for existing primary header -> no error. 2609 self.assert_language_rules_check('foo.cpp', 2610 '#include "config.h"\n' 2611 '#include "foo.h"\n' 2612 '\n' 2613 '#include "bar.h"\n', 2614 '') 2615 2616 os.path.isfile = self.os_path_isfile_orig 2617 2588 2618 2589 2619 def test_check_wtf_includes(self):
Note: See TracChangeset
for help on using the changeset viewer.