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.
15 def _CommonChecks(input_api
, output_api
):
16 """Performs common checks, which includes running pylint."""
18 old_sys_path
= sys
.path
20 # Modules in tools/perf depend on telemetry.
21 sys
.path
= [os
.path
.join(os
.pardir
, 'telemetry')] + sys
.path
22 results
.extend(input_api
.canned_checks
.RunPylint(
23 input_api
, output_api
, black_list
=[], pylintrc
='pylintrc'))
24 results
.extend(_CheckJson(input_api
, output_api
))
25 results
.extend(_CheckWprShaFiles(input_api
, output_api
))
27 sys
.path
= old_sys_path
31 def _CheckWprShaFiles(input_api
, output_api
):
32 """Check whether the wpr sha files have matching URLs."""
33 from telemetry
.util
import cloud_storage
35 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
36 filename
= affected_file
.AbsoluteLocalPath()
37 if not filename
.endswith('wpr.sha1'):
39 expected_hash
= cloud_storage
.ReadHash(filename
)
40 is_wpr_file_uploaded
= any(
41 cloud_storage
.Exists(bucket
, expected_hash
)
42 for bucket
in cloud_storage
.BUCKET_ALIASES
.itervalues())
43 if not is_wpr_file_uploaded
:
44 wpr_filename
= filename
[:-5]
45 results
.append(output_api
.PresubmitError(
46 'There is no URLs matched for wpr sha file %s.\n'
47 'You can upload your new wpr archive file with the command:\n'
48 'depot_tools/upload_to_google_storage.py --bucket '
49 '<Your pageset\'s bucket> %s.\nFor more info: see '
50 'http://www.chromium.org/developers/telemetry/'
51 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
52 (filename
, wpr_filename
)))
56 def _CheckJson(input_api
, output_api
):
57 """Checks whether JSON files in this change can be parsed."""
58 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
59 filename
= affected_file
.AbsoluteLocalPath()
60 if os
.path
.splitext(filename
)[1] != '.json':
63 input_api
.json
.load(open(filename
))
65 return [output_api
.PresubmitError('Error parsing JSON in %s!' % filename
)]
69 def CheckChangeOnUpload(input_api
, output_api
):
71 report
.extend(_CommonChecks(input_api
, output_api
))
75 def CheckChangeOnCommit(input_api
, output_api
):
77 report
.extend(_CommonChecks(input_api
, output_api
))