| 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 gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 """Checks the #include order for the given file f.""" | 571 """Checks the #include order for the given file f.""" |
| 572 | 572 |
| 573 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') | 573 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') |
| 574 # Exclude the following includes from the check: | 574 # Exclude the following includes from the check: |
| 575 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a | 575 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a |
| 576 # specific order. | 576 # specific order. |
| 577 # 2) <atlbase.h>, "build/build_config.h" | 577 # 2) <atlbase.h>, "build/build_config.h" |
| 578 excluded_include_pattern = input_api.re.compile( | 578 excluded_include_pattern = input_api.re.compile( |
| 579 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")') | 579 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")') |
| 580 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') | 580 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') |
| 581 # Match the final or penultimate token if it is xxxtest so we can ignore it |
| 582 # when considering the special first include. |
| 583 test_file_tag_pattern = input_api.re.compile( |
| 584 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)') |
| 581 if_pattern = input_api.re.compile( | 585 if_pattern = input_api.re.compile( |
| 582 r'\s*#\s*(if|elif|else|endif|define|undef).*') | 586 r'\s*#\s*(if|elif|else|endif|define|undef).*') |
| 583 # Some files need specialized order of includes; exclude such files from this | 587 # Some files need specialized order of includes; exclude such files from this |
| 584 # check. | 588 # check. |
| 585 uncheckable_includes_pattern = input_api.re.compile( | 589 uncheckable_includes_pattern = input_api.re.compile( |
| 586 r'\s*#include ' | 590 r'\s*#include ' |
| 587 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*') | 591 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*') |
| 588 | 592 |
| 589 contents = f.NewContents() | 593 contents = f.NewContents() |
| 590 warnings = [] | 594 warnings = [] |
| 591 line_num = 0 | 595 line_num = 0 |
| 592 | 596 |
| 593 # Handle the special first include. If the first include file is | 597 # Handle the special first include. If the first include file is |
| 594 # some/path/file.h, the corresponding including file can be some/path/file.cc, | 598 # some/path/file.h, the corresponding including file can be some/path/file.cc, |
| 595 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h | 599 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h |
| 596 # etc. It's also possible that no special first include exists. | 600 # etc. It's also possible that no special first include exists. |
| 601 # If the included file is some/path/file_platform.h the including file could |
| 602 # also be some/path/file_xxxtest_platform.h. |
| 603 including_file_base_name = test_file_tag_pattern.sub( |
| 604 '', input_api.os_path.basename(f.LocalPath())) |
| 605 |
| 597 for line in contents: | 606 for line in contents: |
| 598 line_num += 1 | 607 line_num += 1 |
| 599 if system_include_pattern.match(line): | 608 if system_include_pattern.match(line): |
| 600 # No special first include -> process the line again along with normal | 609 # No special first include -> process the line again along with normal |
| 601 # includes. | 610 # includes. |
| 602 line_num -= 1 | 611 line_num -= 1 |
| 603 break | 612 break |
| 604 match = custom_include_pattern.match(line) | 613 match = custom_include_pattern.match(line) |
| 605 if match: | 614 if match: |
| 606 match_dict = match.groupdict() | 615 match_dict = match.groupdict() |
| 607 header_basename = input_api.os_path.basename( | 616 header_basename = test_file_tag_pattern.sub( |
| 608 match_dict['FILE']).replace('.h', '') | 617 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '') |
| 609 if header_basename not in input_api.os_path.basename(f.LocalPath()): | 618 |
| 619 if header_basename not in including_file_base_name: |
| 610 # No special first include -> process the line again along with normal | 620 # No special first include -> process the line again along with normal |
| 611 # includes. | 621 # includes. |
| 612 line_num -= 1 | 622 line_num -= 1 |
| 613 break | 623 break |
| 614 | 624 |
| 615 # Split into scopes: Each region between #if and #endif is its own scope. | 625 # Split into scopes: Each region between #if and #endif is its own scope. |
| 616 scopes = [] | 626 scopes = [] |
| 617 current_scope = [] | 627 current_scope = [] |
| 618 for line in contents[line_num:]: | 628 for line in contents[line_num:]: |
| 619 line_num += 1 | 629 line_num += 1 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 trybots += ['cros_x86'] | 1075 trybots += ['cros_x86'] |
| 1066 | 1076 |
| 1067 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1077 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
| 1068 # unless they're .gyp(i) files as changes to those files can break the gyp | 1078 # unless they're .gyp(i) files as changes to those files can break the gyp |
| 1069 # step on that bot. | 1079 # step on that bot. |
| 1070 if (not all(re.search('^chrome', f) for f in files) or | 1080 if (not all(re.search('^chrome', f) for f in files) or |
| 1071 any(re.search('\.gypi?$', f) for f in files)): | 1081 any(re.search('\.gypi?$', f) for f in files)): |
| 1072 trybots += ['android_aosp'] | 1082 trybots += ['android_aosp'] |
| 1073 | 1083 |
| 1074 return trybots | 1084 return trybots |
| OLD | NEW |