Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index 27f03a9ffb0b5303734eedf3a6450d0d399e658e..b6481046101cc3d5ac3f18e1302d8a465cc7f4db 100644 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -8,6 +8,7 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| for more details about the presubmit API built into gcl. |
| """ |
| + |
| _EXCLUDED_PATHS = ( |
| r"^breakpad[\\\/].*", |
| r"^net/tools/spdyshark/[\\\/].*", |
| @@ -17,6 +18,15 @@ _EXCLUDED_PATHS = ( |
| ) |
| +_TEST_ONLY_WARNING = ( |
| + 'You might be calling functions intended only for testing from\n' |
| + 'production code. It is OK to ignore this warning if you know what\n' |
| + 'you are doing, as the heuristics used to detect the situation are\n' |
| + 'not perfect. The commit queue will not block on this warning.\n' |
| + 'Email joi@chromium.org if you have questions.') |
| + |
| + |
| + |
| def _CheckNoInterfacesInBase(input_api, output_api): |
| """Checks to make sure no files in libbase.a have |@interface|.""" |
| pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) |
| @@ -37,7 +47,9 @@ def _CheckNoInterfacesInBase(input_api, output_api): |
| return [] |
| -def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| +def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, |
| + output_api, |
| + committing): |
| """Attempts to prevent use of functions intended only for testing in |
| non-testing code. For now this is just a best-effort implementation |
| that ignores header files and may have some false positives. A |
| @@ -87,11 +99,11 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| line_number += 1 |
| if problems: |
| - return [output_api.PresubmitPromptWarning( |
| - 'You might be calling functions intended only for testing from\n' |
| - 'production code. Please verify that the following usages are OK,\n' |
| - 'and email joi@chromium.org if you are seeing false positives:', |
| - problems)] |
| + if not committing: |
|
M-A Ruel
2011/11/17 20:16:58
Use input_api.is_committing instead. It will simpl
|
| + return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)] |
| + else: |
| + # We don't warn on commit, to avoid stopping commits going through CQ. |
| + return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)] |
| else: |
| return [] |
| @@ -149,7 +161,7 @@ def _CheckNoDEPSGIT(input_api, output_api): |
| return [] |
| -def _CommonChecks(input_api, output_api): |
| +def _CommonChecks(input_api, output_api, committing=False): |
| """Checks common to both upload and commit.""" |
| results = [] |
| results.extend(input_api.canned_checks.PanProjectChecks( |
| @@ -157,7 +169,8 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckNoInterfacesInBase(input_api, output_api)) |
| results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
| results.extend( |
| - _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
| + _CheckNoProductionCodeUsingTestOnlyFunctions( |
| + input_api, output_api, committing)) |
| results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| results.extend(_CheckNoNewWStrings(input_api, output_api)) |
| results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
| @@ -246,7 +259,7 @@ def CheckChangeOnUpload(input_api, output_api): |
| def CheckChangeOnCommit(input_api, output_api): |
| results = [] |
| - results.extend(_CommonChecks(input_api, output_api)) |
| + results.extend(_CommonChecks(input_api, output_api, committing=True)) |
| # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| # input_api, output_api, sources)) |