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

Unified Diff: tools/telemetry/PRESUBMIT.py

Issue 1057553003: [Telemetry] Add test to prevents adding new dependencies to telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Annie's nit Created 5 years, 8 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 | tools/telemetry/TELEMETRY_DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/PRESUBMIT.py
diff --git a/tools/telemetry/PRESUBMIT.py b/tools/telemetry/PRESUBMIT.py
index b3761897dcb1120cdf00e51c4ea8c1b789e83da1..231ba3b10eb052ecc3233882bf32d0de8d3d0d76 100644
--- a/tools/telemetry/PRESUBMIT.py
+++ b/tools/telemetry/PRESUBMIT.py
@@ -1,12 +1,66 @@
# Copyright 2012 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.
+import json
import os
import sys
PYLINT_BLACKLIST = []
PYLINT_DISABLED_WARNINGS = ['R0923', 'R0201', 'E1101']
+
+def _GetCurrentTelemetryDependencies():
+ from telemetry.util import find_dependencies
+ from telemetry.util import path
+ parser = find_dependencies.FindDependenciesCommand.CreateParser()
+ find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None)
+ options, args = parser.parse_args(None)
+ options.positional_args = args
+ target_paths = [
+ os.path.join(path.GetTelemetryDir(), 'telemetry', 'benchmark_runner.py')]
+ return find_dependencies.FindDependencies(target_paths, options=options)
+
+
+def _GetRestrictedTelemetryDeps():
+ from telemetry.util import path
+ telemetry_deps = {}
dtu 2015/04/15 22:25:00 nit: Not needed.
nednguyen 2015/04/15 22:50:00 Done.
+ with open('TELEMETRY_DEPS', 'r') as f:
+ telemetry_deps = json.load(f)
+
+ # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain
+ # the relative path in chromium/src/.
+ def NormalizePath(p):
+ p = p.replace('/', os.path.sep)
+ return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p))
+
+ telemetry_deps['file_deps'] = [
+ NormalizePath(p) for p in telemetry_deps['file_deps']]
+ telemetry_deps['directory_deps'] = [
+ NormalizePath(p) for p in telemetry_deps['directory_deps']]
+ return telemetry_deps
+
+
+# TODO(nednguyen, dtu, aiolos): Remove this check when telemetry no longer has
+# dependency in chromium/src/.
+def _CheckNoExtraThirdPartyDependencies(_input_api, output_api):
+ results = []
+ telemetry_deps = _GetRestrictedTelemetryDeps()
+ current_dependencies = _GetCurrentTelemetryDependencies()
+ for dep_path in current_dependencies:
+ dep_path_is_extra_dep = not (
+ dep_path in telemetry_deps['file_deps'] or
+ any(dep_path.startswith(d) for d in telemetry_deps['directory_deps']))
dtu 2015/04/15 22:25:00 Not quite right. Use path.IsSubpath()
nednguyen 2015/04/15 22:50:00 Done.
+ if dep_path_is_extra_dep:
+ results.append(output_api.PresubmitError(
+ 'Extra third party dependency path is added to telemetry: %s' %
+ dep_path))
+ if results:
+ results.append(output_api.PresubmitError(
+ 'Your patch adds new dependencies to telemetry. Please contact aiolos@,'
+ ' dtu@, or nednguyen@ on how to proceed with this change.'))
+ return results
+
+
def _CommonChecks(input_api, output_api):
results = []
@@ -24,6 +78,7 @@ def _CommonChecks(input_api, output_api):
input_api, output_api,
black_list=PYLINT_BLACKLIST,
disabled_warnings=PYLINT_DISABLED_WARNINGS))
+ results.extend(_CheckNoExtraThirdPartyDependencies(input_api, output_api))
return results
def GetPathsToPrepend(input_api):
« no previous file with comments | « no previous file | tools/telemetry/TELEMETRY_DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698