Chromium Code Reviews| Index: tools/perf/PRESUBMIT.py |
| diff --git a/tools/perf/PRESUBMIT.py b/tools/perf/PRESUBMIT.py |
| index 5c02969c992563f15e961787aadec1c855f7049b..9094e09f371409cd30895cfe164c6ffd3e03f314 100644 |
| --- a/tools/perf/PRESUBMIT.py |
| +++ b/tools/perf/PRESUBMIT.py |
| @@ -19,6 +19,7 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckWprShaFiles(input_api, output_api)) |
| results.extend(_CheckJson(input_api, output_api)) |
| results.extend(_CheckPerfJsonUpToDate(input_api, output_api)) |
| + results.extend(_CheckContribDir(input_api, output_api)) |
| results.extend(input_api.RunTests(input_api.canned_checks.GetPylint( |
| input_api, output_api, extra_paths_list=_GetPathsToPrepend(input_api), |
| pylintrc='pylintrc'))) |
| @@ -49,6 +50,59 @@ def _RunArgs(args, input_api): |
| return (out, p.returncode) |
| +def _CheckOwnershipForContribSubDir(sub_dir, input_api, output_api): |
| + results = [] |
| + owner_file = input_api.os_path.join(sub_dir, 'OWNERS') |
| + if not input_api.os_path.isfile(owner_file): |
| + results.append(output_api.PresubmitError( |
| + '%s must have an OWNERS file' % sub_dir)) |
| + else: |
| + owners = [] |
| + with open(owner_file) as f: |
| + for line in f: |
| + if not line.strip().startswith('#'): |
| + owners.append(line) |
| + if len(owners) < 2: |
| + results.append(output_api.PresubmitError( |
| + '%s must have at least 2 owners' % owner_file)) |
| + 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
|
| + |
| + |
| +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
|
| + """ Check to make sure that: |
| + 1) tools/perf/contrib/ contains only directories, except __init__.py file |
| + and README.md file |
| + 2) Every subdirectory in tools/perf/contrib/ must have an OWNERS file with |
| + at least two OWNERS. |
| + """ |
| + results = [] |
| + contrib_dir = input_api.os_path.abspath( |
| + input_api.os_path.join(input_api.PresubmitLocalPath(), 'contrib')) |
| + init = input_api.os_path.join(contrib_dir, '__init__.py') |
| + readme = input_api.os_path.join(contrib_dir, 'README.md') |
| + |
| + invalid_contrib_files = [] |
| + for f in input_api.AffectedFiles(include_deletes=False): |
| + file_path = f.AbsoluteLocalPath() |
| + if (input_api.os_path.dirname(file_path) == contrib_dir and |
| + not file_path in (init, readme)): |
| + invalid_contrib_files.append(file_path) |
| + |
| + for f in input_api.os_listdir(contrib_dir): |
| + path = input_api.os_path.join(contrib_dir, f) |
| + if input_api.os_path.isdir(path): |
| + results.extend( |
| + _CheckOwnershipForContribSubDir(path, input_api, output_api)) |
| + |
| + if invalid_contrib_files: |
| + results.append(output_api.PresubmitError( |
| + 'You cannot add files to top level of contrib directory. ' |
| + 'Please moves these files to a sub directory:\n %s' % |
| + '\n'.join(invalid_contrib_files))) |
| + return results |
| + |
| + |
| + |
| def _CheckPerfJsonUpToDate(input_api, output_api): |
| results = [] |
| perf_dir = input_api.PresubmitLocalPath() |