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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 (r"^base[\\\/]memory[\\\/]singleton\.h$",)) | 1496 (r"^base[\\\/]memory[\\\/]singleton\.h$",)) |
1497 return input_api.FilterSourceFile(affected_file, black_list=black_list) | 1497 return input_api.FilterSourceFile(affected_file, black_list=black_list) |
1498 | 1498 |
1499 pattern = input_api.re.compile(r'(?<!class\sbase::)Singleton\s*<') | 1499 pattern = input_api.re.compile(r'(?<!class\sbase::)Singleton\s*<') |
1500 files = [] | 1500 files = [] |
1501 for f in input_api.AffectedSourceFiles(FileFilter): | 1501 for f in input_api.AffectedSourceFiles(FileFilter): |
1502 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or | 1502 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
1503 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): | 1503 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
1504 contents = input_api.ReadFile(f) | 1504 contents = input_api.ReadFile(f) |
1505 for line in contents.splitlines(False): | 1505 for line in contents.splitlines(False): |
1506 if (not input_api.re.match(r'//', line) and # Strip C++ comment. | 1506 if (not line.lstrip().startswith('//') and # Strip C++ comment. |
1507 pattern.search(line)): | 1507 pattern.search(line)): |
1508 files.append(f) | 1508 files.append(f) |
1509 break | 1509 break |
1510 | 1510 |
1511 if files: | 1511 if files: |
1512 return [ output_api.PresubmitError( | 1512 return [ output_api.PresubmitError( |
1513 'Found base::Singleton<T> in the following header files.\n' + | 1513 'Found base::Singleton<T> in the following header files.\n' + |
1514 'Please move them to an appropriate source file so that the ' + | 1514 'Please move them to an appropriate source file so that the ' + |
1515 'template gets instantiated in a single compilation unit.', | 1515 'template gets instantiated in a single compilation unit.', |
1516 files) ] | 1516 files) ] |
1517 return [] | 1517 return [] |
1518 | 1518 |
1519 | 1519 |
1520 def _CheckBaseMacrosInHeaders(input_api, output_api): | 1520 def _CheckBaseMacrosInHeaders(input_api, output_api): |
1521 """Check for base/macros.h if DISALLOW_* macro is used.""" | 1521 """Check for base/macros.h if DISALLOW_* macro is used.""" |
1522 | 1522 |
1523 disallows = ('DISALLOW_ASSIGN', 'DISALLOW_COPY', 'DISALLOW_EVIL') | 1523 disallows = ('DISALLOW_ASSIGN', 'DISALLOW_COPY', 'DISALLOW_EVIL') |
1524 macros = '#include "base/macros.h"' | 1524 macros = '#include "base/macros.h"' |
1525 basictypes = '#include "base/basictypes.h"' | 1525 basictypes = '#include "base/basictypes.h"' |
1526 | 1526 |
1527 files = [] | 1527 files = [] |
1528 for f in input_api.AffectedSourceFiles(None): | 1528 for f in input_api.AffectedSourceFiles(None): |
1529 if not f.LocalPath().endswith('.h'): | 1529 if not f.LocalPath().endswith('.h'): |
1530 continue | 1530 continue |
1531 for line_num, line in f.ChangedContents(): | 1531 for line_num, line in f.ChangedContents(): |
| 1532 if line.lstrip().startswith('//'): # Strip C++ comment. |
| 1533 continue |
1532 if any(d in line for d in disallows): | 1534 if any(d in line for d in disallows): |
1533 contents = input_api.ReadFile(f) | 1535 contents = input_api.ReadFile(f) |
1534 if not (macros in contents or basictypes in contents): | 1536 if not (macros in contents or basictypes in contents): |
1535 files.append(f) | 1537 files.append(f) |
1536 break | 1538 break |
1537 | 1539 |
1538 msg = ('The following files appear to be using DISALLOW_* macros.\n' | 1540 msg = ('The following files appear to be using DISALLOW_* macros.\n' |
1539 'Please #include "base/macros.h" in them.') | 1541 'Please #include "base/macros.h" in them.') |
1540 return [output_api.PresubmitError(msg, files)] if files else [] | 1542 return [output_api.PresubmitError(msg, files)] if files else [] |
1541 | 1543 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1974 for master in masters: | 1976 for master in masters: |
1975 try_config.setdefault(master, {}) | 1977 try_config.setdefault(master, {}) |
1976 for builder in masters[master]: | 1978 for builder in masters[master]: |
1977 # Do not trigger presubmit builders, since they're likely to fail | 1979 # Do not trigger presubmit builders, since they're likely to fail |
1978 # (e.g. OWNERS checks before finished code review), and we're | 1980 # (e.g. OWNERS checks before finished code review), and we're |
1979 # running local presubmit anyway. | 1981 # running local presubmit anyway. |
1980 if 'presubmit' not in builder: | 1982 if 'presubmit' not in builder: |
1981 try_config[master][builder] = ['defaulttests'] | 1983 try_config[master][builder] = ['defaulttests'] |
1982 | 1984 |
1983 return try_config | 1985 return try_config |
OLD | NEW |