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_CPU_PPC", |
| 1402 "TARGET_CPU_PPC64", |
| 1403 "TARGET_CPU_68K", |
| 1404 "TARGET_CPU_X86", |
| 1405 "TARGET_CPU_ARM", |
| 1406 "TARGET_CPU_MIPS", |
| 1407 "TARGET_CPU_SPARC", |
| 1408 "TARGET_CPU_ALPHA", |
| 1409 "TARGET_IPHONE_SIMULATOR", |
| 1410 "TARGET_OS_EMBEDDED", |
| 1411 "TARGET_OS_IPHONE", |
| 1412 "TARGET_OS_MAC", |
| 1413 "TARGET_OS_UNIX", |
| 1414 "TARGET_OS_WIN32", |
| 1415 ) |
| 1416 ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)') |
| 1417 results = [] |
| 1418 for lnum, line in f.ChangedContents(): |
| 1419 for match in ifdef_macro.finditer(line): |
| 1420 if match.group(1) in ALWAYS_DEFINED_MACROS: |
| 1421 always_defined = ' %s is always defined. ' % match.group(1) |
| 1422 did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1) |
| 1423 results.append(' %s:%d %s\n\t%s' % (f.LocalPath(), |
| 1424 lnum, |
| 1425 always_defined, |
| 1426 did_you_mean)) |
| 1427 return results |
| 1428 |
| 1429 |
| 1430 def _CheckForInvalidIfDefinedMacros(input_api, output_api): |
| 1431 """Check all affected files for invalid "if defined" macros.""" |
| 1432 bad_macros = [] |
| 1433 for f in input_api.AffectedFiles(): |
| 1434 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| 1435 bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f)) |
| 1436 |
| 1437 if not bad_macros: |
| 1438 return [] |
| 1439 |
| 1440 return [output_api.PresubmitError( |
| 1441 'Found ifdef check on always-defined macro[s]. Please fix your code\n' |
| 1442 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.', |
| 1443 bad_macros)] |
| 1444 |
| 1445 |
1396 def _CheckForIPCRules(input_api, output_api): | 1446 def _CheckForIPCRules(input_api, output_api): |
1397 """Check for same IPC rules described in | 1447 """Check for same IPC rules described in |
1398 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc | 1448 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
1399 """ | 1449 """ |
1400 base_pattern = r'IPC_ENUM_TRAITS\(' | 1450 base_pattern = r'IPC_ENUM_TRAITS\(' |
1401 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) | 1451 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) |
1402 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) | 1452 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) |
1403 | 1453 |
1404 problems = [] | 1454 problems = [] |
1405 for f in input_api.AffectedSourceFiles(None): | 1455 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']) | 1697 builders.extend(['cros_x86']) |
1648 | 1698 |
1649 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1699 # 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 | 1700 # unless they're .gyp(i) files as changes to those files can break the gyp |
1651 # step on that bot. | 1701 # step on that bot. |
1652 if (not all(re.search('^chrome', f) for f in files) or | 1702 if (not all(re.search('^chrome', f) for f in files) or |
1653 any(re.search('\.gypi?$', f) for f in files)): | 1703 any(re.search('\.gypi?$', f) for f in files)): |
1654 builders.extend(['android_aosp']) | 1704 builders.extend(['android_aosp']) |
1655 | 1705 |
1656 return GetDefaultTryConfigs(builders) | 1706 return GetDefaultTryConfigs(builders) |
OLD | NEW |