compile-front-end.py 15 KB

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