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

Side by Side Diff: pkg/front_end/lib/dependency_grapher.dart

Issue 2572383004: Add preliminary packages file support to dependency_grapher. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/error/listener.dart'; 8 import 'package:analyzer/error/listener.dart';
9 import 'package:analyzer/src/dart/scanner/reader.dart'; 9 import 'package:analyzer/src/dart/scanner/reader.dart';
10 import 'package:analyzer/src/generated/parser.dart'; 10 import 'package:analyzer/src/generated/parser.dart';
11 import 'package:front_end/file_system.dart'; 11 import 'package:front_end/file_system.dart';
12 import 'package:front_end/src/async_dependency_walker.dart'; 12 import 'package:front_end/src/async_dependency_walker.dart';
13 import 'package:front_end/src/base/uri_resolver.dart'; 13 import 'package:front_end/src/base/uri_resolver.dart';
14 import 'package:front_end/src/scanner/scanner.dart'; 14 import 'package:front_end/src/scanner/scanner.dart';
15 import 'package:package_config/packages_file.dart' as package_config;
15 16
16 import 'compiler_options.dart'; 17 import 'compiler_options.dart';
17 18
18 /// Generates a representation of the dependency graph of a program. 19 /// Generates a representation of the dependency graph of a program.
19 /// 20 ///
20 /// Given the Uri of one or more files, this function follows `import`, 21 /// Given the Uri of one or more files, this function follows `import`,
21 /// `export`, and `part` declarations to discover a graph of all files involved 22 /// `export`, and `part` declarations to discover a graph of all files involved
22 /// in the program. 23 /// in the program.
23 Future<Graph> graphForProgram( 24 Future<Graph> graphForProgram(
24 List<Uri> sources, CompilerOptions options) async { 25 List<Uri> sources, CompilerOptions options) async {
25 var packages = <String, Uri>{}; // TODO(paulberry): support packages 26 Map<String, Uri> packages;
27 if (options.packagesFilePath == null) {
28 throw new UnimplementedError(); // TODO(paulberry): search for .packages
Siggi Cherem (dart-lang) 2016/12/16 16:30:38 mmm... I recognize the value of having an abstract
Paul Berry 2016/12/16 17:59:07 Acknowledged.
29 } else if (options.packagesFilePath.isEmpty) {
30 packages = {};
31 } else {
32 var contents = await options.fileSystem
33 .entityForPath(options.packagesFilePath)
34 .readAsBytes();
35 var baseLocation =
36 options.fileSystem.context.toUri(options.packagesFilePath);
37 packages = package_config.parse(contents, baseLocation);
38 }
26 var sdkLibraries = <String, Uri>{}; // TODO(paulberry): support SDK libraries 39 var sdkLibraries = <String, Uri>{}; // TODO(paulberry): support SDK libraries
27 var uriResolver = 40 var uriResolver =
28 new UriResolver(packages, sdkLibraries, options.fileSystem.context); 41 new UriResolver(packages, sdkLibraries, options.fileSystem.context);
29 var walker = new _Walker(options.fileSystem, uriResolver); 42 var walker = new _Walker(options.fileSystem, uriResolver);
30 var startingPoint = new _StartingPoint(walker, sources); 43 var startingPoint = new _StartingPoint(walker, sources);
31 await walker.walk(startingPoint); 44 await walker.walk(startingPoint);
32 return walker.graph; 45 return walker.graph;
33 } 46 }
34 47
35 /// A representation of the dependency graph of a program. 48 /// A representation of the dependency graph of a program.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 final LibraryNode library; 142 final LibraryNode library;
130 143
131 _WalkerNode(this.walker, Uri uri) 144 _WalkerNode(this.walker, Uri uri)
132 : uri = uri, 145 : uri = uri,
133 library = new LibraryNode._(uri); 146 library = new LibraryNode._(uri);
134 147
135 @override 148 @override
136 Future<List<_WalkerNode>> computeDependencies() async { 149 Future<List<_WalkerNode>> computeDependencies() async {
137 var dependencies = <_WalkerNode>[]; 150 var dependencies = <_WalkerNode>[];
138 // TODO(paulberry): add error recovery if the file can't be read. 151 // TODO(paulberry): add error recovery if the file can't be read.
139 var contents = await walker.fileSystem 152 var path = walker.uriResolver.resolve(uri);
140 .entityForPath(walker.uriResolver.resolve(uri)) 153 if (path == null) {
141 .readAsString(); 154 // TODO(paulberry): If an error reporter was provided, report the error
155 // in the proper way and continue.
156 throw new StateError('Invalid URI: $uri');
157 }
158 var contents = await walker.fileSystem.entityForPath(path).readAsString();
142 var scanner = new _Scanner(contents); 159 var scanner = new _Scanner(contents);
143 var token = scanner.tokenize(); 160 var token = scanner.tokenize();
144 // TODO(paulberry): report errors. 161 // TODO(paulberry): report errors.
145 var parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); 162 var parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER);
146 var unit = parser.parseDirectives(token); 163 var unit = parser.parseDirectives(token);
147 for (var directive in unit.directives) { 164 for (var directive in unit.directives) {
148 if (directive is UriBasedDirective) { 165 if (directive is UriBasedDirective) {
149 // TODO(paulberry): when we support SDK libraries, we'll need more 166 // TODO(paulberry): when we support SDK libraries, we'll need more
150 // complex logic here to find SDK parts correctly. 167 // complex logic here to find SDK parts correctly.
151 var referencedUri = uri.resolve(directive.uri.stringValue); 168 var referencedUri = uri.resolve(directive.uri.stringValue);
152 if (directive is PartDirective) { 169 if (directive is PartDirective) {
153 library.parts.add(referencedUri); 170 library.parts.add(referencedUri);
154 } else { 171 } else {
155 _WalkerNode dependencyNode = walker.nodeForUri(referencedUri); 172 _WalkerNode dependencyNode = walker.nodeForUri(referencedUri);
156 dependencies.add(dependencyNode); 173 dependencies.add(dependencyNode);
157 library.dependencies.add(dependencyNode.library); 174 library.dependencies.add(dependencyNode.library);
158 } 175 }
159 } 176 }
160 } 177 }
161 return dependencies; 178 return dependencies;
162 } 179 }
163 } 180 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/compiler_options.dart ('k') | pkg/front_end/test/dependency_grapher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698