Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / tools / perf / PRESUBMIT.py
blob83211478d7496de0d71b85eac46e7b89fc74fb8e
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.
5 """Presubmit script for changes affecting tools/perf/.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
11 import os
12 import re
13 import sys
16 def _CommonChecks(input_api, output_api):
17 """Performs common checks, which includes running pylint."""
18 results = []
19 old_sys_path = sys.path
20 try:
21 # Modules in tools/perf depend on telemetry.
22 sys.path = [os.path.join(os.pardir, 'telemetry')] + sys.path
23 results.extend(input_api.canned_checks.RunPylint(
24 input_api, output_api, black_list=[], pylintrc='pylintrc',
25 extra_paths_list=_GetPathsToPrepend(input_api)))
26 results.extend(_CheckJson(input_api, output_api))
27 results.extend(_CheckWprShaFiles(input_api, output_api))
28 finally:
29 sys.path = old_sys_path
30 return results
33 def _GetPathsToPrepend(input_api):
34 perf_dir = input_api.PresubmitLocalPath()
35 chromium_src_dir = input_api.os_path.join(perf_dir, '..', '..')
36 telemetry_dir = input_api.os_path.join(chromium_src_dir, 'tools', 'telemetry')
37 return [
38 telemetry_dir,
39 input_api.os_path.join(telemetry_dir, 'third_party', 'mock'),
43 def _CheckWprShaFiles(input_api, output_api):
44 """Check whether the wpr sha files have matching URLs."""
45 from catapult_base import cloud_storage
46 results = []
47 for affected_file in input_api.AffectedFiles(include_deletes=False):
48 filename = affected_file.AbsoluteLocalPath()
49 if not filename.endswith('wpr.sha1'):
50 continue
51 expected_hash = cloud_storage.ReadHash(filename)
52 is_wpr_file_uploaded = any(
53 cloud_storage.Exists(bucket, expected_hash)
54 for bucket in cloud_storage.BUCKET_ALIASES.itervalues())
55 if not is_wpr_file_uploaded:
56 wpr_filename = filename[:-5]
57 results.append(output_api.PresubmitError(
58 'The file matching %s is not in Cloud Storage yet.\n'
59 'You can upload your new WPR archive file with the command:\n'
60 'depot_tools/upload_to_google_storage.py --bucket '
61 '<Your pageset\'s bucket> %s.\nFor more info: see '
62 'http://www.chromium.org/developers/telemetry/'
63 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
64 (filename, wpr_filename)))
65 return results
68 def _CheckJson(input_api, output_api):
69 """Checks whether JSON files in this change can be parsed."""
70 for affected_file in input_api.AffectedFiles(include_deletes=False):
71 filename = affected_file.AbsoluteLocalPath()
72 if os.path.splitext(filename)[1] != '.json':
73 continue
74 try:
75 input_api.json.load(open(filename))
76 except ValueError:
77 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
78 return []
81 def CheckChangeOnUpload(input_api, output_api):
82 report = []
83 report.extend(_CommonChecks(input_api, output_api))
84 return report
87 def CheckChangeOnCommit(input_api, output_api):
88 report = []
89 report.extend(_CommonChecks(input_api, output_api))
90 return report
93 def _IsBenchmarksModified(change):
94 """Checks whether CL contains any modification to Telemetry benchmarks."""
95 for affected_file in change.AffectedFiles():
96 affected_file_path = affected_file.LocalPath()
97 file_path, _ = os.path.splitext(affected_file_path)
98 if (os.path.join('tools', 'perf', 'benchmarks') in file_path or
99 os.path.join('tools', 'perf', 'measurements') in file_path):
100 return True
101 return False
104 def PostUploadHook(cl, change, output_api):
105 """git cl upload will call this hook after the issue is created/modified.
107 This hook adds extra try bots list to the CL description in order to run
108 Telemetry benchmarks on Perf trybots in addtion to CQ trybots if the CL
109 contains any changes to Telemetry benchmarks.
111 benchmarks_modified = _IsBenchmarksModified(change)
112 rietveld_obj = cl.RpcServer()
113 issue = cl.issue
114 original_description = rietveld_obj.get_description(issue)
115 if not benchmarks_modified or re.search(
116 r'^CQ_EXTRA_TRYBOTS=.*', original_description, re.M | re.I):
117 return []
119 results = []
120 bots = [
121 'linux_perf_bisect',
122 'mac_10_10_perf_bisect',
123 'win_perf_bisect',
124 'android_nexus5_perf_bisect'
126 bots = ['tryserver.chromium.perf:%s' % s for s in bots]
127 bots_string = ';'.join(bots)
128 description = original_description
129 description += '\nCQ_EXTRA_TRYBOTS=%s' % bots_string
130 results.append(output_api.PresubmitNotifyResult(
131 'Automatically added Perf trybots to run Telemetry benchmarks on CQ.'))
133 if description != original_description:
134 rietveld_obj.update_description(issue, description)
136 return results