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