1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# Copyright (c) 2014 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 sys
import os
import re
def _AddToPathIfNeeded(path):
if path not in sys.path:
sys.path.insert(0, path)
def UpdateSysPathIfNeeded():
for path in GetDependencyPaths():
_AddToPathIfNeeded(path)
def GetDependencyPaths():
# TODO(#3703): Separate the paths that are only used by the dev server into
# another call.
p = TracingProject()
return [
p.catapult_path,
p.py_vulcanize_path,
p.vinn_path,
os.path.join(p.catapult_third_party_path, 'WebOb'),
os.path.join(p.catapult_third_party_path, 'Paste'),
os.path.join(p.catapult_third_party_path, 'six'),
os.path.join(p.catapult_third_party_path, 'webapp2'),
os.path.join(p.catapult_path, 'common', 'py_utils'),
os.path.join(p.tracing_third_party_path, 'symbols')
]
def _FindAllFilesRecursive(source_paths):
assert isinstance(source_paths, list)
all_filenames = set()
for source_path in source_paths:
for dirpath, _, filenames in os.walk(source_path):
for f in filenames:
if f.startswith('.'):
continue
x = os.path.abspath(os.path.join(dirpath, f))
all_filenames.add(x)
return all_filenames
def _IsFilenameATest(x):
if x.endswith('_test.js'):
return True
if x.endswith('_test.html'):
return True
if x.endswith('_unittest.js'):
return True
if x.endswith('_unittest.html'):
return True
# TODO(nduca): Add content test?
return False
class TracingProject(object):
catapult_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), os.path.pardir))
tracing_root_path = os.path.join(catapult_path, 'tracing')
trace_processor_root_path = os.path.join(catapult_path, 'trace_processor')
common_root_path = os.path.join(catapult_path, 'common')
tracing_src_path = os.path.join(tracing_root_path, 'tracing')
extras_path = os.path.join(tracing_src_path, 'extras')
ui_extras_path = os.path.join(tracing_src_path, 'ui', 'extras')
catapult_third_party_path = os.path.join(catapult_path, 'third_party')
polymer_path = os.path.join(catapult_third_party_path, 'polymer')
tracing_third_party_path = os.path.join(tracing_root_path, 'third_party')
py_vulcanize_path = os.path.join(common_root_path, 'py_vulcanize')
vinn_path = os.path.join(catapult_third_party_path, 'vinn')
jszip_path = os.path.join(tracing_third_party_path, 'jszip')
pako_path = os.path.join(tracing_third_party_path, 'pako')
glmatrix_path = os.path.join(
tracing_third_party_path, 'gl-matrix', 'dist')
mannwhitneyu_path = os.path.join(
tracing_third_party_path, 'mannwhitneyu')
ui_path = os.path.join(tracing_src_path, 'ui')
d3_path = os.path.join(tracing_third_party_path, 'd3')
chai_path = os.path.join(tracing_third_party_path, 'chai')
mocha_path = os.path.join(tracing_third_party_path, 'mocha')
oboe_path = os.path.join(tracing_third_party_path, 'oboe')
mre_path = os.path.join(tracing_src_path, 'mre')
metrics_path = os.path.join(tracing_src_path, 'metrics')
diagnostics_path = os.path.join(tracing_src_path, 'value', 'diagnostics')
value_ui_path = os.path.join(tracing_src_path, 'value', 'ui')
metrics_ui_path = os.path.join(tracing_src_path, 'metrics', 'ui')
test_data_path = os.path.join(tracing_root_path, 'test_data')
skp_data_path = os.path.join(tracing_root_path, 'skp_data')
rjsmin_path = os.path.join(
tracing_third_party_path, 'tvcm', 'third_party', 'rjsmin')
rcssmin_path = os.path.join(
tracing_third_party_path, 'tvcm', 'third_party', 'rcssmin')
def __init__(self):
self.source_paths = []
self.source_paths.append(self.tracing_root_path)
self.source_paths.append(self.polymer_path)
self.source_paths.append(self.tracing_third_party_path)
self.source_paths.append(self.mre_path)
self.source_paths.append(self.jszip_path)
self.source_paths.append(self.pako_path)
self.source_paths.append(self.glmatrix_path)
self.source_paths.append(self.mannwhitneyu_path)
self.source_paths.append(self.d3_path)
self.source_paths.append(self.chai_path)
self.source_paths.append(self.mocha_path)
self.source_paths.append(self.oboe_path)
def CreateVulcanizer(self):
from py_vulcanize import project as project_module
return project_module.Project(self.source_paths)
def IsD8CompatibleFile(self, filename):
if filename.startswith(self.ui_path):
return False
if filename.startswith(self.value_ui_path):
return False
if filename.startswith(self.metrics_ui_path):
return False
return True
def FindAllTestModuleRelPaths(self, pred=None):
if pred is None:
pred = lambda x: True
all_filenames = _FindAllFilesRecursive([self.tracing_src_path])
test_module_filenames = [x for x in all_filenames if
_IsFilenameATest(x) and pred(x)]
test_module_filenames.sort()
return [os.path.relpath(x, self.tracing_root_path)
for x in test_module_filenames]
def FindAllMetricsModuleRelPaths(self):
all_filenames = _FindAllFilesRecursive([self.tracing_src_path])
all_metrics_module_filenames = []
for x in all_filenames:
if x.startswith(self.metrics_path) and not _IsFilenameATest(x):
all_metrics_module_filenames.append(x)
all_metrics_module_filenames.sort()
return [os.path.relpath(x, self.tracing_root_path)
for x in all_metrics_module_filenames]
def FindAllDiagnosticsModuleRelPaths(self):
all_filenames = _FindAllFilesRecursive([self.tracing_src_path])
all_diagnostics_module_filenames = []
for x in all_filenames:
if x.startswith(self.diagnostics_path) and not _IsFilenameATest(x):
all_diagnostics_module_filenames.append(x)
all_diagnostics_module_filenames.sort()
return [os.path.relpath(x, self.tracing_root_path)
for x in all_diagnostics_module_filenames]
def FindAllD8TestModuleRelPaths(self):
return self.FindAllTestModuleRelPaths(pred=self.IsD8CompatibleFile)
def GetConfigNames(self):
config_files = [
os.path.join(self.ui_extras_path, x)
for x in os.listdir(self.ui_extras_path)
if x.endswith('_config.html')
]
config_files = [x for x in config_files if os.path.isfile(x)]
config_basenames = [os.path.basename(x) for x in config_files]
config_names = [re.match('(.+)_config.html$', x).group(1)
for x in config_basenames]
return config_names
def GetDefaultConfigName(self):
assert 'full' in self.GetConfigNames()
return 'full'
def AddConfigNameOptionToParser(self, parser):
choices = self.GetConfigNames()
parser.add_argument(
'--config', dest='config_name',
choices=choices, default=self.GetDefaultConfigName(),
help='Picks a browser config. Valid choices: %s' % ', '.join(choices))
return choices
def GetModuleNameForConfigName(self, config_name):
return 'tracing.ui.extras.%s_config' % config_name
|