OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 _TEST_ONLY_WARNING = ( | 57 _TEST_ONLY_WARNING = ( |
58 'You might be calling functions intended only for testing from\n' | 58 'You might be calling functions intended only for testing from\n' |
59 'production code. It is OK to ignore this warning if you know what\n' | 59 'production code. It is OK to ignore this warning if you know what\n' |
60 'you are doing, as the heuristics used to detect the situation are\n' | 60 'you are doing, as the heuristics used to detect the situation are\n' |
61 'not perfect. The commit queue will not block on this warning.') | 61 'not perfect. The commit queue will not block on this warning.') |
62 | 62 |
63 | 63 |
64 _INCLUDE_ORDER_WARNING = ( | 64 _INCLUDE_ORDER_WARNING = ( |
65 'Your #include order seems to be broken. Remember to use the right ' | 65 'Your #include order seems to be broken. Remember to use the right ' |
66 'collation (LC_COLLATE=C) and check https://google-styleguide.googlecode' | 66 'collation (LC_COLLATE=C) and check\nhttps://google-styleguide.googlecode' |
67 '.com/svn/trunk/cppguide.html#Names_and_Order_of_Includes') | 67 '.com/svn/trunk/cppguide.html#Names_and_Order_of_Includes') |
68 | 68 |
69 _BANNED_OBJC_FUNCTIONS = ( | 69 _BANNED_OBJC_FUNCTIONS = ( |
70 ( | 70 ( |
71 'addTrackingRect:', | 71 'addTrackingRect:', |
72 ( | 72 ( |
73 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' | 73 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
74 'prohibited. Please use CrTrackingArea instead.', | 74 'prohibited. Please use CrTrackingArea instead.', |
75 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', | 75 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
76 ), | 76 ), |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>') | 695 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>') |
696 custom_include_pattern = input_api.re.compile(r'\s*#include ".*') | 696 custom_include_pattern = input_api.re.compile(r'\s*#include ".*') |
697 | 697 |
698 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3) | 698 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3) |
699 | 699 |
700 state = C_SYSTEM_INCLUDES | 700 state = C_SYSTEM_INCLUDES |
701 | 701 |
702 previous_line = '' | 702 previous_line = '' |
703 previous_line_num = 0 | 703 previous_line_num = 0 |
704 problem_linenums = [] | 704 problem_linenums = [] |
| 705 out_of_order = " - line belongs before previous line" |
705 for line_num, line in scope: | 706 for line_num, line in scope: |
706 if c_system_include_pattern.match(line): | 707 if c_system_include_pattern.match(line): |
707 if state != C_SYSTEM_INCLUDES: | 708 if state != C_SYSTEM_INCLUDES: |
708 problem_linenums.append((line_num, previous_line_num)) | 709 problem_linenums.append((line_num, previous_line_num, |
| 710 " - C system include file in wrong block")) |
709 elif previous_line and previous_line > line: | 711 elif previous_line and previous_line > line: |
710 problem_linenums.append((line_num, previous_line_num)) | 712 problem_linenums.append((line_num, previous_line_num, |
| 713 out_of_order)) |
711 elif cpp_system_include_pattern.match(line): | 714 elif cpp_system_include_pattern.match(line): |
712 if state == C_SYSTEM_INCLUDES: | 715 if state == C_SYSTEM_INCLUDES: |
713 state = CPP_SYSTEM_INCLUDES | 716 state = CPP_SYSTEM_INCLUDES |
714 elif state == CUSTOM_INCLUDES: | 717 elif state == CUSTOM_INCLUDES: |
715 problem_linenums.append((line_num, previous_line_num)) | 718 problem_linenums.append((line_num, previous_line_num, |
| 719 " - c++ system include file in wrong block")) |
716 elif previous_line and previous_line > line: | 720 elif previous_line and previous_line > line: |
717 problem_linenums.append((line_num, previous_line_num)) | 721 problem_linenums.append((line_num, previous_line_num, out_of_order)) |
718 elif custom_include_pattern.match(line): | 722 elif custom_include_pattern.match(line): |
719 if state != CUSTOM_INCLUDES: | 723 if state != CUSTOM_INCLUDES: |
720 state = CUSTOM_INCLUDES | 724 state = CUSTOM_INCLUDES |
721 elif previous_line and previous_line > line: | 725 elif previous_line and previous_line > line: |
722 problem_linenums.append((line_num, previous_line_num)) | 726 problem_linenums.append((line_num, previous_line_num, out_of_order)) |
723 else: | 727 else: |
724 problem_linenums.append(line_num) | 728 problem_linenums.append((line_num, previous_line_num, |
| 729 "Unknown include type")) |
725 previous_line = line | 730 previous_line = line |
726 previous_line_num = line_num | 731 previous_line_num = line_num |
727 | 732 |
728 warnings = [] | 733 warnings = [] |
729 for (line_num, previous_line_num) in problem_linenums: | 734 for (line_num, previous_line_num, failure_type) in problem_linenums: |
730 if line_num in changed_linenums or previous_line_num in changed_linenums: | 735 if line_num in changed_linenums or previous_line_num in changed_linenums: |
731 warnings.append(' %s:%d' % (file_path, line_num)) | 736 warnings.append(' %s:%d:%s' % (file_path, line_num, failure_type)) |
732 return warnings | 737 return warnings |
733 | 738 |
734 | 739 |
735 def _CheckIncludeOrderInFile(input_api, f, changed_linenums): | 740 def _CheckIncludeOrderInFile(input_api, f, changed_linenums): |
736 """Checks the #include order for the given file f.""" | 741 """Checks the #include order for the given file f.""" |
737 | 742 |
738 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') | 743 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') |
739 # Exclude the following includes from the check: | 744 # Exclude the following includes from the check: |
740 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a | 745 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a |
741 # specific order. | 746 # specific order. |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 for master in masters: | 1879 for master in masters: |
1875 try_config.setdefault(master, {}) | 1880 try_config.setdefault(master, {}) |
1876 for builder in masters[master]: | 1881 for builder in masters[master]: |
1877 # Do not trigger presubmit builders, since they're likely to fail | 1882 # Do not trigger presubmit builders, since they're likely to fail |
1878 # (e.g. OWNERS checks before finished code review), and we're | 1883 # (e.g. OWNERS checks before finished code review), and we're |
1879 # running local presubmit anyway. | 1884 # running local presubmit anyway. |
1880 if 'presubmit' not in builder: | 1885 if 'presubmit' not in builder: |
1881 try_config[master][builder] = ['defaulttests'] | 1886 try_config[master][builder] = ['defaulttests'] |
1882 | 1887 |
1883 return try_config | 1888 return try_config |
OLD | NEW |