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 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1276 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) | 1276 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
1277 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 1277 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
1278 results.extend(_CheckFilePermissions(input_api, output_api)) | 1278 results.extend(_CheckFilePermissions(input_api, output_api)) |
1279 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) | 1279 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
1280 results.extend(_CheckIncludeOrder(input_api, output_api)) | 1280 results.extend(_CheckIncludeOrder(input_api, output_api)) |
1281 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) | 1281 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
1282 results.extend(_CheckPatchFiles(input_api, output_api)) | 1282 results.extend(_CheckPatchFiles(input_api, output_api)) |
1283 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) | 1283 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
1284 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) | 1284 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
1285 results.extend(_CheckForInvalidOSMacros(input_api, output_api)) | 1285 results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
1286 results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api)) | |
1286 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) | 1287 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
1287 results.extend( | 1288 results.extend( |
1288 input_api.canned_checks.CheckChangeHasNoTabs( | 1289 input_api.canned_checks.CheckChangeHasNoTabs( |
1289 input_api, | 1290 input_api, |
1290 output_api, | 1291 output_api, |
1291 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1292 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1292 results.extend(_CheckSpamLogging(input_api, output_api)) | 1293 results.extend(_CheckSpamLogging(input_api, output_api)) |
1293 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1294 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1294 results.extend(_CheckCygwinShell(input_api, output_api)) | 1295 results.extend(_CheckCygwinShell(input_api, output_api)) |
1295 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1296 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1386 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): | 1387 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): |
1387 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) | 1388 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
1388 | 1389 |
1389 if not bad_macros: | 1390 if not bad_macros: |
1390 return [] | 1391 return [] |
1391 | 1392 |
1392 return [output_api.PresubmitError( | 1393 return [output_api.PresubmitError( |
1393 'Possibly invalid OS macro[s] found. Please fix your code\n' | 1394 'Possibly invalid OS macro[s] found. Please fix your code\n' |
1394 'or add your macro to src/PRESUBMIT.py.', bad_macros)] | 1395 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
1395 | 1396 |
1397 | |
1398 def _CheckForInvalidIfDefinedMacrosInFile(input_api, f): | |
1399 """Check all affected files for invalid "if defined" macros.""" | |
1400 ALWAYS_DEFINED_MACROS = ( | |
1401 "TARGET_IPHONE_SIMULATOR", | |
stuartmorgan
2014/09/25 23:42:32
From TargetConditionals.h, I'd suggest we also add
lliabraa
2014/09/26 18:22:43
Done. I added all the CPU and OS defines
| |
1402 ) | |
1403 preprocessor_statement = input_api.re.compile(r'^\s*#') | |
1404 ifdef_macro = input_api.re.compile(r'(ifdef\s|defined\()([^\s\)]+)') | |
stuartmorgan
2014/09/25 23:42:32
Why separate regexes, vs ^\s*#.*(ifdef|defined\()
lliabraa
2014/09/26 18:22:43
I copied that bit from _CheckForInvalidOSMacrosInF
| |
1405 results = [] | |
1406 for lnum, line in f.ChangedContents(): | |
1407 if preprocessor_statement.search(line): | |
1408 for match in ifdef_macro.finditer(line): | |
1409 if match.group(2) in ALWAYS_DEFINED_MACROS: | |
1410 always_defined = ' %s is always defined. ' % match.group(2) | |
1411 did_you_mean = 'Did you mean \'#if %s\'?' % match.group(2) | |
1412 results.append(' %s:%d %s\n\t%s' % (f.LocalPath(), | |
1413 lnum, | |
1414 always_defined, | |
1415 did_you_mean)) | |
1416 return results | |
1417 | |
1418 | |
1419 def _CheckForInvalidIfDefinedMacros(input_api, output_api): | |
1420 """Check all affected files for invalid "if defined" macros.""" | |
1421 bad_macros = [] | |
1422 for f in input_api.AffectedFiles(): | |
1423 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): | |
1424 bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f)) | |
1425 | |
1426 if not bad_macros: | |
1427 return [] | |
1428 | |
1429 return [output_api.PresubmitError( | |
1430 'Possibly invalid if defined macro[s] found. Please fix your code\n' | |
1431 'or add your macro to src/PRESUBMIT.py.', bad_macros)] | |
stuartmorgan
2014/09/25 23:42:32
Where would they add it to fix the error?
lliabraa
2014/09/26 18:22:43
Done. I've changed this text a bit. If the ifdef i
| |
1432 | |
1433 | |
1396 def _CheckForIPCRules(input_api, output_api): | 1434 def _CheckForIPCRules(input_api, output_api): |
1397 """Check for same IPC rules described in | 1435 """Check for same IPC rules described in |
1398 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc | 1436 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
1399 """ | 1437 """ |
1400 base_pattern = r'IPC_ENUM_TRAITS\(' | 1438 base_pattern = r'IPC_ENUM_TRAITS\(' |
1401 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) | 1439 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) |
1402 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) | 1440 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) |
1403 | 1441 |
1404 problems = [] | 1442 problems = [] |
1405 for f in input_api.AffectedSourceFiles(None): | 1443 for f in input_api.AffectedSourceFiles(None): |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 builders.extend(['cros_x86']) | 1685 builders.extend(['cros_x86']) |
1648 | 1686 |
1649 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1687 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
1650 # unless they're .gyp(i) files as changes to those files can break the gyp | 1688 # unless they're .gyp(i) files as changes to those files can break the gyp |
1651 # step on that bot. | 1689 # step on that bot. |
1652 if (not all(re.search('^chrome', f) for f in files) or | 1690 if (not all(re.search('^chrome', f) for f in files) or |
1653 any(re.search('\.gypi?$', f) for f in files)): | 1691 any(re.search('\.gypi?$', f) for f in files)): |
1654 builders.extend(['android_aosp']) | 1692 builders.extend(['android_aosp']) |
1655 | 1693 |
1656 return GetDefaultTryConfigs(builders) | 1694 return GetDefaultTryConfigs(builders) |
OLD | NEW |