Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: pkg/analyzer/tool/task_dependency_graph/generate.dart

Issue 1817913002: Generate the task model graph as an HTML file and put it in the doc directory. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Copy support files into local directory Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/doc/tasks.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This file contains code to output a description of tasks and their 6 * This file contains code to output a description of tasks and their
7 * dependencies in ".dot" format. Prior to running, the user should run "pub 7 * dependencies in ".dot" format. Prior to running, the user should run "pub
8 * get" in the analyzer directory to ensure that a "packages" folder exists. 8 * get" in the analyzer directory to ensure that a "packages" folder exists.
9 * 9 *
10 * TODO(paulberry): 10 * TODO(paulberry):
(...skipping 24 matching lines...) Expand all
35 import 'package:analyzer/src/generated/source_io.dart'; 35 import 'package:analyzer/src/generated/source_io.dart';
36 import 'package:path/path.dart' as path; 36 import 'package:path/path.dart' as path;
37 import 'package:path/path.dart'; 37 import 'package:path/path.dart';
38 38
39 /** 39 /**
40 * Generate the target .dot file. 40 * Generate the target .dot file.
41 */ 41 */
42 main() { 42 main() {
43 String script = Platform.script.toFilePath(windows: Platform.isWindows); 43 String script = Platform.script.toFilePath(windows: Platform.isWindows);
44 String pkgPath = normalize(join(dirname(script), '..', '..')); 44 String pkgPath = normalize(join(dirname(script), '..', '..'));
45 GeneratedContent.generateAll(pkgPath, <GeneratedContent>[target]); 45 GeneratedContent.generateAll(pkgPath, <GeneratedContent>[target, htmlTarget]);
46 } 46 }
47 47
48 final GeneratedFile htmlTarget = new GeneratedFile(
49 'doc/tasks.html', (String pkgPath) => new Driver(pkgPath).generateHtml());
50
48 final GeneratedFile target = new GeneratedFile( 51 final GeneratedFile target = new GeneratedFile(
49 'tool/task_dependency_graph/tasks.dot', 52 'tool/task_dependency_graph/tasks.dot',
50 (String pkgPath) => new Driver(pkgPath).generateFileContents()); 53 (String pkgPath) => new Driver(pkgPath).generateFileContents());
51 54
52 typedef void GetterFinderCallback(PropertyAccessorElement element); 55 typedef void GetterFinderCallback(PropertyAccessorElement element);
53 56
54 class Driver { 57 class Driver {
58 static bool hasInitializedPlugins = false;
55 PhysicalResourceProvider resourceProvider; 59 PhysicalResourceProvider resourceProvider;
56 AnalysisContext context; 60 AnalysisContext context;
57 InterfaceType resultDescriptorType; 61 InterfaceType resultDescriptorType;
58 InterfaceType listOfResultDescriptorType; 62 InterfaceType listOfResultDescriptorType;
59 ClassElement enginePluginClass; 63 ClassElement enginePluginClass;
60 CompilationUnitElement taskUnitElement; 64 CompilationUnitElement taskUnitElement;
61 InterfaceType extensionPointIdType; 65 InterfaceType extensionPointIdType;
66
62 final String rootDir; 67 final String rootDir;
63 68
64 Driver(String pkgPath) : rootDir = new Directory(pkgPath).absolute.path; 69 Driver(String pkgPath) : rootDir = new Directory(pkgPath).absolute.path;
65 70
66 /** 71 /**
67 * Get an [io.File] object corresponding to the file in which the generated 72 * Get an [io.File] object corresponding to the file in which the generated
68 * graph should be output. 73 * graph should be output.
69 */ 74 */
70 io.File get file => new io.File( 75 io.File get file => new io.File(
71 path.join(rootDir, 'tool', 'task_dependency_graph', 'tasks.dot')); 76 path.join(rootDir, 'tool', 'task_dependency_graph', 'tasks.dot'));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 node.accept(new GetterFinder(resultDescriptorType, resultDescriptors.add)); 119 node.accept(new GetterFinder(resultDescriptorType, resultDescriptors.add));
115 for (PropertyAccessorElement resultDescriptor in resultDescriptors) { 120 for (PropertyAccessorElement resultDescriptor in resultDescriptors) {
116 callback(resultDescriptor.name); 121 callback(resultDescriptor.name);
117 } 122 }
118 } 123 }
119 124
120 /** 125 /**
121 * Generate the task dependency graph and return it as a [String]. 126 * Generate the task dependency graph and return it as a [String].
122 */ 127 */
123 String generateFileContents() { 128 String generateFileContents() {
124 AnalysisEngine.instance.processRequiredPlugins(); 129 return '''
130 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
131 // for details. All rights reserved. Use of this source code is governed by a
132 // BSD-style license that can be found in the LICENSE file.
133 //
134 // This file has been automatically generated. Please do not edit it manually.
135 // To regenerate the file, use the script
136 // "pkg/analyzer/tool/task_dependency_graph/generate.dart".
137 //
138 // To render this graph using Graphviz (www.graphviz.org) use the command:
139 // "dot tasks.dot -Tpdf -O".
140 digraph G {
141 ${generateGraphData()}
142 }
143 ''';
144 }
145
146 String generateGraphData() {
147 if (!hasInitializedPlugins) {
148 AnalysisEngine.instance.processRequiredPlugins();
149 hasInitializedPlugins = true;
150 }
125 List<String> lines = <String>[]; 151 List<String> lines = <String>[];
126 resourceProvider = PhysicalResourceProvider.INSTANCE; 152 resourceProvider = PhysicalResourceProvider.INSTANCE;
127 DartSdk sdk = DirectoryBasedDartSdk.defaultSdk; 153 DartSdk sdk = DirectoryBasedDartSdk.defaultSdk;
128 context = AnalysisEngine.instance.createAnalysisContext(); 154 context = AnalysisEngine.instance.createAnalysisContext();
129 String packageRootPath; 155 String packageRootPath;
130 if (Platform.packageRoot != null) { 156 if (Platform.packageRoot != null) {
131 packageRootPath = Uri.parse(Platform.packageRoot).toFilePath(); 157 packageRootPath = Uri.parse(Platform.packageRoot).toFilePath();
132 } else { 158 } else {
133 packageRootPath = path.join(rootDir, 'packages'); 159 packageRootPath = path.join(rootDir, 'packages');
134 } 160 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 TopLevelVariableElement extensionIdVariable = _getExtensionId(resultList); 216 TopLevelVariableElement extensionIdVariable = _getExtensionId(resultList);
191 findExtensions(enginePluginAst, extensionIdVariable, (String extension) { 217 findExtensions(enginePluginAst, extensionIdVariable, (String extension) {
192 results.add(extension); 218 results.add(extension);
193 lines.add(' $extension -> $resultList'); 219 lines.add(' $extension -> $resultList');
194 }); 220 });
195 } 221 }
196 for (String result in results) { 222 for (String result in results) {
197 lines.add(' $result [shape=box]'); 223 lines.add(' $result [shape=box]');
198 } 224 }
199 lines.sort(); 225 lines.sort();
226 return lines.join('\n');
227 }
228
229 String generateHtml() {
200 return ''' 230 return '''
201 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 231 <!DOCTYPE html>
202 // for details. All rights reserved. Use of this source code is governed by a 232 <html>
203 // BSD-style license that can be found in the LICENSE file. 233 <head>
204 // 234 <title>Analysis Task Dependency Graph</title>
205 // This file has been automatically generated. Please do not edit it manually. 235 <link rel="stylesheet" href="support/style.css">
206 // To regenerate the file, use the script 236 <script src="support/viz.js"></script>
207 // "pkg/analyzer/tool/task_dependency_graph/generate.dart". 237 <script type="application/dart" src="support/web_app.dart.js"></script>
208 // 238 <script src="support/dart.js"></script>
209 // To render this graph using Graphviz (www.graphviz.org) use the command: 239 </head>
210 // "dot tasks.dot -Tpdf -O". 240 <body>
241 <button id="zoomBtn">Zoom</button>
242 <script type="text/vnd.graphviz" id="dot">
211 digraph G { 243 digraph G {
212 ${lines.join('\n')} 244 tooltip="Analysis Task Dependency Graph";
245 node [fontname=Helvetica];
246 edge [fontname=Helvetica, fontcolor=gray];
247 ${generateGraphData()}
213 } 248 }
249 </script>
250 </body>
251 </html>
214 '''; 252 ''';
215 } 253 }
216 254
217 CompilationUnit getUnit(Source source) => 255 CompilationUnit getUnit(Source source) =>
218 context.resolveCompilationUnit2(source, source); 256 context.resolveCompilationUnit2(source, source);
219 257
220 Source setupSource(String filename) { 258 Source setupSource(String filename) {
221 String filePath = path.join(rootDir, filename); 259 String filePath = path.join(rootDir, filename);
222 File file = resourceProvider.getResource(filePath); 260 File file = resourceProvider.getResource(filePath);
223 Source source = file.createSource(); 261 Source source = file.createSource();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 @override 349 @override
312 visitIdentifier(Identifier node) { 350 visitIdentifier(Identifier node) {
313 Element element = node.staticElement; 351 Element element = node.staticElement;
314 if (element is PropertyAccessorElement && 352 if (element is PropertyAccessorElement &&
315 element.isGetter && 353 element.isGetter &&
316 element.returnType.isSubtypeOf(type)) { 354 element.returnType.isSubtypeOf(type)) {
317 callback(element); 355 callback(element);
318 } 356 }
319 } 357 }
320 } 358 }
OLDNEW
« no previous file with comments | « pkg/analyzer/doc/tasks.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698