OLD | NEW |
---|---|
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 import json | |
4 import os | 5 import os |
5 import sys | 6 import sys |
6 | 7 |
7 PYLINT_BLACKLIST = [] | 8 PYLINT_BLACKLIST = [] |
8 PYLINT_DISABLED_WARNINGS = ['R0923', 'R0201', 'E1101'] | 9 PYLINT_DISABLED_WARNINGS = ['R0923', 'R0201', 'E1101'] |
9 | 10 |
11 | |
12 def _GetCurrentTelemetryDependencies(): | |
13 from telemetry.util import find_dependencies | |
14 from telemetry.util import path | |
15 parser = find_dependencies.FindDependenciesCommand.CreateParser() | |
16 find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None) | |
17 options, args = parser.parse_args(None) | |
18 options.positional_args = args | |
19 target_paths = [ | |
20 os.path.join(path.GetTelemetryDir(), 'telemetry', 'benchmark_runner.py')] | |
21 return find_dependencies.FindDependencies(target_paths, options=options) | |
22 | |
23 | |
24 def _GetRestrictedTelemetryDeps(): | |
25 from telemetry.util import path | |
26 telemetry_deps = {} | |
27 with open('TELEMETRY_DEPS', 'r') as f: | |
28 telemetry_deps = json.load(f) | |
29 | |
30 # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain | |
31 # the relative path in chromium/src/. | |
32 def NormalizePath(p): | |
33 p = p.replace('/', os.path.sep) | |
34 return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p)) | |
35 | |
36 telemetry_deps['file_deps'] = [ | |
37 NormalizePath(p) for p in telemetry_deps['file_deps']] | |
38 telemetry_deps['directory_deps'] = [ | |
39 NormalizePath(p) for p in telemetry_deps['directory_deps']] | |
40 return telemetry_deps | |
41 | |
42 | |
43 #TODO(nednguyen, dtu, aiolos): Remove this check when telemetry no longer has | |
44 # dependency in chromium/src/. | |
45 def _CheckNoExtraThirdPartyDependencies(_input_api, output_api): | |
46 results = [] | |
47 telemetry_deps = _GetRestrictedTelemetryDeps() | |
48 current_dependencies = _GetCurrentTelemetryDependencies() | |
49 for dep_path in current_dependencies: | |
50 dep_path_is_extra_dep = not ( | |
51 dep_path in telemetry_deps['file_deps'] or | |
52 any(dep_path.startswith(d) for d in telemetry_deps['directory_deps'])) | |
53 if dep_path_is_extra_dep: | |
54 results.append(output_api.PresubmitError( | |
55 'Extra third party dependency path is added to telemetry: %s' % | |
56 dep_path)) | |
57 if results: | |
58 results.append(output_api.PresubmitError( | |
59 'Your patch adds new dependencies to telemetry. Please contact aiolos@,' | |
60 ' dtu@, or nednguyen@ on how to proceeds with this change.')) | |
sullivan
2015/04/14 19:20:34
nit: s/proceeds/proceed/
nednguyen
2015/04/14 19:46:53
Done.
| |
61 return results | |
62 | |
63 | |
10 def _CommonChecks(input_api, output_api): | 64 def _CommonChecks(input_api, output_api): |
11 results = [] | 65 results = [] |
12 | 66 |
13 # TODO(nduca): This should call update_docs.IsUpdateDocsNeeded(). | 67 # TODO(nduca): This should call update_docs.IsUpdateDocsNeeded(). |
14 # Disabled due to crbug.com/255326. | 68 # Disabled due to crbug.com/255326. |
15 if False: | 69 if False: |
16 update_docs_path = os.path.join( | 70 update_docs_path = os.path.join( |
17 input_api.PresubmitLocalPath(), 'update_docs') | 71 input_api.PresubmitLocalPath(), 'update_docs') |
18 assert os.path.exists(update_docs_path) | 72 assert os.path.exists(update_docs_path) |
19 results.append(output_api.PresubmitError( | 73 results.append(output_api.PresubmitError( |
20 'Docs are stale. Please run:\n' + | 74 'Docs are stale. Please run:\n' + |
21 '$ %s' % os.path.abspath(update_docs_path))) | 75 '$ %s' % os.path.abspath(update_docs_path))) |
22 | 76 |
23 results.extend(input_api.canned_checks.RunPylint( | 77 results.extend(input_api.canned_checks.RunPylint( |
24 input_api, output_api, | 78 input_api, output_api, |
25 black_list=PYLINT_BLACKLIST, | 79 black_list=PYLINT_BLACKLIST, |
26 disabled_warnings=PYLINT_DISABLED_WARNINGS)) | 80 disabled_warnings=PYLINT_DISABLED_WARNINGS)) |
81 results.extend(_CheckNoExtraThirdPartyDependencies(input_api, output_api)) | |
27 return results | 82 return results |
28 | 83 |
29 def GetPathsToPrepend(input_api): | 84 def GetPathsToPrepend(input_api): |
30 return [input_api.PresubmitLocalPath(), | 85 return [input_api.PresubmitLocalPath(), |
31 os.path.join(input_api.PresubmitLocalPath(), os.path.pardir, | 86 os.path.join(input_api.PresubmitLocalPath(), os.path.pardir, |
32 os.path.pardir, 'third_party', 'typ')] | 87 os.path.pardir, 'third_party', 'typ')] |
33 | 88 |
34 def RunWithPrependedPath(prepended_path, fn, *args): | 89 def RunWithPrependedPath(prepended_path, fn, *args): |
35 old_path = sys.path | 90 old_path = sys.path |
36 | 91 |
37 try: | 92 try: |
38 sys.path = prepended_path + old_path | 93 sys.path = prepended_path + old_path |
39 return fn(*args) | 94 return fn(*args) |
40 finally: | 95 finally: |
41 sys.path = old_path | 96 sys.path = old_path |
42 | 97 |
43 def CheckChangeOnUpload(input_api, output_api): | 98 def CheckChangeOnUpload(input_api, output_api): |
44 def go(): | 99 def go(): |
45 results = [] | 100 results = [] |
46 results.extend(_CommonChecks(input_api, output_api)) | 101 results.extend(_CommonChecks(input_api, output_api)) |
47 return results | 102 return results |
48 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) | 103 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) |
49 | 104 |
50 def CheckChangeOnCommit(input_api, output_api): | 105 def CheckChangeOnCommit(input_api, output_api): |
51 def go(): | 106 def go(): |
52 results = [] | 107 results = [] |
53 results.extend(_CommonChecks(input_api, output_api)) | 108 results.extend(_CommonChecks(input_api, output_api)) |
54 return results | 109 return results |
55 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) | 110 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) |
OLD | NEW |