| OLD | NEW |
| (Empty) |
| 1 # Copyright 2015 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 import json | |
| 6 import os | |
| 7 import platform | |
| 8 import sys | |
| 9 import unittest | |
| 10 | |
| 11 from telemetry.internal.util import find_dependencies | |
| 12 from telemetry.internal.util import path | |
| 13 | |
| 14 | |
| 15 _TELEMETRY_DEPS_PATH = os.path.join( | |
| 16 path.GetTelemetryDir(), 'telemetry', 'TELEMETRY_DEPS') | |
| 17 | |
| 18 | |
| 19 def _GetCurrentTelemetryDependencies(): | |
| 20 parser = find_dependencies.FindDependenciesCommand.CreateParser() | |
| 21 find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None) | |
| 22 options, args = parser.parse_args(['']) | |
| 23 options.positional_args = args | |
| 24 return find_dependencies.FindDependencies([], options=options) | |
| 25 | |
| 26 | |
| 27 def _GetRestrictedTelemetryDeps(): | |
| 28 with open(_TELEMETRY_DEPS_PATH, 'r') as f: | |
| 29 telemetry_deps = json.load(f) | |
| 30 | |
| 31 # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain | |
| 32 # the relative path in chromium/src/. | |
| 33 def NormalizePath(p): | |
| 34 p = p.replace('/', os.path.sep) | |
| 35 return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p)) | |
| 36 | |
| 37 telemetry_deps['file_deps'] = [ | |
| 38 NormalizePath(p) for p in telemetry_deps['file_deps']] | |
| 39 telemetry_deps['directory_deps'] = [ | |
| 40 NormalizePath(p) for p in telemetry_deps['directory_deps']] | |
| 41 return telemetry_deps | |
| 42 | |
| 43 | |
| 44 class TelemetryDependenciesTest(unittest.TestCase): | |
| 45 | |
| 46 def testNoNewTelemetryDependencies(self): | |
| 47 telemetry_deps = _GetRestrictedTelemetryDeps() | |
| 48 current_dependencies = _GetCurrentTelemetryDependencies() | |
| 49 extra_dep_paths = [] | |
| 50 for dep_path in current_dependencies: | |
| 51 if not (dep_path in telemetry_deps['file_deps'] or | |
| 52 any(path.IsSubpath(dep_path, d) | |
| 53 for d in telemetry_deps['directory_deps'])): | |
| 54 extra_dep_paths.append(dep_path) | |
| 55 # Temporarily ignore failure on Mac because test is failing on Mac 10.8 bot. | |
| 56 # crbug.com/522335 | |
| 57 if extra_dep_paths: | |
| 58 if platform.system() != 'Darwin': | |
| 59 self.fail( | |
| 60 'Your patch adds new dependencies to telemetry. Please contact ' | |
| 61 'aiolos@,dtu@, or nednguyen@ on how to proceed with this change. ' | |
| 62 'Extra dependencies:\n%s' % '\n'.join(extra_dep_paths)) | |
| 63 else: | |
| 64 print ('Dependencies check failed on mac platform. Extra deps: %s\n' | |
| 65 ' sys.path: %s' % (extra_dep_paths, sys.path)) | |
| OLD | NEW |