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

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

Issue 2869273003: Add PRESUBMIT check to enforce the rule of tools/perf/contrib/ directory (Closed)
Patch Set: remove debug print 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
(Empty)
1 # Copyright 2017 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.
4
5
6 def _CommonChecks(input_api, output_api):
7 """Performs common checks, which includes running pylint."""
8 results = []
9
10 results.extend(_CheckContribDir(input_api, output_api))
11 return results
12
13
14 def _CheckOwnershipForContribSubDir(sub_dir, input_api, output_api):
15 results = []
16 owner_file = input_api.os_path.join(sub_dir, 'OWNERS')
17 if not input_api.os_path.isfile(owner_file):
18 results.append(output_api.PresubmitError(
19 '%s must have an OWNERS file' % sub_dir))
20 else:
21 owners = []
22 with open(owner_file) as f:
23 for line in f:
24 if line.strip() and not line.strip().startswith('#'):
25 owners.append(line)
26 if len(owners) < 2:
27 results.append(output_api.PresubmitError(
28 '%s must have at least 2 owners' % owner_file))
29 return results
30
31
32 def _CheckContribDir(input_api, output_api):
33 """ Check to make sure that:
34 1) tools/perf/contrib/ contains only directories, except __init__.py,
35 README.md, and PRESUBMIT.py file
36 2) Every subdirectory in tools/perf/contrib/ must have an OWNERS file with
37 at least two OWNERS.
38 """
39 results = []
40 contrib_dir = input_api.PresubmitLocalPath()
41 init = input_api.os_path.join(contrib_dir, '__init__.py')
42 readme = input_api.os_path.join(contrib_dir, 'README.md')
43 presubmit = input_api.os_path.join(contrib_dir, 'PRESUBMIT.py')
44
45 invalid_contrib_files = []
46 for f in input_api.AffectedFiles(include_deletes=False):
47 file_path = f.AbsoluteLocalPath()
48 if (input_api.os_path.dirname(file_path) == contrib_dir and
49 not file_path in (init, readme, presubmit)):
50 invalid_contrib_files.append(file_path)
51
52 for f in input_api.os_listdir(contrib_dir):
53 path = input_api.os_path.join(contrib_dir, f)
54 if input_api.os_path.isdir(path):
55 results.extend(
56 _CheckOwnershipForContribSubDir(path, input_api, output_api))
57
58 if invalid_contrib_files:
59 results.append(output_api.PresubmitError(
60 'You cannot add files to top level of contrib directory. '
61 'Please moves these files to a sub directory:\n %s' %
62 '\n'.join(invalid_contrib_files)))
63 return results
64
65
66 def CheckChangeOnUpload(input_api, output_api):
67 report = []
68 report.extend(_CommonChecks(input_api, output_api))
69 return report
70
71
72 def CheckChangeOnCommit(input_api, output_api):
73 report = []
74 report.extend(_CommonChecks(input_api, output_api))
75 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