Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: PRESUBMIT.py

Issue 11418128: PRESUBMIT #include check enhancement: <sys/..> includes can be in any order. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 for (line_num, previous_line_num) in problem_linenums: 551 for (line_num, previous_line_num) in problem_linenums:
552 if line_num in changed_linenums or previous_line_num in changed_linenums: 552 if line_num in changed_linenums or previous_line_num in changed_linenums:
553 warnings.append(' %s:%d' % (file_path, line_num)) 553 warnings.append(' %s:%d' % (file_path, line_num))
554 return warnings 554 return warnings
555 555
556 556
557 def _CheckIncludeOrderInFile(input_api, f, is_source, changed_linenums): 557 def _CheckIncludeOrderInFile(input_api, f, is_source, changed_linenums):
558 """Checks the #include order for the given file f.""" 558 """Checks the #include order for the given file f."""
559 559
560 system_include_pattern = input_api.re.compile(r'\s*#include \<.*') 560 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
561 # Exclude #include <sys/...> includes from the check; they often need to
M-A Ruel 2012/11/22 14:36:51 I'd exclude anything with the pattern \<.+\?/.+?\>
marja 2012/11/22 18:08:53 Done; though I used a simpler pattern: \s*#include
562 # appear in a specific order.
563 sys_include_pattern = input_api.re.compile(r'\s*#include \<sys/.*')
561 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') 564 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
562 if_pattern = input_api.re.compile(r'\s*#\s*(if|elif|else|endif).*') 565 if_pattern = input_api.re.compile(r'\s*#\s*(if|elif|else|endif).*')
563 566
564 contents = f.NewContents() 567 contents = f.NewContents()
565 warnings = [] 568 warnings = []
566 line_num = 0 569 line_num = 0
567 570
568 # Handle the special first include for source files. If the header file is 571 # Handle the special first include for source files. If the header file is
569 # some/path/file.h, the corresponding source file can be some/path/file.cc, 572 # some/path/file.h, the corresponding source file can be some/path/file.cc,
570 # some/other/path/file.cc, some/path/file_platform.cc etc. It's also possible 573 # some/other/path/file.cc, some/path/file_platform.cc etc. It's also possible
(...skipping 18 matching lines...) Expand all
589 break 592 break
590 593
591 # 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.
592 scopes = [] 595 scopes = []
593 current_scope = [] 596 current_scope = []
594 for line in contents[line_num:]: 597 for line in contents[line_num:]:
595 line_num += 1 598 line_num += 1
596 if if_pattern.match(line): 599 if if_pattern.match(line):
597 scopes.append(current_scope) 600 scopes.append(current_scope)
598 current_scope = [] 601 current_scope = []
599 elif (system_include_pattern.match(line) or 602 elif ((system_include_pattern.match(line) or
600 custom_include_pattern.match(line)): 603 custom_include_pattern.match(line)) and
604 not sys_include_pattern.match(line)):
601 current_scope.append((line_num, line)) 605 current_scope.append((line_num, line))
602 scopes.append(current_scope) 606 scopes.append(current_scope)
603 607
604 for scope in scopes: 608 for scope in scopes:
605 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(), 609 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
606 changed_linenums)) 610 changed_linenums))
607 return warnings 611 return warnings
608 612
609 613
610 def _CheckIncludeOrder(input_api, output_api): 614 def _CheckIncludeOrder(input_api, output_api):
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 827
824 # Match things like path/aura/file.cc and path/file_aura.cc. 828 # Match things like path/aura/file.cc and path/file_aura.cc.
825 # Same for ash and chromeos. 829 # Same for ash and chromeos.
826 if any(re.search('[/_](ash|aura)', f) for f in files): 830 if any(re.search('[/_](ash|aura)', f) for f in files):
827 trybots += ['linux_chromeos_clang:compile', 'win_aura', 831 trybots += ['linux_chromeos_clang:compile', 'win_aura',
828 'linux_chromeos_asan'] 832 'linux_chromeos_asan']
829 elif any(re.search('[/_]chromeos', f) for f in files): 833 elif any(re.search('[/_]chromeos', f) for f in files):
830 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] 834 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
831 835
832 return trybots 836 return trybots
OLDNEW
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698