1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 def _CommonChecks(input_api
, output_api
):
9 # TODO(nduca): This should call update_docs.IsUpdateDocsNeeded().
10 # Disabled due to crbug.com/255326.
12 update_docs_path
= input_api
.os_path
.join(
13 input_api
.PresubmitLocalPath(), 'update_docs')
14 assert input_api
.os_path
.exists(update_docs_path
)
15 results
.append(output_api
.PresubmitError(
16 'Docs are stale. Please run:\n' +
17 '$ %s' % input_api
.os_path
.abspath(update_docs_path
)))
19 pylint_checks
= input_api
.canned_checks
.GetPylint(
20 input_api
, output_api
, extra_paths_list
=_GetPathsToPrepend(input_api
),
23 results
.extend(_CheckNoMoreUsageOfDeprecatedCode(
24 input_api
, output_api
, deprecated_code
='GetChromiumSrcDir()',
26 results
.extend(input_api
.RunTests(pylint_checks
))
30 def _CheckNoMoreUsageOfDeprecatedCode(
31 input_api
, output_api
, deprecated_code
, crbug_number
):
33 # These checks are not perfcet but should be good enough for most of our
35 def _IsAddedLine(line
):
36 return line
.startswith('+') and not line
.startswith('+++ ')
37 def _IsRemovedLine(line
):
38 return line
.startswith('-') and not line
.startswith('--- ')
40 presubmit_dir
= input_api
.os_path
.join(
41 input_api
.PresubmitLocalPath(), 'PRESUBMIT.py')
45 for affected_file
in input_api
.AffectedFiles():
46 # Do not do the check on PRESUBMIT.py itself.
47 if affected_file
.AbsoluteLocalPath() == presubmit_dir
:
49 for line
in affected_file
.GenerateScmDiff().splitlines():
50 if _IsAddedLine(line
) and deprecated_code
in line
:
52 elif _IsRemovedLine(line
) and deprecated_code
in line
:
55 if added_calls
> removed_calls
:
56 results
.append(output_api
.PresubmitError(
57 'Your patch adds more instances of %s. Please see crbug.com/%i for'
58 'how to proceed.' % (deprecated_code
, crbug_number
)))
62 def _GetPathsToPrepend(input_api
):
63 telemetry_dir
= input_api
.PresubmitLocalPath()
64 chromium_src_dir
= input_api
.os_path
.join(telemetry_dir
, '..', '..')
67 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'altgraph'),
68 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'mock'),
69 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'modulegraph'),
70 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'pexpect'),
71 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'png'),
72 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'pyserial'),
73 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'typ'),
74 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'webpagereplay'),
75 input_api
.os_path
.join(telemetry_dir
, 'third_party', 'websocket-client'),
77 input_api
.os_path
.join(chromium_src_dir
, 'build', 'android'),
78 input_api
.os_path
.join(chromium_src_dir
,
79 'third_party', 'catapult', 'tracing'),
83 def CheckChangeOnUpload(input_api
, output_api
):
85 results
.extend(_CommonChecks(input_api
, output_api
))
89 def CheckChangeOnCommit(input_api
, output_api
):
91 results
.extend(_CommonChecks(input_api
, output_api
))