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 PYLINT_DISABLED_WARNINGS
= [
16 'R0923', # Interface not implemented
17 'R0201', # Method could be a function
18 'E1101', # Non-existent member is accessed.
22 def _CommonChecks(input_api
, output_api
):
23 """Performs common checks, which includes running pylint."""
25 old_sys_path
= sys
.path
27 # Modules in tools/perf depend on telemetry.
28 sys
.path
= [os
.path
.join(os
.pardir
, 'telemetry')] + sys
.path
29 results
.extend(input_api
.canned_checks
.RunPylint(
30 input_api
, output_api
,
31 black_list
=PYLINT_BLACKLIST
,
32 disabled_warnings
=PYLINT_DISABLED_WARNINGS
))
33 results
.extend(_CheckJson(input_api
, output_api
))
34 results
.extend(_CheckWprShaFiles(input_api
, output_api
))
36 sys
.path
= old_sys_path
40 def _CheckWprShaFiles(input_api
, output_api
):
41 """Check whether the wpr sha files have matching URLs."""
42 from telemetry
.util
import cloud_storage
44 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
45 filename
= affected_file
.AbsoluteLocalPath()
46 if not filename
.endswith('wpr.sha1'):
48 expected_hash
= cloud_storage
.ReadHash(filename
)
49 is_wpr_file_uploaded
= any(
50 cloud_storage
.Exists(bucket
, expected_hash
)
51 for bucket
in cloud_storage
.BUCKET_ALIASES
.itervalues())
52 if not is_wpr_file_uploaded
:
53 wpr_filename
= filename
[:-5]
54 results
.append(output_api
.PresubmitError(
55 'There is no URLs matched for wpr sha file %s.\n'
56 'You can upload your new wpr archive file with the command:\n'
57 'depot_tools/upload_to_google_storage.py --bucket '
58 '<Your pageset\'s bucket> %s.\nFor more info: see '
59 'http://www.chromium.org/developers/telemetry/'
60 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
61 (filename
, wpr_filename
)))
65 def _CheckJson(input_api
, output_api
):
66 """Checks whether JSON files in this change can be parsed."""
67 for affected_file
in input_api
.AffectedFiles(include_deletes
=False):
68 filename
= affected_file
.AbsoluteLocalPath()
69 if os
.path
.splitext(filename
)[1] != '.json':
72 input_api
.json
.load(open(filename
))
74 return [output_api
.PresubmitError('Error parsing JSON in %s!' % filename
)]
78 def CheckChangeOnUpload(input_api
, output_api
):
80 report
.extend(_CommonChecks(input_api
, output_api
))
84 def CheckChangeOnCommit(input_api
, output_api
):
86 report
.extend(_CommonChecks(input_api
, output_api
))