Update V8 to version 4.7.24.
[chromium-blink-merge.git] / tools / telemetry / PRESUBMIT.py
blobd94e787fa17791064f52345afd6813a3e09f8c1f
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):
7 results = []
9 # TODO(nduca): This should call update_docs.IsUpdateDocsNeeded().
10 # Disabled due to crbug.com/255326.
11 if False:
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),
21 pylintrc='pylintrc')
23 results.extend(_CheckNoMoreUsageOfDeprecatedCode(
24 input_api, output_api, deprecated_code='GetChromiumSrcDir()',
25 crbug_number=511332))
26 results.extend(input_api.RunTests(pylint_checks))
27 return results
30 def _CheckNoMoreUsageOfDeprecatedCode(
31 input_api, output_api, deprecated_code, crbug_number):
32 results = []
33 # These checks are not perfcet but should be good enough for most of our
34 # usecases.
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')
43 added_calls = 0
44 removed_calls = 0
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:
48 continue
49 for line in affected_file.GenerateScmDiff().splitlines():
50 if _IsAddedLine(line) and deprecated_code in line:
51 added_calls += 1
52 elif _IsRemovedLine(line) and deprecated_code in line:
53 removed_calls += 1
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)))
59 return results
62 def _GetPathsToPrepend(input_api):
63 telemetry_dir = input_api.PresubmitLocalPath()
64 chromium_src_dir = input_api.os_path.join(telemetry_dir, '..', '..')
65 return [
66 telemetry_dir,
67 input_api.os_path.join(telemetry_dir, 'third_party', 'mock'),
68 input_api.os_path.join(telemetry_dir, 'third_party', 'png'),
69 input_api.os_path.join(telemetry_dir, 'third_party', 'typ'),
70 input_api.os_path.join(telemetry_dir, 'third_party', 'webpagereplay'),
71 input_api.os_path.join(telemetry_dir, 'third_party', 'websocket-client'),
72 input_api.os_path.join(telemetry_dir, 'third_party', 'modulegraph'),
73 input_api.os_path.join(telemetry_dir, 'third_party', 'altgraph'),
75 input_api.os_path.join(chromium_src_dir, 'build', 'android'),
76 input_api.os_path.join(chromium_src_dir,
77 'third_party', 'catapult', 'tracing'),
81 def CheckChangeOnUpload(input_api, output_api):
82 results = []
83 results.extend(_CommonChecks(input_api, output_api))
84 return results
87 def CheckChangeOnCommit(input_api, output_api):
88 results = []
89 results.extend(_CommonChecks(input_api, output_api))
90 return results