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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/contrib/PRESUBMIT.py
diff --git a/tools/perf/contrib/PRESUBMIT.py b/tools/perf/contrib/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..38f2a046b110ce458a9f784cf1ad406f17e23e57
--- /dev/null
+++ b/tools/perf/contrib/PRESUBMIT.py
@@ -0,0 +1,75 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+def _CommonChecks(input_api, output_api):
+ """Performs common checks, which includes running pylint."""
+ results = []
+
+ results.extend(_CheckContribDir(input_api, output_api))
+ return results
+
+
+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 line.strip() and 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
+
+
+def _CheckContribDir(input_api, output_api):
+ """ Check to make sure that:
+ 1) tools/perf/contrib/ contains only directories, except __init__.py,
+ README.md, and PRESUBMIT.py file
+ 2) Every subdirectory in tools/perf/contrib/ must have an OWNERS file with
+ at least two OWNERS.
+ """
+ results = []
+ contrib_dir = input_api.PresubmitLocalPath()
+ init = input_api.os_path.join(contrib_dir, '__init__.py')
+ readme = input_api.os_path.join(contrib_dir, 'README.md')
+ presubmit = input_api.os_path.join(contrib_dir, 'PRESUBMIT.py')
+
+ 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, presubmit)):
+ 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 CheckChangeOnUpload(input_api, output_api):
+ report = []
+ report.extend(_CommonChecks(input_api, output_api))
+ return report
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ report = []
+ report.extend(_CommonChecks(input_api, output_api))
+ return report
« 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