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.
16 def _CommonChecks(input_api
, output_api
):
17 """Performs common checks, which includes running pylint."""
19 old_sys_path
= sys
.path
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 results
.extend(_CheckJson(input_api
, output_api
))
26 results
.extend(_CheckWprShaFiles(input_api
, output_api
))
28 sys
.path
= old_sys_path
32 def _CheckWprShaFiles(input_api
, output_api
):
33 """Check whether the wpr sha files have matching URLs."""
34 from catapult_base
import cloud_storage
36 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
37 filename
= affected_file
.AbsoluteLocalPath()
38 if not filename
.endswith('wpr.sha1'):
40 expected_hash
= cloud_storage
.ReadHash(filename
)
41 is_wpr_file_uploaded
= any(
42 cloud_storage
.Exists(bucket
, expected_hash
)
43 for bucket
in cloud_storage
.BUCKET_ALIASES
.itervalues())
44 if not is_wpr_file_uploaded
:
45 wpr_filename
= filename
[:-5]
46 results
.append(output_api
.PresubmitError(
47 'There is no URLs matched for wpr sha file %s.\n'
48 'You can upload your new wpr archive file with the command:\n'
49 'depot_tools/upload_to_google_storage.py --bucket '
50 '<Your pageset\'s bucket> %s.\nFor more info: see '
51 'http://www.chromium.org/developers/telemetry/'
52 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
53 (filename
, wpr_filename
)))
57 def _CheckJson(input_api
, output_api
):
58 """Checks whether JSON files in this change can be parsed."""
59 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
60 filename
= affected_file
.AbsoluteLocalPath()
61 if os
.path
.splitext(filename
)[1] != '.json':
64 input_api
.json
.load(open(filename
))
66 return [output_api
.PresubmitError('Error parsing JSON in %s!' % filename
)]
70 def CheckChangeOnUpload(input_api
, output_api
):
72 report
.extend(_CommonChecks(input_api
, output_api
))
76 def CheckChangeOnCommit(input_api
, output_api
):
78 report
.extend(_CommonChecks(input_api
, output_api
))
82 def _IsBenchmarksModified(change
):
83 """Checks whether CL contains any modification to Telemetry benchmarks."""
84 for affected_file
in change
.AffectedFiles():
85 affected_file_path
= affected_file
.LocalPath()
86 file_path
, _
= os
.path
.splitext(affected_file_path
)
87 if (os
.path
.join('tools', 'perf', 'benchmarks') in file_path
or
88 os
.path
.join('tools', 'perf', 'measurements') in file_path
):
93 def PostUploadHook(cl
, change
, output_api
):
94 """git cl upload will call this hook after the issue is created/modified.
96 This hook adds extra try bots list to the CL description in order to run
97 Telemetry benchmarks on Perf trybots in addtion to CQ trybots if the CL
98 contains any changes to Telemetry benchmarks.
100 benchmarks_modified
= _IsBenchmarksModified(change
)
101 rietveld_obj
= cl
.RpcServer()
103 original_description
= rietveld_obj
.get_description(issue
)
104 if not benchmarks_modified
or re
.search(
105 r
'^CQ_EXTRA_TRYBOTS=.*', original_description
, re
.M | re
.I
):
113 'android_nexus5_perf_bisect'
115 bots
= ['tryserver.chromium.perf:%s' % s
for s
in bots
]
116 bots_string
= ';'.join(bots
)
117 description
= original_description
118 description
+= '\nCQ_EXTRA_TRYBOTS=%s' % bots_string
119 results
.append(output_api
.PresubmitNotifyResult(
120 'Automatically added Perf trybots to run Telemetry benchmarks on CQ.'))
122 if description
!= original_description
:
123 rietveld_obj
.update_description(issue
, description
)