Web Inspector: implement Flame Chart for CPU profiler.
[WebKit-https.git] / Source / WebCore / inspector / compile-front-end.py
1 #!/usr/bin/env python
2 # Copyright (c) 2012 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import os
31 import os.path
32 import generate_protocol_externs
33 import shutil
34 import sys
35 import tempfile
36
37 inspector_path = "Source/WebCore/inspector"
38 inspector_frontend_path = inspector_path + "/front-end"
39 protocol_externs_path = inspector_frontend_path + "/protocol-externs.js"
40
41 generate_protocol_externs.generate_protocol_externs(protocol_externs_path, inspector_path + "/Inspector.json")
42
43 jsmodule_name_prefix = "jsmodule_"
44 modules = [
45     {
46         "name": "common",
47         "dependencies": [],
48         "sources": [
49             "Color.js",
50             "DOMExtension.js",
51             "Object.js",
52             "ParsedURL.js",
53             "Progress.js",
54             "Settings.js",
55             "UIString.js",
56             "UserMetrics.js",
57             "utilities.js",
58         ]
59     },
60     {
61         "name": "sdk",
62         "dependencies": ["common"],
63         "sources": [
64             "ApplicationCacheModel.js",
65             "CompilerScriptMapping.js",
66             "ConsoleModel.js",
67             "ContentProvider.js",
68             "ContentProviders.js",
69             "CookieParser.js",
70             "CSSMetadata.js",
71             "CSSStyleModel.js",
72             "BreakpointManager.js",
73             "Database.js",
74             "DOMAgent.js",
75             "DOMStorage.js",
76             "DebuggerModel.js",
77             "DebuggerScriptMapping.js",
78             "FileManager.js",
79             "FileMapping.js",
80             "FileSystemMapping.js",
81             "FileSystemModel.js",
82             "FileSystemProjectDelegate.js",
83             "FileUtils.js",
84             "HAREntry.js",
85             "IndexedDBModel.js",
86             "InspectorBackend.js",
87             "IsolatedFileSystemManager.js",
88             "IsolatedFileSystem.js",
89             "Linkifier.js",
90             "NetworkLog.js",
91             "NetworkUISourceCodeProvider.js",
92             "PresentationConsoleMessageHelper.js",
93             "RuntimeModel.js",
94             "SASSSourceMapping.js",
95             "Script.js",
96             "ScriptFormatter.js",
97             "ScriptSnippetModel.js",
98             "SimpleWorkspaceProvider.js",
99             "SnippetStorage.js",
100             "SourceMapping.js",
101             "StylesSourceMapping.js",
102             "TimelineManager.js",
103             "RemoteObject.js",
104             "Resource.js",
105             "DefaultScriptMapping.js",
106             "ResourceScriptMapping.js",
107             "LiveEditSupport.js",
108             "ResourceTreeModel.js",
109             "ResourceType.js",
110             "ResourceUtils.js",
111             "SourceMap.js",
112             "NetworkManager.js",
113             "NetworkRequest.js",
114             "UISourceCode.js",
115             "UserAgentSupport.js",
116             "Workspace.js",
117             "protocol-externs.js",
118         ]
119     },
120     {
121         "name": "ui",
122         "dependencies": ["common"],
123         "sources": [
124             "Checkbox.js",
125             "ContextMenu.js",
126             "DOMSyntaxHighlighter.js",
127             "DataGrid.js",
128             "DefaultTextEditor.js",
129             "Dialog.js",
130             "DockController.js",
131             "Drawer.js",
132             "EmptyView.js",
133             "GoToLineDialog.js",
134             "HelpScreen.js",
135             "InspectorView.js",
136             "KeyboardShortcut.js",
137             "Panel.js",
138             "PanelEnablerView.js",
139             "Placard.js",
140             "Popover.js",
141             "ProgressIndicator.js",
142             "PropertiesSection.js",
143             "SearchController.js",
144             "Section.js",
145             "SidebarPane.js",
146             "SidebarTreeElement.js",
147             "ShortcutsScreen.js",
148             "ShowMoreDataGridNode.js",
149             "SidebarOverlay.js",
150             "SoftContextMenu.js",
151             "SourceTokenizer.js",
152             "Spectrum.js",
153             "SplitView.js",
154             "SidebarView.js",
155             "StatusBarButton.js",
156             "SuggestBox.js",
157             "TabbedPane.js",
158             "TextEditor.js",
159             "TextEditorHighlighter.js",
160             "TextEditorModel.js",
161             "TextPrompt.js",
162             "TextUtils.js",
163             "TimelineGrid.js",
164             "Toolbar.js",
165             "UIUtils.js",
166             "View.js",
167             "ViewportControl.js",
168             "treeoutline.js",
169         ]
170     },
171     {
172         "name": "components",
173         "dependencies": ["sdk", "ui"],
174         "sources": [
175             "AdvancedSearchController.js",
176             "HandlerRegistry.js",
177             "ConsoleMessage.js",
178             "CookiesTable.js",
179             "DOMBreakpointsSidebarPane.js",
180             "DOMPresentationUtils.js",
181             "ElementsTreeOutline.js",
182             "FontView.js",
183             "ImageView.js",
184             "NativeBreakpointsSidebarPane.js",
185             "ObjectPopoverHelper.js",
186             "ObjectPropertiesSection.js",
187             "SourceFrame.js",
188             "ResourceView.js",
189         ]
190     },
191     {
192         "name": "elements",
193         "dependencies": ["components"],
194         "sources": [
195             "CSSNamedFlowCollectionsView.js",
196             "CSSNamedFlowView.js",
197             "ElementsPanel.js",
198             "ElementsPanelDescriptor.js",
199             "EventListenersSidebarPane.js",
200             "MetricsSidebarPane.js",
201             "PropertiesSidebarPane.js",
202             "StylesSidebarPane.js",
203         ]
204     },
205     {
206         "name": "network",
207         "dependencies": ["components"],
208         "sources": [
209             "NetworkItemView.js",
210             "RequestCookiesView.js",
211             "RequestHeadersView.js",
212             "RequestHTMLView.js",
213             "RequestJSONView.js",
214             "RequestPreviewView.js",
215             "RequestResponseView.js",
216             "RequestTimingView.js",
217             "RequestView.js",
218             "ResourceWebSocketFrameView.js",
219             "NetworkPanel.js",
220             "NetworkPanelDescriptor.js",
221         ]
222     },
223     {
224         "name": "resources",
225         "dependencies": ["components"],
226         "sources": [
227             "ApplicationCacheItemsView.js",
228             "CookieItemsView.js",
229             "DatabaseQueryView.js",
230             "DatabaseTableView.js",
231             "DirectoryContentView.js",
232             "DOMStorageItemsView.js",
233             "FileContentView.js",
234             "FileSystemView.js",
235             "IndexedDBViews.js",
236             "ResourcesPanel.js",
237         ]
238     },
239     {
240         "name": "workers",
241         "dependencies": ["components"],
242         "sources": [
243             "WorkerManager.js",
244         ]
245     },
246     {
247         "name": "scripts",
248         "dependencies": ["components", "workers"],
249         "sources": [
250             "BreakpointsSidebarPane.js",
251             "CallStackSidebarPane.js",
252             "FilteredItemSelectionDialog.js",
253             "JavaScriptSourceFrame.js",
254             "NavigatorOverlayController.js",
255             "NavigatorView.js",
256             "RevisionHistoryView.js",
257             "ScopeChainSidebarPane.js",
258             "ScriptsNavigator.js",
259             "ScriptsPanel.js",
260             "ScriptsPanelDescriptor.js",
261             "ScriptsSearchScope.js",
262             "SnippetJavaScriptSourceFrame.js",
263             "StyleSheetOutlineDialog.js",
264             "TabbedEditorContainer.js",
265             "UISourceCodeFrame.js",
266             "WatchExpressionsSidebarPane.js",
267             "WorkersSidebarPane.js",
268         ]
269     },
270     {
271         "name": "console",
272         "dependencies": ["components"],
273         "sources": [
274             "ConsoleView.js",
275             "ConsolePanel.js",
276         ]
277     },
278     {
279         "name": "timeline",
280         "dependencies": ["components"],
281         "sources": [
282             "DOMCountersGraph.js",
283             "MemoryStatistics.js",
284             "NativeMemoryGraph.js",
285             "TimelineModel.js",
286             "TimelineOverviewPane.js",
287             "TimelinePanel.js",
288             "TimelinePanelDescriptor.js",
289             "TimelinePresentationModel.js",
290             "TimelineFrameController.js"
291         ]
292     },
293     {
294         "name": "audits",
295         "dependencies": ["components"],
296         "sources": [
297             "AuditCategories.js",
298             "AuditController.js",
299             "AuditFormatters.js",
300             "AuditLauncherView.js",
301             "AuditResultView.js",
302             "AuditRules.js",
303             "AuditsPanel.js",
304         ]
305     },
306     {
307         "name": "extensions",
308         "dependencies": ["components"],
309         "sources": [
310             "ExtensionAPI.js",
311             "ExtensionAuditCategory.js",
312             "ExtensionPanel.js",
313             "ExtensionRegistryStub.js",
314             "ExtensionServer.js",
315             "ExtensionView.js",
316         ]
317     },
318     {
319         "name": "settings",
320         "dependencies": ["components", "extensions"],
321         "sources": [
322             "SettingsScreen.js",
323             "OverridesView.js",
324         ]
325     },
326     {
327         "name": "tests",
328         "dependencies": ["components"],
329         "sources": [
330             "TestController.js",
331         ]
332     },
333     {
334         "name": "profiler",
335         "dependencies": ["components", "workers"],
336         "sources": [
337             "BottomUpProfileDataGridTree.js",
338             "CPUProfileView.js",
339             "CSSSelectorProfileView.js",
340             "FlameChart.js",
341             "HeapSnapshot.js",
342             "HeapSnapshotDataGrids.js",
343             "HeapSnapshotGridNodes.js",
344             "HeapSnapshotLoader.js",
345             "HeapSnapshotProxy.js",
346             "HeapSnapshotView.js",
347             "HeapSnapshotWorker.js",
348             "HeapSnapshotWorkerDispatcher.js",
349             "JSHeapSnapshot.js",
350             "NativeHeapSnapshot.js",
351             "NativeMemorySnapshotView.js",
352             "ProfileDataGridTree.js",
353             "ProfilesPanel.js",
354             "ProfilesPanelDescriptor.js",
355             "ProfileLauncherView.js",
356             "TopDownProfileDataGridTree.js",
357             "CanvasProfileView.js",
358         ]
359     },
360     {
361         "name": "host_stub",
362         "dependencies": ["components", "profiler", "timeline"],
363         "sources": [
364             "InspectorFrontendAPI.js",
365             "InspectorFrontendHostStub.js",
366         ]
367     }
368 ]
369
370 modules_by_name = {}
371 for module in modules:
372     modules_by_name[module["name"]] = module
373
374
375 def dump_module(name, recursively, processed_modules):
376     if name in processed_modules:
377         return ""
378     processed_modules[name] = True
379     module = modules_by_name[name]
380     command = ""
381     if recursively:
382         for dependency in module["dependencies"]:
383             command += dump_module(dependency, recursively, processed_modules)
384     command += " \\\n    --module " + jsmodule_name_prefix + module["name"] + ":"
385     command += str(len(module["sources"]))
386     firstDependency = True
387     for dependency in module["dependencies"]:
388         if firstDependency:
389             command += ":"
390         else:
391             command += ","
392         firstDependency = False
393         command += jsmodule_name_prefix + dependency
394     for script in module["sources"]:
395         command += " \\\n        --js " + inspector_frontend_path + "/" + script
396     return command
397
398 modules_dir = tempfile.mkdtemp()
399 compiler_command = "java -jar ~/closure/compiler.jar --summary_detail_level 3 --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keyword --module_output_path_prefix %s/ \\\n" % modules_dir
400
401 process_recursively = len(sys.argv) > 1
402 if process_recursively:
403     module_name = sys.argv[1]
404     if module_name != "all":
405         modules = []
406         for i in range(1, len(sys.argv)):
407             modules.append(modules_by_name[sys.argv[i]])
408     for module in modules:
409         command = compiler_command
410         command += "    --externs " + inspector_frontend_path + "/externs.js"
411         command += dump_module(module["name"], True, {})
412         print "Compiling \"" + module["name"] + "\""
413         os.system(command)
414 else:
415     command = compiler_command
416     command += "    --externs " + inspector_frontend_path + "/externs.js"
417     for module in modules:
418         command += dump_module(module["name"], False, {})
419     os.system(command)
420
421 if not process_recursively:
422     print "Compiling InjectedScriptSource.js..."
423     os.system("echo \"var injectedScriptValue = \" > " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
424     os.system("cat  " + inspector_path + "/" + "InjectedScriptSource.js" + " >> " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
425     command = compiler_command
426     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
427     command += "    --externs " + protocol_externs_path + " \\\n"
428     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
429     command += "        --js " + inspector_path + "/" + "InjectedScriptSourceTmp.js" + " \\\n"
430     command += "\n"
431     os.system(command)
432     os.system("rm " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
433
434     print "Compiling InjectedScriptCanvasModuleSource.js..."
435     os.system("echo \"var injectedScriptCanvasModuleValue = \" > " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
436     os.system("cat  " + inspector_path + "/" + "InjectedScriptCanvasModuleSource.js" + " >> " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
437     command = compiler_command
438     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
439     command += "    --externs " + protocol_externs_path + " \\\n"
440     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
441     command += "        --js " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js" + " \\\n"
442     command += "\n"
443     os.system(command)
444     os.system("rm " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
445
446 shutil.rmtree(modules_dir)
447 #os.system("rm " + protocol_externs_path)