Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: tools/perf/PRESUBMIT.py

Issue 2869273003: Add PRESUBMIT check to enforce the rule of tools/perf/contrib/ directory (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Presubmit script for changes affecting tools/perf/. 5 """Presubmit script for changes affecting tools/perf/.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
11 import os 11 import os
12 import sys 12 import sys
13 13
14 14
15 def _CommonChecks(input_api, output_api): 15 def _CommonChecks(input_api, output_api):
16 """Performs common checks, which includes running pylint.""" 16 """Performs common checks, which includes running pylint."""
17 results = [] 17 results = []
18 18
19 results.extend(_CheckWprShaFiles(input_api, output_api)) 19 results.extend(_CheckWprShaFiles(input_api, output_api))
20 results.extend(_CheckJson(input_api, output_api)) 20 results.extend(_CheckJson(input_api, output_api))
21 results.extend(_CheckPerfJsonUpToDate(input_api, output_api)) 21 results.extend(_CheckPerfJsonUpToDate(input_api, output_api))
22 results.extend(_CheckContribDir(input_api, output_api))
22 results.extend(input_api.RunTests(input_api.canned_checks.GetPylint( 23 results.extend(input_api.RunTests(input_api.canned_checks.GetPylint(
23 input_api, output_api, extra_paths_list=_GetPathsToPrepend(input_api), 24 input_api, output_api, extra_paths_list=_GetPathsToPrepend(input_api),
24 pylintrc='pylintrc'))) 25 pylintrc='pylintrc')))
25 return results 26 return results
26 27
27 28
28 def _GetPathsToPrepend(input_api): 29 def _GetPathsToPrepend(input_api):
29 perf_dir = input_api.PresubmitLocalPath() 30 perf_dir = input_api.PresubmitLocalPath()
30 chromium_src_dir = input_api.os_path.join(perf_dir, '..', '..') 31 chromium_src_dir = input_api.os_path.join(perf_dir, '..', '..')
31 telemetry_dir = input_api.os_path.join( 32 telemetry_dir = input_api.os_path.join(
(...skipping 10 matching lines...) Expand all
42 ] 43 ]
43 44
44 45
45 def _RunArgs(args, input_api): 46 def _RunArgs(args, input_api):
46 p = input_api.subprocess.Popen(args, stdout=input_api.subprocess.PIPE, 47 p = input_api.subprocess.Popen(args, stdout=input_api.subprocess.PIPE,
47 stderr=input_api.subprocess.STDOUT) 48 stderr=input_api.subprocess.STDOUT)
48 out, _ = p.communicate() 49 out, _ = p.communicate()
49 return (out, p.returncode) 50 return (out, p.returncode)
50 51
51 52
53 def _CheckOwnershipForContribSubDir(sub_dir, input_api, output_api):
54 results = []
55 owner_file = input_api.os_path.join(sub_dir, 'OWNERS')
56 if not input_api.os_path.isfile(owner_file):
57 results.append(output_api.PresubmitError(
58 '%s must have an OWNERS file' % sub_dir))
59 else:
60 owners = []
61 with open(owner_file) as f:
62 for line in f:
63 if not line.strip().startswith('#'):
64 owners.append(line)
65 if len(owners) < 2:
66 results.append(output_api.PresubmitError(
67 '%s must have at least 2 owners' % owner_file))
68 return results
sullivan 2017/05/10 14:59:19 Just wanted to check there's not already an API in
nednguyen 2017/05/10 22:07:37 I look around and there is no API there that suppo
69
70
71 def _CheckContribDir(input_api, output_api):
charliea (OOO until 10-5) 2017/05/10 15:52:29 (I'm not super familiar with how PRESUBMIT.py work
72 """ Check to make sure that:
73 1) tools/perf/contrib/ contains only directories, except __init__.py file
74 and README.md file
75 2) Every subdirectory in tools/perf/contrib/ must have an OWNERS file with
76 at least two OWNERS.
77 """
78 results = []
79 contrib_dir = input_api.os_path.abspath(
80 input_api.os_path.join(input_api.PresubmitLocalPath(), 'contrib'))
81 init = input_api.os_path.join(contrib_dir, '__init__.py')
82 readme = input_api.os_path.join(contrib_dir, 'README.md')
83
84 invalid_contrib_files = []
85 for f in input_api.AffectedFiles(include_deletes=False):
86 file_path = f.AbsoluteLocalPath()
87 if (input_api.os_path.dirname(file_path) == contrib_dir and
88 not file_path in (init, readme)):
89 invalid_contrib_files.append(file_path)
90
91 for f in input_api.os_listdir(contrib_dir):
92 path = input_api.os_path.join(contrib_dir, f)
93 if input_api.os_path.isdir(path):
94 results.extend(
95 _CheckOwnershipForContribSubDir(path, input_api, output_api))
96
97 if invalid_contrib_files:
98 results.append(output_api.PresubmitError(
99 'You cannot add files to top level of contrib directory. '
100 'Please moves these files to a sub directory:\n %s' %
101 '\n'.join(invalid_contrib_files)))
102 return results
103
104
105
52 def _CheckPerfJsonUpToDate(input_api, output_api): 106 def _CheckPerfJsonUpToDate(input_api, output_api):
53 results = [] 107 results = []
54 perf_dir = input_api.PresubmitLocalPath() 108 perf_dir = input_api.PresubmitLocalPath()
55 out, return_code = _RunArgs([ 109 out, return_code = _RunArgs([
56 input_api.python_executable, 110 input_api.python_executable,
57 input_api.os_path.join(perf_dir, 'generate_perf_data'), 111 input_api.os_path.join(perf_dir, 'generate_perf_data'),
58 '--validate-only'], input_api) 112 '--validate-only'], input_api)
59 if return_code: 113 if return_code:
60 results.append(output_api.PresubmitError( 114 results.append(output_api.PresubmitError(
61 'Validating Perf JSON configs failed.', long_text=out)) 115 'Validating Perf JSON configs failed.', long_text=out))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 def CheckChangeOnUpload(input_api, output_api): 166 def CheckChangeOnUpload(input_api, output_api):
113 report = [] 167 report = []
114 report.extend(_CommonChecks(input_api, output_api)) 168 report.extend(_CommonChecks(input_api, output_api))
115 return report 169 return report
116 170
117 171
118 def CheckChangeOnCommit(input_api, output_api): 172 def CheckChangeOnCommit(input_api, output_api):
119 report = [] 173 report = []
120 report.extend(_CommonChecks(input_api, output_api)) 174 report.extend(_CommonChecks(input_api, output_api))
121 return report 175 return report
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698