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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 | 550 |
551 | 551 |
552 def _CheckIncludeOrderInFile(input_api, f, changed_linenums): | 552 def _CheckIncludeOrderInFile(input_api, f, changed_linenums): |
553 """Checks the #include order for the given file f.""" | 553 """Checks the #include order for the given file f.""" |
554 | 554 |
555 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') | 555 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') |
556 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes | 556 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes |
557 # often need to appear in a specific order. | 557 # often need to appear in a specific order. |
558 excluded_include_pattern = input_api.re.compile(r'\s*#include \<.*/.*') | 558 excluded_include_pattern = input_api.re.compile(r'\s*#include \<.*/.*') |
559 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') | 559 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') |
560 if_pattern = ( | 560 if_pattern = input_api.re.compile( |
561 input_api.re.compile(r'\s*#\s*(if|elif|else|endif|define|undef).*')) | 561 r'\s*#\s*(if|elif|else|endif|define|undef).*') |
562 # Some files need specialized order of includes; exclude such files from this | |
563 # check. | |
564 uncheckable_includes_pattern = input_api.re.compile( | |
565 r'\s*#include ' | |
566 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*') | |
562 | 567 |
563 contents = f.NewContents() | 568 contents = f.NewContents() |
564 warnings = [] | 569 warnings = [] |
565 line_num = 0 | 570 line_num = 0 |
566 | 571 |
567 # Handle the special first include. If the first include file is | 572 # Handle the special first include. If the first include file is |
568 # some/path/file.h, the corresponding including file can be some/path/file.cc, | 573 # some/path/file.h, the corresponding including file can be some/path/file.cc, |
569 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h | 574 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h |
570 # etc. It's also possible that no special first include exists. | 575 # etc. It's also possible that no special first include exists. |
571 for line in contents: | 576 for line in contents: |
(...skipping 12 matching lines...) Expand all Loading... | |
584 # No special first include -> process the line again along with normal | 589 # No special first include -> process the line again along with normal |
585 # includes. | 590 # includes. |
586 line_num -= 1 | 591 line_num -= 1 |
587 break | 592 break |
588 | 593 |
589 # Split into scopes: Each region between #if and #endif is its own scope. | 594 # Split into scopes: Each region between #if and #endif is its own scope. |
590 scopes = [] | 595 scopes = [] |
591 current_scope = [] | 596 current_scope = [] |
592 for line in contents[line_num:]: | 597 for line in contents[line_num:]: |
593 line_num += 1 | 598 line_num += 1 |
599 if uncheckable_includes_pattern.match(line): | |
M-A Ruel
2012/12/18 13:37:33
Why not just skip the file instead of aborting?
marja
2012/12/18 14:57:40
I assume you meant "line" instead of "file"; such
M-A Ruel
2012/12/18 20:02:07
Yes I meant line and not file. I don't mind.
lgtm
| |
600 return [] | |
594 if if_pattern.match(line): | 601 if if_pattern.match(line): |
595 scopes.append(current_scope) | 602 scopes.append(current_scope) |
596 current_scope = [] | 603 current_scope = [] |
597 elif ((system_include_pattern.match(line) or | 604 elif ((system_include_pattern.match(line) or |
598 custom_include_pattern.match(line)) and | 605 custom_include_pattern.match(line)) and |
599 not excluded_include_pattern.match(line)): | 606 not excluded_include_pattern.match(line)): |
600 current_scope.append((line_num, line)) | 607 current_scope.append((line_num, line)) |
601 scopes.append(current_scope) | 608 scopes.append(current_scope) |
602 | 609 |
603 for scope in scopes: | 610 for scope in scopes: |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 'win_aura', | 879 'win_aura', |
873 'win_rel', | 880 'win_rel', |
874 ] | 881 ] |
875 | 882 |
876 # Match things like path/aura/file.cc and path/file_aura.cc. | 883 # Match things like path/aura/file.cc and path/file_aura.cc. |
877 # Same for chromeos. | 884 # Same for chromeos. |
878 if any(re.search('[/_](aura|chromeos)', f) for f in files): | 885 if any(re.search('[/_](aura|chromeos)', f) for f in files): |
879 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] | 886 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] |
880 | 887 |
881 return trybots | 888 return trybots |
OLD | NEW |