Web Inspector: Display Named Flows in the Tabbed Pane of the "CSS Named Flows" Drawer
[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
40 generate_protocol_externs.generate_protocol_externs(inspector_frontend_path + "/protocol-externs.js", inspector_path + "/Inspector.json")
41
42 jsmodule_name_prefix = "jsmodule_"
43 modules = [
44     {
45         "name": "common",
46         "dependencies": [],
47         "sources": [
48             "Color.js",
49             "Object.js",
50             "ParsedURL.js",
51             "Settings.js",
52             "UIString.js",
53             "UserMetrics.js",
54             "utilities.js",
55         ]
56     },
57     {
58         "name": "sdk",
59         "dependencies": ["common"],
60         "sources": [
61             "ApplicationCacheModel.js",
62             "CompilerScriptMapping.js",
63             "ConsoleModel.js",
64             "ContentProvider.js",
65             "ContentProviders.js",
66             "CookieParser.js",
67             "CSSCompletions.js",
68             "CSSKeywordCompletions.js",
69             "CSSStyleModel.js",
70             "BreakpointManager.js",
71             "Database.js",
72             "DOMAgent.js",
73             "DOMStorage.js",
74             "DebuggerModel.js",
75             "DebuggerScriptMapping.js",
76             "FileManager.js",
77             "FileSystemModel.js",
78             "FileUtils.js",
79             "HAREntry.js",
80             "IndexedDBModel.js",
81             "InspectorBackend.js",
82             "JavaScriptSource.js",
83             "Linkifier.js",
84             "NetworkLog.js",
85             "NetworkUISourceCodeProvider.js",
86             "PresentationConsoleMessageHelper.js",
87             "SASSSourceMapping.js",
88             "Script.js",
89             "ScriptFormatter.js",
90             "ScriptSnippetModel.js",
91             "SnippetStorage.js",
92             "SourceMapping.js",
93             "StyleSource.js",
94             "StylesSourceMapping.js",
95             "TimelineManager.js",
96             "RemoteObject.js",
97             "Resource.js",
98             "ResourceScriptMapping.js",
99             "ResourceTreeModel.js",
100             "ResourceType.js",
101             "ResourceUtils.js",
102             "NetworkManager.js",
103             "NetworkRequest.js",
104             "UISourceCode.js",
105             "UserAgentSupport.js",
106             "Workspace.js",
107             "protocol-externs.js",
108         ]
109     },
110     {
111         "name": "ui",
112         "dependencies": ["common"],
113         "sources": [
114             "Checkbox.js",
115             "ContextMenu.js",
116             "DOMExtension.js",
117             "DOMSyntaxHighlighter.js",
118             "DataGrid.js",
119             "DefaultTextEditor.js",
120             "Dialog.js",
121             "Drawer.js",
122             "EmptyView.js",
123             "GoToLineDialog.js",
124             "HelpScreen.js",
125             "InspectorView.js",
126             "KeyboardShortcut.js",
127             "Panel.js",
128             "PanelEnablerView.js",
129             "Placard.js",
130             "Popover.js",
131             "ProgressBar.js",
132             "PropertiesSection.js",
133             "SearchController.js",
134             "Section.js",
135             "SidebarPane.js",
136             "SidebarTreeElement.js",
137             "ShortcutsScreen.js",
138             "ShowMoreDataGridNode.js",
139             "SidebarOverlay.js",
140             "SoftContextMenu.js",
141             "SourceTokenizer.js",
142             "Spectrum.js",
143             "SplitView.js",
144             "StatusBarButton.js",
145             "TabbedPane.js",
146             "TextEditor.js",
147             "TextEditorHighlighter.js",
148             "TextEditorModel.js",
149             "TextPrompt.js",
150             "TimelineGrid.js",
151             "Toolbar.js",
152             "UIUtils.js",
153             "View.js",
154             "treeoutline.js",
155         ]
156     },
157     {
158         "name": "components",
159         "dependencies": ["sdk", "ui"],
160         "sources": [
161             "AdvancedSearchController.js",
162             "HandlerRegistry.js",
163             "ConsoleMessage.js",
164             "CookiesTable.js",
165             "DOMBreakpointsSidebarPane.js",
166             "DOMPresentationUtils.js",
167             "ElementsTreeOutline.js",
168             "FontView.js",
169             "ImageView.js",
170             "NativeBreakpointsSidebarPane.js",
171             "ObjectPopoverHelper.js",
172             "ObjectPropertiesSection.js",
173             "RuntimeModel.js",
174             "SourceFrame.js",
175             "ResourceView.js",
176         ]
177     },
178     {
179         "name": "elements",
180         "dependencies": ["components"],
181         "sources": [
182             "CSSNamedFlowCollectionsView.js",
183             "CSSNamedFlowView.js",
184             "ElementsPanel.js",
185             "ElementsPanelDescriptor.js",
186             "EventListenersSidebarPane.js",
187             "MetricsSidebarPane.js",
188             "PropertiesSidebarPane.js",
189             "StylesSidebarPane.js",
190         ]
191     },
192     {
193         "name": "network",
194         "dependencies": ["components"],
195         "sources": [
196             "NetworkItemView.js",
197             "RequestCookiesView.js",
198             "RequestHeadersView.js",
199             "RequestHTMLView.js",
200             "RequestJSONView.js",
201             "RequestPreviewView.js",
202             "RequestResponseView.js",
203             "RequestTimingView.js",
204             "RequestView.js",
205             "ResourceWebSocketFrameView.js",
206             "NetworkPanel.js",
207             "NetworkPanelDescriptor.js",
208         ]
209     },
210     {
211         "name": "resources",
212         "dependencies": ["components"],
213         "sources": [
214             "ApplicationCacheItemsView.js",
215             "CookieItemsView.js",
216             "DatabaseQueryView.js",
217             "DatabaseTableView.js",
218             "DirectoryContentView.js",
219             "DOMStorageItemsView.js",
220             "FileContentView.js",
221             "FileSystemView.js",
222             "IndexedDBViews.js",
223             "ResourcesPanel.js",
224         ]
225     },
226     {
227         "name": "scripts",
228         "dependencies": ["components"],
229         "sources": [
230             "BreakpointsSidebarPane.js",
231             "CallStackSidebarPane.js",
232             "FilteredItemSelectionDialog.js",
233             "JavaScriptSourceFrame.js",
234             "NavigatorOverlayController.js",
235             "NavigatorView.js",
236             "RevisionHistoryView.js",
237             "ScopeChainSidebarPane.js",
238             "ScriptsNavigator.js",
239             "ScriptsPanel.js",
240             "ScriptsPanelDescriptor.js",
241             "ScriptsSearchScope.js",
242             "SnippetJavaScriptSourceFrame.js",
243             "StyleSheetOutlineDialog.js",
244             "TabbedEditorContainer.js",
245             "UISourceCodeFrame.js",
246             "WatchExpressionsSidebarPane.js",
247             "WorkersSidebarPane.js",
248         ]
249     },
250     {
251         "name": "console",
252         "dependencies": ["components"],
253         "sources": [
254             "ConsoleView.js",
255             "ConsolePanel.js",
256         ]
257     },
258     {
259         "name": "timeline",
260         "dependencies": ["components"],
261         "sources": [
262             "MemoryStatistics.js",
263             "TimelineModel.js",
264             "TimelineOverviewPane.js",
265             "TimelinePanel.js",
266             "TimelinePresentationModel.js",
267             "TimelineFrameController.js"
268         ]
269     },
270     {
271         "name": "audits",
272         "dependencies": ["components"],
273         "sources": [
274             "AuditCategories.js",
275             "AuditFormatters.js",
276             "AuditLauncherView.js",
277             "AuditResultView.js",
278             "AuditRules.js",
279             "AuditsPanel.js",
280         ]
281     },
282     {
283         "name": "extensions",
284         "dependencies": ["components"],
285         "sources": [
286             "ExtensionAPI.js",
287             "ExtensionAuditCategory.js",
288             "ExtensionPanel.js",
289             "ExtensionRegistryStub.js",
290             "ExtensionServer.js",
291             "ExtensionView.js",
292         ]
293     },
294     {
295         "name": "settings",
296         "dependencies": ["components", "extensions"],
297         "sources": [
298             "SettingsScreen.js",
299         ]
300     },
301     {
302         "name": "workers",
303         "dependencies": ["components"],
304         "sources": [
305             "WorkerManager.js",
306         ]
307     },
308     {
309         "name": "tests",
310         "dependencies": ["components"],
311         "sources": [
312             "TestController.js",
313         ]
314     },
315     {
316         "name": "profiler",
317         "dependencies": ["components"],
318         "sources": [
319             "BottomUpProfileDataGridTree.js",
320             "CPUProfileView.js",
321             "CSSSelectorProfileView.js",
322             "HeapSnapshot.js",
323             "HeapSnapshotDataGrids.js",
324             "HeapSnapshotGridNodes.js",
325             "HeapSnapshotLoader.js",
326             "HeapSnapshotProxy.js",
327             "HeapSnapshotView.js",
328             "HeapSnapshotWorker.js",
329             "HeapSnapshotWorkerDispatcher.js",
330             "NativeMemorySnapshotView.js",
331             "ProfileDataGridTree.js",
332             "ProfilesPanel.js",
333             "ProfileLauncherView.js",
334             "TopDownProfileDataGridTree.js",
335             "WebGLProfileView.js",
336         ]
337     },
338     {
339         "name": "host_stub",
340         "dependencies": ["ui"],
341         "sources": [
342             "InspectorFrontendHostStub.js",
343         ]
344     },
345 ]
346
347 modules_by_name = {}
348 for module in modules:
349     modules_by_name[module["name"]] = module
350
351
352 def dump_module(name, recursively, processed_modules):
353     if name in processed_modules:
354         return ""
355     processed_modules[name] = True
356     module = modules_by_name[name]
357     command = ""
358     if recursively:
359         for dependency in module["dependencies"]:
360             command += dump_module(dependency, recursively, processed_modules)
361     command += " \\\n    --module " + jsmodule_name_prefix + module["name"] + ":"
362     command += str(len(module["sources"]))
363     firstDependency = True
364     for dependency in module["dependencies"]:
365         if firstDependency:
366             command += ":"
367         else:
368             command += ","
369         firstDependency = False
370         command += jsmodule_name_prefix + dependency
371     for script in module["sources"]:
372         command += " \\\n        --js " + inspector_frontend_path + "/" + script
373     return command
374
375 modules_dir = tempfile.mkdtemp()
376 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
377
378 process_recursively = len(sys.argv) > 1
379 if process_recursively:
380     module_name = sys.argv[1]
381     if module_name != "all":
382         modules = []
383         for i in range(1, len(sys.argv)):
384             modules.append(modules_by_name[sys.argv[i]])
385     for module in modules:
386         command = compiler_command
387         command += "    --externs " + inspector_frontend_path + "/externs.js"
388         command += dump_module(module["name"], True, {})
389         print "Compiling \"" + module["name"] + "\""
390         os.system(command)
391 else:
392     command = compiler_command
393     command += "    --externs " + inspector_frontend_path + "/externs.js"
394     for module in modules:
395         command += dump_module(module["name"], False, {})
396     os.system(command)
397
398 if not process_recursively:
399     print "Compiling InjectedScriptSource.js..."
400     os.system("echo \"var injectedScriptValue = \" > " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
401     os.system("cat  " + inspector_path + "/" + "InjectedScriptSource.js" + " >> " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
402     command = compiler_command
403     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
404     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
405     command += "        --js " + inspector_path + "/" + "InjectedScriptSourceTmp.js" + " \\\n"
406     command += "\n"
407     os.system(command)
408     os.system("rm " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
409
410     print "Compiling InjectedScriptWebGLModuleSource.js..."
411     os.system("echo \"var injectedScriptWebGLModuleValue = \" > " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
412     os.system("cat  " + inspector_path + "/" + "InjectedScriptWebGLModuleSource.js" + " >> " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
413     command = compiler_command
414     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
415     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
416     command += "        --js " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js" + " \\\n"
417     command += "\n"
418     os.system(command)
419     os.system("rm " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
420
421 shutil.rmtree(modules_dir)