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

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

Issue 148893004: Docgen snapshot needs to use dart-sdk as its SDK root in a downloaded SDK (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also find the root directory more robustly, and tolerate not having MDN docs Created 6 years, 10 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 | 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) 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 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return result; 140 return result;
141 } 141 }
142 142
143 /// Analyzes set of libraries by getting a mirror system and triggers the 143 /// Analyzes set of libraries by getting a mirror system and triggers the
144 /// documentation of the libraries. 144 /// documentation of the libraries.
145 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, 145 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries,
146 {String packageRoot, bool parseSdk: false}) { 146 {String packageRoot, bool parseSdk: false}) {
147 if (libraries.isEmpty) throw new StateError('No Libraries.'); 147 if (libraries.isEmpty) throw new StateError('No Libraries.');
148 148
149 // Finds the root of SDK library based off the location of docgen. 149 // Finds the root of SDK library based off the location of docgen.
150 // We have two different places to look, depending if we're in a development
151 // repo or in a built SDK, either sdk or dart-sdk respectively
150 var root = _Generator._rootDirectory; 152 var root = _Generator._rootDirectory;
151 var sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk'))); 153 var sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk')));
154 if (!new Directory(sdkRoot).existsSync()) {
155 sdkRoot = path.normalize(path.absolute(path.join(root, 'dart-sdk')));
156 }
152 _Generator.logger.info('SDK Root: ${sdkRoot}'); 157 _Generator.logger.info('SDK Root: ${sdkRoot}');
153 return _Generator._analyzeLibraries(libraries, sdkRoot, 158 return _Generator._analyzeLibraries(libraries, sdkRoot,
154 packageRoot: packageRoot); 159 packageRoot: packageRoot);
155 } 160 }
156 161
157 /// For types that we do not explicitly create or have not yet created in our 162 /// For types that we do not explicitly create or have not yet created in our
158 /// entity map (like core types). 163 /// entity map (like core types).
159 class DummyMirror implements Indexable { 164 class DummyMirror implements Indexable {
160 DeclarationMirror mirror; 165 DeclarationMirror mirror;
161 /// The library that contains this element, if any. Used as a hint to help 166 /// The library that contains this element, if any. Used as a hint to help
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 /// available on the file system. 455 /// available on the file system.
451 static void _ensureOutputDirectory(String outputDirectory, bool append) { 456 static void _ensureOutputDirectory(String outputDirectory, bool append) {
452 _outputDirectory = outputDirectory; 457 _outputDirectory = outputDirectory;
453 if (!append) { 458 if (!append) {
454 var dir = new Directory(_outputDirectory); 459 var dir = new Directory(_outputDirectory);
455 if (dir.existsSync()) dir.deleteSync(recursive: true); 460 if (dir.existsSync()) dir.deleteSync(recursive: true);
456 } 461 }
457 } 462 }
458 463
459 /// Helper accessor to determine the full pathname of the root of the dart 464 /// Helper accessor to determine the full pathname of the root of the dart
460 /// checkout. 465 /// checkout. We can be in one of three situations:
466 /// 1) Running from pkg/docgen/bin/docgen.dart
467 /// 2) Running from a snapshot in a build,
468 /// e.g. xcodebuild/ReleaseIA32/dart-sdk/bin
469 /// 3) Running from a built distribution,
470 /// e.g. ...somename/dart-sdk/bin/snapshots
461 static String get _rootDirectory { 471 static String get _rootDirectory {
462 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath())); 472 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath()));
463 var root = scriptDir; 473 var root = scriptDir;
464 while(path.basename(root) != 'dart') { 474 var base = path.basename(root);
475 // When we find dart-sdk or sdk we are one level below the root.
476 while (base != 'dart-sdk' && base != 'sdk' && base != 'pkg') {
465 root = path.dirname(root); 477 root = path.dirname(root);
478 base = path.basename(root);
479 if (root == base) {
480 // We have reached the root of the filesystem without finding anything.
481 throw new FileSystemException(
482 "Cannot find SDK directory starting from ",
483 scriptDir);
484 }
466 } 485 }
467 return root; 486 return path.dirname(root);
468 } 487 }
469 488
470 /// Analyzes set of libraries and provides a mirror system which can be used 489 /// Analyzes set of libraries and provides a mirror system which can be used
471 /// for static inspection of the source code. 490 /// for static inspection of the source code.
472 static Future<MirrorSystem> _analyzeLibraries(List<Uri> libraries, 491 static Future<MirrorSystem> _analyzeLibraries(List<Uri> libraries,
473 String libraryRoot, {String packageRoot}) { 492 String libraryRoot, {String packageRoot}) {
474 SourceFileProvider provider = new CompilerSourceFileProvider(); 493 SourceFileProvider provider = new CompilerSourceFileProvider();
475 api.DiagnosticHandler diagnosticHandler = 494 api.DiagnosticHandler diagnosticHandler =
476 (new FormattingDiagnosticHandler(provider) 495 (new FormattingDiagnosticHandler(provider)
477 ..showHints = false 496 ..showHints = false
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 1532
1514 OwnedIndexable(DeclarationMirror mirror, this.owner) : super(mirror); 1533 OwnedIndexable(DeclarationMirror mirror, this.owner) : super(mirror);
1515 1534
1516 /// Generates MDN comments from database.json. 1535 /// Generates MDN comments from database.json.
1517 String _mdnComment() { 1536 String _mdnComment() {
1518 //Check if MDN is loaded. 1537 //Check if MDN is loaded.
1519 if (Indexable._mdn == null) { 1538 if (Indexable._mdn == null) {
1520 // Reading in MDN related json file. 1539 // Reading in MDN related json file.
1521 var root = _Generator._rootDirectory; 1540 var root = _Generator._rootDirectory;
1522 var mdnPath = path.join(root, 'utils/apidoc/mdn/database.json'); 1541 var mdnPath = path.join(root, 'utils/apidoc/mdn/database.json');
1523 Indexable._mdn = JSON.decode(new File(mdnPath).readAsStringSync()); 1542 var mdnFile = new File(mdnPath);
1543 if (mdnFile.existsSync()) {
1544 Indexable._mdn = JSON.decode(mdnFile.readAsStringSync());
1545 } else {
1546 _Generator.logger.warning("Cannot find MDN docs expected at $mdnPath");
1547 Indexable._mdn = {};
1548 }
1524 } 1549 }
1525 var domAnnotation = this.annotations.firstWhere( 1550 var domAnnotation = this.annotations.firstWhere(
1526 (e) => e.mirror.qualifiedName == 'metadata.DomName', 1551 (e) => e.mirror.qualifiedName == 'metadata.DomName',
1527 orElse: () => null); 1552 orElse: () => null);
1528 if (domAnnotation == null) return ''; 1553 if (domAnnotation == null) return '';
1529 var domName = domAnnotation.parameters.single; 1554 var domName = domAnnotation.parameters.single;
1530 var parts = domName.split('.'); 1555 var parts = domName.split('.');
1531 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); 1556 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]);
1532 if (parts.length == 1) return _mdnTypeComment(parts[0]); 1557 if (parts.length == 1) return _mdnTypeComment(parts[0]);
1533 } 1558 }
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 .map((e) => originalMirror.getField(e.simpleName).reflectee) 2164 .map((e) => originalMirror.getField(e.simpleName).reflectee)
2140 .where((e) => e != null) 2165 .where((e) => e != null)
2141 .toList(); 2166 .toList();
2142 } 2167 }
2143 2168
2144 Map toMap() => { 2169 Map toMap() => {
2145 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, 2170 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName,
2146 'parameters': parameters 2171 'parameters': parameters
2147 }; 2172 };
2148 } 2173 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698