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

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 19695013: "Reverting 25378" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/docgen/test/single_library_test.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 * **docgen** is a tool for creating machine readable representations of Dart 6 * **docgen** is a tool for creating machine readable representations of Dart
7 * code metadata, including: classes, members, comments and annotations. 7 * code metadata, including: classes, members, comments and annotations.
8 * 8 *
9 * docgen is run on a `.dart` file or a directory containing `.dart` files. 9 * docgen is run on a `.dart` file or a directory containing `.dart` files.
10 * 10 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (FileSystemEntity.typeSync(files.first) 76 if (FileSystemEntity.typeSync(files.first)
77 == FileSystemEntityType.DIRECTORY) { 77 == FileSystemEntityType.DIRECTORY) {
78 packageRoot = _findPackageRoot(files.first); 78 packageRoot = _findPackageRoot(files.first);
79 } 79 }
80 } 80 }
81 logger.info('Package Root: ${packageRoot}'); 81 logger.info('Package Root: ${packageRoot}');
82 82
83 linkResolver = (name) => 83 linkResolver = (name) =>
84 fixReference(name, _currentLibrary, _currentClass, _currentMember); 84 fixReference(name, _currentLibrary, _currentClass, _currentMember);
85 85
86 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) 86 return getMirrorSystem(files, packageRoot, parseSdk: parseSdk)
87 .then((MirrorSystem mirrorSystem) { 87 .then((MirrorSystem mirrorSystem) {
88 if (mirrorSystem.libraries.isEmpty) { 88 if (mirrorSystem.libraries.isEmpty) {
89 throw new StateError('No library mirrors were created.'); 89 throw new StateError('No library mirrors were created.');
90 } 90 }
91 _documentLibraries(mirrorSystem.libraries.values, 91 _documentLibraries(mirrorSystem.libraries.values,
92 includeSdk: includeSdk, includePrivate: includePrivate, 92 includeSdk: includeSdk, includePrivate: includePrivate,
93 outputToYaml: outputToYaml); 93 outputToYaml: outputToYaml);
94 94
95 return true; 95 return true;
96 }); 96 });
(...skipping 15 matching lines...) Expand all
112 } 112 }
113 return libraries; 113 return libraries;
114 } 114 }
115 115
116 List<String> _listDartFromDir(String args) { 116 List<String> _listDartFromDir(String args) {
117 var files = listDir(args, recursive: true); 117 var files = listDir(args, recursive: true);
118 // To avoid anaylzing package files twice, only files with paths not 118 // To avoid anaylzing package files twice, only files with paths not
119 // containing '/packages' will be added. The only exception is if the file to 119 // containing '/packages' will be added. The only exception is if the file to
120 // analyze already has a '/package' in its path. 120 // analyze already has a '/package' in its path.
121 return files.where((f) => f.endsWith('.dart') && 121 return files.where((f) => f.endsWith('.dart') &&
122 (!f.contains('${path.separator}packages') || 122 (!f.contains('/packages') || args.contains('/packages'))).toList()
123 args.contains('${path.separator}packages'))).toList()
124 ..forEach((lib) => logger.info('Added to libraries: $lib')); 123 ..forEach((lib) => logger.info('Added to libraries: $lib'));
125 } 124 }
126 125
127 String _findPackageRoot(String directory) { 126 String _findPackageRoot(String directory) {
128 var files = listDir(directory, recursive: true); 127 var files = listDir(directory, recursive: true);
129 // Return '' means that there was no pubspec.yaml and therefor no packageRoot. 128 // Return '' means that there was no pubspec.yaml and therefor no packageRoot.
130 String packageRoot = files.firstWhere((f) => 129 String packageRoot = files.firstWhere((f) =>
131 f.endsWith('${path.separator}pubspec.yaml'), orElse: () => ''); 130 f.endsWith('/pubspec.yaml'), orElse: () => '');
132 if (packageRoot != '') { 131 if (packageRoot != '') {
133 packageRoot = path.join(path.dirname(packageRoot), 'packages'); 132 packageRoot = path.dirname(packageRoot) + '/packages';
134 } 133 }
135 return packageRoot; 134 return packageRoot;
136 } 135 }
137 136
138 List<String> _listSdk() { 137 List<String> _listSdk() {
139 var sdk = new List<String>(); 138 var sdk = new List<String>();
140 LIBRARIES.forEach((String name, LibraryInfo info) { 139 LIBRARIES.forEach((String name, LibraryInfo info) {
141 if (info.documented) { 140 if (info.documented) {
142 sdk.add('dart:$name'); 141 sdk.add('dart:$name');
143 logger.info('Add to SDK: ${sdk.last}'); 142 logger.info('Add to SDK: ${sdk.last}');
144 } 143 }
145 }); 144 });
146 return sdk; 145 return sdk;
147 } 146 }
148 147
149 /** 148 /**
150 * Analyzes set of libraries by getting a mirror system and triggers the 149 * Analyzes set of libraries by getting a mirror system and triggers the
151 * documentation of the libraries. 150 * documentation of the libraries.
152 */ 151 */
153 Future<MirrorSystem> getMirrorSystem(List<String> args, {String packageRoot, 152 Future<MirrorSystem> getMirrorSystem(List<String> args, String packageRoot,
154 bool parseSdk:false}) { 153 {bool parseSdk:false}) {
155 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); 154 var libraries = !parseSdk ? _listLibraries(args) : _listSdk();
156 if (libraries.isEmpty) throw new StateError('No Libraries.'); 155 if (libraries.isEmpty) throw new StateError('No Libraries.');
157 // DART_SDK should be set to the root of the SDK library. 156 // DART_SDK should be set to the root of the SDK library.
158 var sdkRoot = Platform.environment['DART_SDK']; 157 var sdkRoot = Platform.environment['DART_SDK'];
159 if (sdkRoot != null) { 158 if (sdkRoot != null) {
160 logger.info('Using DART_SDK to find SDK at $sdkRoot'); 159 logger.info('Using DART_SDK to find SDK at $sdkRoot');
161 } else { 160 } else {
162 // If DART_SDK is not defined in the environment, 161 // If DART_SDK is not defined in the environment,
163 // assuming the dart executable is from the Dart SDK folder inside bin. 162 // assuming the dart executable is from the Dart SDK folder inside bin.
164 sdkRoot = path.join(path.dirname(path.dirname(path.dirname(path.dirname( 163 sdkRoot = path.dirname(path.dirname(new Options().executable));
165 path.absolute(new Options().script))))), 'sdk');
166 logger.info('SDK Root: ${sdkRoot}'); 164 logger.info('SDK Root: ${sdkRoot}');
167 } 165 }
166
168 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); 167 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot);
169 } 168 }
170 169
171 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly 170 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly
172 // error message letting them know why it is failing to create a mirror system. 171 // error message letting them know why it is failing to create a mirror system.
173 // If there is conflicting library names, should modify it with a hash at the 172 // If there is conflicting library names, should modify it with a hash at the
174 // end of it's library name. 173 // end of it's library name.
175 /** 174 /**
176 * Analyzes set of libraries and provides a mirror system which can be used 175 * Analyzes set of libraries and provides a mirror system which can be used
177 * for static inspection of the source code. 176 * for static inspection of the source code.
178 */ 177 */
179 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, 178 Future<MirrorSystem> _analyzeLibraries(List<String> libraries,
180 String libraryRoot, {String packageRoot}) { 179 String libraryRoot, {String packageRoot}) {
181 SourceFileProvider provider = new SourceFileProvider(); 180 SourceFileProvider provider = new SourceFileProvider();
182 api.DiagnosticHandler diagnosticHandler = 181 api.DiagnosticHandler diagnosticHandler =
183 new FormattingDiagnosticHandler(provider).diagnosticHandler; 182 new FormattingDiagnosticHandler(provider).diagnosticHandler;
184 Uri libraryUri = new Uri(scheme: 'file', path: appendSlash(libraryRoot)); 183 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot'));
185 Uri packageUri = null; 184 Uri packageUri = null;
186 if (packageRoot != null) { 185 if (packageRoot != null) {
187 packageUri = new Uri(scheme: 'file', path: appendSlash(packageRoot)); 186 packageUri = currentDirectory.resolve(appendSlash('$packageRoot'));
188 } 187 }
189 List<Uri> librariesUri = <Uri>[]; 188 List<Uri> librariesUri = <Uri>[];
190 libraries.forEach((library) { 189 libraries.forEach((library) {
191 librariesUri.add(currentDirectory.resolve(library)); 190 librariesUri.add(currentDirectory.resolve(library));
192 }); 191 });
193 return dart2js.analyze(librariesUri, libraryUri, packageUri, 192 return dart2js.analyze(librariesUri, libraryUri, packageUri,
194 provider.readStringFromUri, diagnosticHandler, 193 provider.readStringFromUri, diagnosticHandler,
195 ['--preserve-comments', '--categories=Client,Server']) 194 ['--preserve-comments', '--categories=Client,Server'])
196 ..catchError((error) { 195 ..catchError((error) {
197 logger.severe('Error: Failed to create mirror system. '); 196 logger.severe('Error: Failed to create mirror system. ');
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 String name; 670 String name;
672 String type; 671 String type;
673 672
674 Generic(this.name, this.type); 673 Generic(this.name, this.type);
675 674
676 Map toMap() => { 675 Map toMap() => {
677 'name': name, 676 'name': name,
678 'type': type 677 'type': type
679 }; 678 };
680 } 679 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/test/single_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698