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

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

Issue 18233004: Added a flag package-root for users to define where the package directory is. (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 | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/lib/src/dart2js_mirrors.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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void _setCommandLineArguments(ArgResults argResults) { 83 void _setCommandLineArguments(ArgResults argResults) {
84 outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml'; 84 outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml';
85 outputToJson = argResults['json'] || argResults['output-format'] == 'json'; 85 outputToJson = argResults['json'] || argResults['output-format'] == 'json';
86 if (outputToYaml && outputToJson) { 86 if (outputToYaml && outputToJson) {
87 throw new ArgumentError('Cannot have contradictory output flags.'); 87 throw new ArgumentError('Cannot have contradictory output flags.');
88 } 88 }
89 outputToYaml = outputToYaml || !outputToJson; 89 outputToYaml = outputToYaml || !outputToJson;
90 includePrivate = argResults['include-private']; 90 includePrivate = argResults['include-private'];
91 parseSdk = argResults['parse-sdk']; 91 parseSdk = argResults['parse-sdk'];
92 includeSdk = parseSdk || argResults['include-sdk']; 92 includeSdk = parseSdk || argResults['include-sdk'];
93 packageDir = argResults['package-root'];
94 if (packageDir != null) logger.info('Package Root: ${packageDir}');
93 } 95 }
94 96
95 List<String> _listLibraries(List<String> args) { 97 List<String> _listLibraries(List<String> args) {
96 // TODO(janicejl): At the moment, only have support to have either one file, 98 // TODO(janicejl): At the moment, only have support to have either one file,
97 // or one directory. This is because there can only be one package directory 99 // or one directory. This is because there can only be one package directory
98 // since only one docgen is created per run. 100 // since only one docgen is created per run.
99 if (args.length != 1) throw new UnsupportedError(USAGE); 101 if (args.length != 1) throw new UnsupportedError(USAGE);
100 var libraries = new List<String>(); 102 var libraries = new List<String>();
101 var type = FileSystemEntity.typeSync(args[0]); 103 var type = FileSystemEntity.typeSync(args[0]);
102 104
103 if (type == FileSystemEntityType.FILE) { 105 if (type == FileSystemEntityType.FILE) {
104 libraries.add(path.absolute(args[0])); 106 libraries.add(path.absolute(args[0]));
105 logger.info('Added to libraries: ${libraries.last}'); 107 logger.info('Added to libraries: ${libraries.last}');
106 } else { 108 } else {
107 libraries.addAll(_listDartFromDir(args[0])); 109 libraries.addAll(_listDartFromDir(args[0]));
108 } 110 }
109 logger.info('Package Directory: $packageDir');
110 return libraries; 111 return libraries;
111 } 112 }
112 113
113 List<String> _listDartFromDir(String args) { 114 List<String> _listDartFromDir(String args) {
114 var files = listDir(args, recursive: true); 115 var files = listDir(args, recursive: true);
115 packageDir = files.firstWhere((f) => 116 if (packageDir == null) {
116 f.endsWith('/pubspec.yaml'), orElse: () => ''); 117 packageDir = files.firstWhere((f) =>
117 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; 118 f.endsWith('/pubspec.yaml'), orElse: () => '');
118 return files.where((f) => 119 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages';
119 f.endsWith('.dart') && !f.contains('/packages')).toList() 120 logger.info('Package Directory: $packageDir');
121 }
122 // To avoid anaylzing package files twice, only files with paths not
123 // containing '/packages' will be added. The only exception is if the file to
124 // analyze already has a '/package' in its path.
125 return files.where((f) => f.endsWith('.dart') &&
126 (!f.contains('/packages') || args.contains('/packages'))).toList()
120 ..forEach((lib) => logger.info('Added to libraries: $lib')); 127 ..forEach((lib) => logger.info('Added to libraries: $lib'));
121 } 128 }
122 129
123 List<String> _listSdk() { 130 List<String> _listSdk() {
124 var sdk = new List<String>(); 131 var sdk = new List<String>();
125 LIBRARIES.forEach((String name, LibraryInfo info) { 132 LIBRARIES.forEach((String name, LibraryInfo info) {
126 if (info.documented) { 133 if (info.documented) {
127 sdk.add('dart:$name'); 134 sdk.add('dart:$name');
128 logger.info('Add to SDK: ${sdk.last}'); 135 logger.info('Add to SDK: ${sdk.last}');
129 } 136 }
(...skipping 15 matching lines...) Expand all
145 } else { 152 } else {
146 // If DART_SDK is not defined in the environment, 153 // If DART_SDK is not defined in the environment,
147 // assuming the dart executable is from the Dart SDK folder inside bin. 154 // assuming the dart executable is from the Dart SDK folder inside bin.
148 sdkRoot = path.dirname(path.dirname(new Options().executable)); 155 sdkRoot = path.dirname(path.dirname(new Options().executable));
149 logger.info('SDK Root: ${sdkRoot}'); 156 logger.info('SDK Root: ${sdkRoot}');
150 } 157 }
151 158
152 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); 159 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir);
153 } 160 }
154 161
162 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly
163 // error message letting them know why it is failing to create a mirror system.
164 // If there is conflicting library names, should modify it with a hash at the
165 // end of it's library name.
155 /** 166 /**
156 * Analyzes set of libraries and provides a mirror system which can be used 167 * Analyzes set of libraries and provides a mirror system which can be used
157 * for static inspection of the source code. 168 * for static inspection of the source code.
158 */ 169 */
159 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, 170 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries,
160 String libraryRoot, {String packageRoot}) { 171 String libraryRoot, {String packageRoot}) {
161 SourceFileProvider provider = new SourceFileProvider(); 172 SourceFileProvider provider = new SourceFileProvider();
162 api.DiagnosticHandler diagnosticHandler = 173 api.DiagnosticHandler diagnosticHandler =
163 new FormattingDiagnosticHandler(provider).diagnosticHandler; 174 new FormattingDiagnosticHandler(provider).diagnosticHandler;
164 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); 175 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot'));
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 parameterMap['qualifiedname'] = qualifiedName; 547 parameterMap['qualifiedname'] = qualifiedName;
537 parameterMap['optional'] = isOptional.toString(); 548 parameterMap['optional'] = isOptional.toString();
538 parameterMap['named'] = isNamed.toString(); 549 parameterMap['named'] = isNamed.toString();
539 parameterMap['default'] = hasDefaultValue.toString(); 550 parameterMap['default'] = hasDefaultValue.toString();
540 parameterMap['type'] = type; 551 parameterMap['type'] = type;
541 parameterMap['value'] = defaultValue; 552 parameterMap['value'] = defaultValue;
542 parameterMap['annotations'] = new List.from(annotations); 553 parameterMap['annotations'] = new List.from(annotations);
543 return parameterMap; 554 return parameterMap;
544 } 555 }
545 } 556 }
OLDNEW
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/lib/src/dart2js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698