OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 # TODO(eakuefner): Remove this test once Telemetry lives in Catapult. |
6 import os | 6 import os |
7 import platform | 7 import platform |
8 import sys | 8 import sys |
9 import unittest | 9 import unittest |
10 | 10 |
11 from telemetry.internal.util import find_dependencies | |
12 from telemetry.internal.util import path | 11 from telemetry.internal.util import path |
13 | 12 |
| 13 from core import find_dependencies |
| 14 from core import path_util |
14 | 15 |
15 _TELEMETRY_DEPS_PATH = os.path.join( | 16 _TELEMETRY_DEPS = [ |
16 path.GetTelemetryDir(), 'telemetry', 'TELEMETRY_DEPS') | 17 'build/android/devil/', |
| 18 'build/android/pylib/', |
| 19 'third_party/catapult/', |
| 20 'tools/telemetry/'] |
17 | 21 |
18 | 22 |
19 def _GetCurrentTelemetryDependencies(): | 23 def _GetCurrentTelemetryDependencies(): |
20 parser = find_dependencies.FindDependenciesCommand.CreateParser() | 24 parser = find_dependencies.FindDependenciesCommand.CreateParser() |
21 find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None) | 25 find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None) |
22 options, args = parser.parse_args(['']) | 26 options, args = parser.parse_args(['']) |
23 options.positional_args = args | 27 options.positional_args = args |
24 return find_dependencies.FindDependencies([], options=options) | 28 return find_dependencies.FindDependencies([], options=options) |
25 | 29 |
26 | 30 |
27 def _GetRestrictedTelemetryDeps(): | 31 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 # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain |
32 # the relative path in chromium/src/. | 33 # the relative path in chromium/src/. |
33 def NormalizePath(p): | 34 def NormalizePath(p): |
34 p = p.replace('/', os.path.sep) | 35 p = p.replace('/', os.path.sep) |
35 return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p)) | 36 return os.path.realpath(os.path.join(path_util.GetChromiumSrcDir(), p)) |
36 | 37 |
37 telemetry_deps['file_deps'] = [ | 38 return map(NormalizePath, _TELEMETRY_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 | 39 |
43 | 40 |
44 class TelemetryDependenciesTest(unittest.TestCase): | 41 class TelemetryDependenciesTest(unittest.TestCase): |
45 | 42 |
46 def testNoNewTelemetryDependencies(self): | 43 def testNoNewTelemetryDependencies(self): |
47 telemetry_deps = _GetRestrictedTelemetryDeps() | 44 telemetry_deps = _GetRestrictedTelemetryDeps() |
48 current_dependencies = _GetCurrentTelemetryDependencies() | 45 current_dependencies = _GetCurrentTelemetryDependencies() |
49 extra_dep_paths = [] | 46 extra_dep_paths = [] |
50 for dep_path in current_dependencies: | 47 for dep_path in current_dependencies: |
51 if not (dep_path in telemetry_deps['file_deps'] or | 48 if not any(path.IsSubpath(dep_path, d) for d in telemetry_deps): |
52 any(path.IsSubpath(dep_path, d) | |
53 for d in telemetry_deps['directory_deps'])): | |
54 extra_dep_paths.append(dep_path) | 49 extra_dep_paths.append(dep_path) |
55 # Temporarily ignore failure on Mac because test is failing on Mac 10.8 bot. | 50 # Temporarily ignore failure on Mac because test is failing on Mac 10.8 bot. |
56 # crbug.com/522335 | 51 # crbug.com/522335 |
57 if extra_dep_paths: | 52 if extra_dep_paths: |
58 if platform.system() != 'Darwin': | 53 if platform.system() != 'Darwin': |
59 self.fail( | 54 self.fail( |
60 'Your patch adds new dependencies to telemetry. Please contact ' | 55 'Your patch adds new dependencies to telemetry. Please contact ' |
61 'aiolos@,dtu@, or nednguyen@ on how to proceed with this change. ' | 56 'aiolos@,dtu@, or nednguyen@ on how to proceed with this change. ' |
62 'Extra dependencies:\n%s' % '\n'.join(extra_dep_paths)) | 57 'Extra dependencies:\n%s' % '\n'.join(extra_dep_paths)) |
63 else: | 58 else: |
64 print ('Dependencies check failed on mac platform. Extra deps: %s\n' | 59 print ('Dependencies check failed on mac platform. Extra deps: %s\n' |
65 ' sys.path: %s' % (extra_dep_paths, sys.path)) | 60 ' sys.path: %s' % (extra_dep_paths, sys.path)) |
OLD | NEW |