Not reviewed. Added svn:eol-style native to unbreak some build bots.
[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             "ElementsPanel.js",
184             "ElementsPanelDescriptor.js",
185             "EventListenersSidebarPane.js",
186             "MetricsSidebarPane.js",
187             "PropertiesSidebarPane.js",
188             "StylesSidebarPane.js",
189         ]
190     },
191     {
192         "name": "network",
193         "dependencies": ["components"],
194         "sources": [
195             "NetworkItemView.js",
196             "RequestCookiesView.js",
197             "RequestHeadersView.js",
198             "RequestHTMLView.js",
199             "RequestJSONView.js",
200             "RequestPreviewView.js",
201             "RequestResponseView.js",
202             "RequestTimingView.js",
203             "RequestView.js",
204             "ResourceWebSocketFrameView.js",
205             "NetworkPanel.js",
206             "NetworkPanelDescriptor.js",
207         ]
208     },
209     {
210         "name": "resources",
211         "dependencies": ["components"],
212         "sources": [
213             "ApplicationCacheItemsView.js",
214             "CookieItemsView.js",
215             "DatabaseQueryView.js",
216             "DatabaseTableView.js",
217             "DirectoryContentView.js",
218             "DOMStorageItemsView.js",
219             "FileContentView.js",
220             "FileSystemView.js",
221             "IndexedDBViews.js",
222             "ResourcesPanel.js",
223         ]
224     },
225     {
226         "name": "scripts",
227         "dependencies": ["components"],
228         "sources": [
229             "BreakpointsSidebarPane.js",
230             "CallStackSidebarPane.js",
231             "FilteredItemSelectionDialog.js",
232             "JavaScriptSourceFrame.js",
233             "NavigatorOverlayController.js",
234             "NavigatorView.js",
235             "RevisionHistoryView.js",
236             "ScopeChainSidebarPane.js",
237             "ScriptsNavigator.js",
238             "ScriptsPanel.js",
239             "ScriptsPanelDescriptor.js",
240             "ScriptsSearchScope.js",
241             "SnippetJavaScriptSourceFrame.js",
242             "StyleSheetOutlineDialog.js",
243             "TabbedEditorContainer.js",
244             "UISourceCodeFrame.js",
245             "WatchExpressionsSidebarPane.js",
246             "WorkersSidebarPane.js",
247         ]
248     },
249     {
250         "name": "console",
251         "dependencies": ["components"],
252         "sources": [
253             "ConsoleView.js",
254             "ConsolePanel.js",
255         ]
256     },
257     {
258         "name": "timeline",
259         "dependencies": ["components"],
260         "sources": [
261             "MemoryStatistics.js",
262             "TimelineModel.js",
263             "TimelineOverviewPane.js",
264             "TimelinePanel.js",
265             "TimelinePresentationModel.js",
266             "TimelineFrameController.js"
267         ]
268     },
269     {
270         "name": "audits",
271         "dependencies": ["components"],
272         "sources": [
273             "AuditCategories.js",
274             "AuditFormatters.js",
275             "AuditLauncherView.js",
276             "AuditResultView.js",
277             "AuditRules.js",
278             "AuditsPanel.js",
279         ]
280     },
281     {
282         "name": "extensions",
283         "dependencies": ["components"],
284         "sources": [
285             "ExtensionAPI.js",
286             "ExtensionAuditCategory.js",
287             "ExtensionPanel.js",
288             "ExtensionRegistryStub.js",
289             "ExtensionServer.js",
290             "ExtensionView.js",
291         ]
292     },
293     {
294         "name": "settings",
295         "dependencies": ["components", "extensions"],
296         "sources": [
297             "SettingsScreen.js",
298         ]
299     },
300     {
301         "name": "workers",
302         "dependencies": ["components"],
303         "sources": [
304             "WorkerManager.js",
305         ]
306     },
307     {
308         "name": "tests",
309         "dependencies": ["components"],
310         "sources": [
311             "TestController.js",
312         ]
313     },
314     {
315         "name": "profiler",
316         "dependencies": ["components"],
317         "sources": [
318             "BottomUpProfileDataGridTree.js",
319             "CPUProfileView.js",
320             "CSSSelectorProfileView.js",
321             "HeapSnapshot.js",
322             "HeapSnapshotDataGrids.js",
323             "HeapSnapshotGridNodes.js",
324             "HeapSnapshotLoader.js",
325             "HeapSnapshotProxy.js",
326             "HeapSnapshotView.js",
327             "HeapSnapshotWorker.js",
328             "HeapSnapshotWorkerDispatcher.js",
329             "NativeMemorySnapshotView.js",
330             "ProfileDataGridTree.js",
331             "ProfilesPanel.js",
332             "ProfileLauncherView.js",
333             "TopDownProfileDataGridTree.js",
334             "WebGLProfileView.js",
335         ]
336     },
337     {
338         "name": "host_stub",
339         "dependencies": ["ui"],
340         "sources": [
341             "InspectorFrontendHostStub.js",
342         ]
343     },
344 ]
345
346 modules_by_name = {}
347 for module in modules:
348     modules_by_name[module["name"]] = module
349
350
351 def dump_module(name, recursively, processed_modules):
352     if name in processed_modules:
353         return ""
354     processed_modules[name] = True
355     module = modules_by_name[name]
356     command = ""
357     if recursively:
358         for dependency in module["dependencies"]:
359             command += dump_module(dependency, recursively, processed_modules)
360     command += " \\\n    --module " + jsmodule_name_prefix + module["name"] + ":"
361     command += str(len(module["sources"]))
362     firstDependency = True
363     for dependency in module["dependencies"]:
364         if firstDependency:
365             command += ":"
366         else:
367             command += ","
368         firstDependency = False
369         command += jsmodule_name_prefix + dependency
370     for script in module["sources"]:
371         command += " \\\n        --js " + inspector_frontend_path + "/" + script
372     return command
373
374 modules_dir = tempfile.mkdtemp()
375 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
376
377 process_recursively = len(sys.argv) > 1
378 if process_recursively:
379     module_name = sys.argv[1]
380     if module_name != "all":
381         modules = []
382         for i in range(1, len(sys.argv)):
383             modules.append(modules_by_name[sys.argv[i]])
384     for module in modules:
385         command = compiler_command
386         command += "    --externs " + inspector_frontend_path + "/externs.js"
387         command += dump_module(module["name"], True, {})
388         print "Compiling \"" + module["name"] + "\""
389         os.system(command)
390 else:
391     command = compiler_command
392     command += "    --externs " + inspector_frontend_path + "/externs.js"
393     for module in modules:
394         command += dump_module(module["name"], False, {})
395     os.system(command)
396
397 if not process_recursively:
398     print "Compiling InjectedScriptSource.js..."
399     os.system("echo \"var injectedScriptValue = \" > " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
400     os.system("cat  " + inspector_path + "/" + "InjectedScriptSource.js" + " >> " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
401     command = compiler_command
402     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
403     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
404     command += "        --js " + inspector_path + "/" + "InjectedScriptSourceTmp.js" + " \\\n"
405     command += "\n"
406     os.system(command)
407     os.system("rm " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
408
409     print "Compiling InjectedScriptWebGLModuleSource.js..."
410     os.system("echo \"var injectedScriptWebGLModuleValue = \" > " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
411     os.system("cat  " + inspector_path + "/" + "InjectedScriptWebGLModuleSource.js" + " >> " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
412     command = compiler_command
413     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
414     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
415     command += "        --js " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js" + " \\\n"
416     command += "\n"
417     os.system(command)
418     os.system("rm " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
419
420 shutil.rmtree(modules_dir)