OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 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 sys | 5 import sys |
6 import os | 6 import os |
7 | 7 |
8 | 8 |
9 def _AddToPathIfNeeded(path): | 9 def _AddToPathIfNeeded(path): |
10 if path not in sys.path: | 10 if path not in sys.path: |
(...skipping 13 matching lines...) Expand all Loading... |
24 def UpdateSysPathIfNeeded(): | 24 def UpdateSysPathIfNeeded(): |
25 p = PerfInsightsProject() | 25 p = PerfInsightsProject() |
26 | 26 |
27 _AddToPathIfNeeded(p.perf_insights_third_party_path) | 27 _AddToPathIfNeeded(p.perf_insights_third_party_path) |
28 | 28 |
29 # TODO(fmeawad): We should add catapult projects even inside | 29 # TODO(fmeawad): We should add catapult projects even inside |
30 # appengine, see issue #1246 | 30 # appengine, see issue #1246 |
31 if not _IsRunningInAppEngine(): | 31 if not _IsRunningInAppEngine(): |
32 _AddToPathIfNeeded(p.catapult_path) | 32 _AddToPathIfNeeded(p.catapult_path) |
33 _AddToPathIfNeeded(p.tracing_root_path) | 33 _AddToPathIfNeeded(p.tracing_root_path) |
34 _AddToPathIfNeeded(p.beautifulsoup_path) | 34 _AddToPathIfNeeded(p.py_vulcanize_path) |
35 | 35 |
36 import tracing_project | 36 import tracing_project |
37 tracing_project.UpdateSysPathIfNeeded() | 37 tracing_project.UpdateSysPathIfNeeded() |
38 | 38 |
39 | 39 |
40 def _FindAllFilesRecursive(source_paths): | 40 def _FindAllFilesRecursive(source_paths): |
41 assert isinstance(source_paths, list) | 41 assert isinstance(source_paths, list) |
42 all_filenames = set() | 42 all_filenames = set() |
43 for source_path in source_paths: | 43 for source_path in source_paths: |
44 for dirpath, _, filenames in os.walk(source_path): | 44 for dirpath, _, filenames in os.walk(source_path): |
(...skipping 16 matching lines...) Expand all Loading... |
61 return True | 61 return True |
62 | 62 |
63 if x.endswith('_unittest.html'): | 63 if x.endswith('_unittest.html'): |
64 return True | 64 return True |
65 | 65 |
66 # TODO(nduca): Add content test? | 66 # TODO(nduca): Add content test? |
67 return False | 67 return False |
68 | 68 |
69 | 69 |
70 class PerfInsightsProject(object): | 70 class PerfInsightsProject(object): |
71 catapult_path = os.path.abspath( | 71 catapult_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
72 os.path.join(os.path.dirname(__file__), '..')) | |
73 | 72 |
74 perf_insights_root_path = os.path.abspath( | 73 perf_insights_root_path = os.path.abspath( |
75 os.path.join(catapult_path, 'perf_insights')) | 74 os.path.join(catapult_path, 'perf_insights')) |
76 perf_insights_src_path = os.path.abspath( | 75 perf_insights_src_path = os.path.abspath( |
77 os.path.join(perf_insights_root_path, 'perf_insights')) | 76 os.path.join(perf_insights_root_path,'perf_insights')) |
78 perf_insights_ui_path = os.path.abspath( | 77 perf_insights_ui_path = os.path.abspath( |
79 os.path.join(perf_insights_src_path, 'ui')) | 78 os.path.join(perf_insights_src_path, 'ui')) |
80 perf_insights_test_data_path = os.path.abspath( | 79 perf_insights_test_data_path = os.path.abspath( |
81 os.path.join(perf_insights_root_path, 'test_data')) | 80 os.path.join(perf_insights_root_path, 'test_data')) |
82 perf_insights_examples_path = os.path.abspath( | 81 perf_insights_examples_path = os.path.abspath( |
83 os.path.join(perf_insights_root_path, 'perf_insights_examples')) | 82 os.path.join(perf_insights_root_path, 'perf_insights_examples')) |
84 | |
85 perf_insights_third_party_path = os.path.abspath( | 83 perf_insights_third_party_path = os.path.abspath( |
86 os.path.join(perf_insights_root_path, 'third_party')) | 84 os.path.join(perf_insights_root_path, 'third_party')) |
87 | 85 |
88 tracing_root_path = os.path.abspath( | 86 tracing_root_path = os.path.abspath( |
89 os.path.join(catapult_path, 'tracing')) | 87 os.path.join(catapult_path, 'tracing')) |
90 | 88 |
91 beautifulsoup_path = os.path.abspath( | 89 py_vulcanize_path = os.path.abspath( |
92 os.path.join(tracing_root_path, 'third_party', 'tvcm', | 90 os.path.join(catapult_path, 'third_party', 'py_vulcanize')) |
93 'third_party', 'beautifulsoup')) | |
94 | |
95 | 91 |
96 def __init__(self): # pylint: disable=unused-argument | 92 def __init__(self): # pylint: disable=unused-argument |
97 self._source_paths = None | 93 self._source_paths = None |
98 | 94 |
99 @property | 95 @property |
100 def source_paths(self): | 96 def source_paths(self): |
101 # We lazily init of source_paths because for perf_insights_project's | 97 # We lazily init of source_paths because for perf_insights_project's |
102 # UpdateSysPathIfNeeded to run, the PerfInsightsProject must be __init__'d, | 98 # UpdateSysPathIfNeeded to run, the PerfInsightsProject must be __init__'d, |
103 # because thats where we centralize the various directory names. | 99 # because thats where we centralize the various directory names. |
104 # And, for source_paths to be set up, we need the UpdateSysPathIfNeeded to | 100 # And, for source_paths to be set up, we need the UpdateSysPathIfNeeded to |
105 # have run! We use laziness to resolve this cyclic dependency. | 101 # have run! We use laziness to resolve this cyclic dependency. |
106 if self._source_paths is None: | 102 if self._source_paths is None: |
107 self._source_paths = [] | 103 self._source_paths = [] |
108 self._source_paths.append(self.perf_insights_root_path) | 104 self._source_paths.append(self.perf_insights_root_path) |
109 | 105 |
110 import tracing_project as tracing_project_module | 106 import tracing_project as tracing_project_module |
111 tracing_project = tracing_project_module.TracingProject() | 107 tracing_project = tracing_project_module.TracingProject() |
112 self._source_paths.extend(tracing_project.source_paths) | 108 self._source_paths.extend(tracing_project.source_paths) |
113 | 109 |
114 return self._source_paths | 110 return self._source_paths |
115 | 111 |
116 def GetAbsPathFromHRef(self, href): | 112 def GetAbsPathFromHRef(self, href): |
117 for source_path in self.source_paths: | 113 for source_path in self.source_paths: |
118 candidate = os.path.abspath(os.path.join(source_path, href[1:])) | 114 candidate = os.path.abspath(os.path.join(source_path, href[1:])) |
119 if os.path.exists(candidate): | 115 if os.path.exists(candidate): |
120 return candidate | 116 return candidate |
121 return None | 117 return None |
122 | 118 |
123 def CreateVulcanizer(self): | 119 def CreateVulcanizer(self): |
124 from tvcm import project as project_module | 120 from py_vulcanize import project as project_module |
125 return project_module.Project(self.source_paths) | 121 return project_module.Project(self.source_paths) |
126 | 122 |
127 def IsD8CompatibleFile(self, filename): | 123 def IsD8CompatibleFile(self, filename): |
128 if filename.startswith(self.perf_insights_ui_path): | 124 if filename.startswith(self.perf_insights_ui_path): |
129 return False | 125 return False |
130 return True | 126 return True |
131 | 127 |
132 def FindAllTestModuleRelPaths(self, pred=None): | 128 def FindAllTestModuleRelPaths(self, pred=None): |
133 if pred is None: | 129 if pred is None: |
134 pred = lambda x: True | 130 pred = lambda x: True |
135 all_filenames = _FindAllFilesRecursive([self.perf_insights_src_path, | 131 all_filenames = _FindAllFilesRecursive([self.perf_insights_src_path, |
136 self.perf_insights_examples_path]) | 132 self.perf_insights_examples_path]) |
137 test_module_filenames = [x for x in all_filenames if | 133 test_module_filenames = [x for x in all_filenames if |
138 _IsFilenameATest(x) and pred(x)] | 134 _IsFilenameATest(x) and pred(x)] |
139 test_module_filenames.sort() | 135 test_module_filenames.sort() |
140 | 136 |
141 return [os.path.relpath(x, self.perf_insights_root_path) | 137 return [os.path.relpath(x, self.perf_insights_root_path) |
142 for x in test_module_filenames] | 138 for x in test_module_filenames] |
143 | 139 |
144 def FindAllD8TestModuleRelPaths(self): | 140 def FindAllD8TestModuleRelPaths(self): |
145 return self.FindAllTestModuleRelPaths(pred=self.IsD8CompatibleFile) | 141 return self.FindAllTestModuleRelPaths(pred=self.IsD8CompatibleFile) |
OLD | NEW |