Skip to content

Commit 3b0bc62

Browse files
authored
Document arbitrary SDK-like things as Dart SDKs. (#1665)
* refactors * Library/Package/PackageGraph constructor shuffle * Not quite there; still need to populate non-local packages * weird vm thing * Got it? * Add another test * tweaks for Flutter * Initialization speedups * Canonicalize path comparisons and increase timeouts on the complex dartdoc tests for travis * Update grind with different parameters * First step complete, now to eliminate dupes * Condense more into config * remove commented out line * Everything but the generator information is moved now. * dartfmt * Restore a commented out test * Use localPublicLibraries in restored test * Move generator into DartDoc pseudo-factory * Specify SDK dirs on command line * dartfmt + review comments * dartfmt * pubspec * Throw correct exception * new is not optional yet * Tweak to make cwd == SDK viable * tweak travis timeout and fix windows * Review comments
1 parent c10cd71 commit 3b0bc62

10 files changed

+150
-119
lines changed

bin/dartdoc.dart

Lines changed: 79 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ main(List<String> arguments) async {
4343
exit(0);
4444
}
4545

46-
Directory sdkDir = getSdkDir();
47-
final bool sdkDocs = args['sdk-docs'];
46+
Directory sdkDir = new Directory(args['sdk-dir']);
47+
bool sdkDocs = args['sdk-docs'];
4848
final bool showProgress = args['show-progress'];
4949

5050
Directory inputDir;
@@ -56,6 +56,14 @@ main(List<String> arguments) async {
5656
inputDir = args['input'];
5757
}
5858

59+
// If our input directory looks like the Dart SDK, then assume it is one,
60+
// and is the one we want to document against.
61+
PackageMeta packageMeta = new PackageMeta.fromDir(inputDir);
62+
if (packageMeta.isSdk) {
63+
sdkDir = inputDir;
64+
sdkDocs = true;
65+
}
66+
5967
List<String> footerTextFilePaths = [];
6068
// If we're generating docs for the Dart SDK, we insert a copyright footer.
6169
if (sdkDocs) {
@@ -142,8 +150,6 @@ main(List<String> arguments) async {
142150
});
143151
}
144152

145-
PackageMeta packageMeta = new PackageMeta.fromDir(inputDir);
146-
147153
if (packageMeta == null) {
148154
stderr.writeln(
149155
' fatal error: Unable to generate documentation: no pubspec.yaml found');
@@ -249,104 +255,108 @@ main(List<String> arguments) async {
249255

250256
ArgParser _createArgsParser() {
251257
var parser = new ArgParser();
252-
parser.addFlag('help',
253-
abbr: 'h', negatable: false, help: 'Show command help.');
254-
parser.addFlag('version',
255-
help: 'Display the version for $name.', negatable: false);
256258
parser.addFlag('add-crossdart',
257259
help: 'Add Crossdart links to the source code pieces.',
258260
negatable: false,
259261
defaultsTo: false);
260-
parser.addFlag('sdk-docs',
261-
help: 'Generate ONLY the docs for the Dart SDK.', negatable: false);
262-
parser.addFlag('show-warnings',
263-
help: 'Display warnings.', negatable: false, defaultsTo: false);
264-
parser.addFlag('show-progress',
265-
help: 'Display progress indications to console stdout', negatable: false);
266-
parser.addOption('sdk-readme',
267-
help: 'Path to the SDK description file. Deprecated (ignored)');
268-
parser.addOption('input', help: 'Path to source directory.');
269-
parser.addOption('output',
270-
help: 'Path to output directory.', defaultsTo: defaultOutDir);
271-
parser.addMultiOption('header',
272-
splitCommas: true, help: 'paths to header files containing HTML text.');
262+
parser.addOption('ambiguous-reexport-scorer-min-confidence',
263+
help:
264+
'Minimum scorer confidence to suppress warning on ambiguous reexport.',
265+
defaultsTo: '0.1',
266+
hide: true);
267+
parser.addFlag('auto-include-dependencies',
268+
help:
269+
'Include all the used libraries into the docs, even the ones not in the current package or "include-external"',
270+
negatable: false,
271+
defaultsTo: false);
272+
parser.addMultiOption('category-order',
273+
help:
274+
'A list of package names to place first when grouping libraries in packages. '
275+
'Unmentioned categories are sorted after these. (deprecated, replaced by package-order)',
276+
splitCommas: true);
277+
parser.addOption('example-path-prefix',
278+
help: 'Prefix for @example paths.\n(defaults to the project root)');
279+
parser.addMultiOption('exclude',
280+
splitCommas: true, help: 'Library names to ignore.');
281+
parser.addMultiOption('exclude-packages',
282+
splitCommas: true, help: 'Package names to ignore.');
283+
parser.addOption('favicon',
284+
help: 'A path to a favicon for the generated docs.');
273285
parser.addMultiOption('footer',
274286
splitCommas: true, help: 'paths to footer files containing HTML text.');
275287
parser.addMultiOption('footer-text',
276288
splitCommas: true,
277289
help: 'paths to footer-text files '
278290
'(optional text next to the package name and version).');
279-
parser.addMultiOption('exclude',
280-
splitCommas: true, help: 'Library names to ignore.');
281-
parser.addMultiOption('exclude-packages',
282-
splitCommas: true, help: 'Package names to ignore.');
291+
parser.addMultiOption('header',
292+
splitCommas: true, help: 'paths to header files containing HTML text.');
293+
parser.addFlag('help',
294+
abbr: 'h', negatable: false, help: 'Show command help.');
295+
parser.addFlag('hide-sdk-text',
296+
help:
297+
'Drop all text for SDK components. Helpful for integration tests for dartdoc, probably not useful for anything else.',
298+
negatable: true,
299+
defaultsTo: false,
300+
hide: true);
301+
parser.addOption('hosted-url',
302+
help:
303+
'URL where the docs will be hosted (used to generate the sitemap).');
283304
parser.addMultiOption('include',
284305
splitCommas: true, help: 'Library names to generate docs for.');
285306
parser.addMultiOption('include-external',
286307
help: 'Additional (external) dart files to include; use "dir/fileName", '
287308
'as in lib/material.dart.');
288-
parser.addOption('hosted-url',
289-
help:
290-
'URL where the docs will be hosted (used to generate the sitemap).');
291-
parser.addOption('example-path-prefix',
292-
help: 'Prefix for @example paths.\n(defaults to the project root)');
293-
parser.addOption('rel-canonical-prefix',
294-
help: 'If provided, add a rel="canonical" prefixed with provided value. '
295-
'Consider using if\nbuilding many versions of the docs for public '
296-
'SEO; learn more at https://goo.gl/gktN6F.');
297309
parser.addFlag('include-source',
298310
help: 'Show source code blocks.', negatable: true, defaultsTo: true);
299-
parser.addOption('favicon',
300-
help: 'A path to a favicon for the generated docs.');
301-
parser.addFlag('use-categories',
302-
help:
303-
'Group libraries from the same package in the libraries sidebar. (deprecated, ignored)',
304-
negatable: false,
305-
defaultsTo: false);
306-
parser.addMultiOption('category-order',
307-
help:
308-
'A list of package names to place first when grouping libraries in packages. '
309-
'Unmentioned categories are sorted after these. (deprecated, replaced by package-order)',
310-
splitCommas: true);
311+
parser.addOption('input', help: 'Path to source directory.');
312+
parser.addFlag('json',
313+
help: 'Prints out progress JSON maps. One entry per line.',
314+
defaultsTo: false,
315+
negatable: true);
316+
parser.addOption('output',
317+
help: 'Path to output directory.', defaultsTo: defaultOutDir);
311318
parser.addMultiOption('package-order',
312319
help:
313320
'A list of package names to place first when grouping libraries in packages. '
314321
'Unmentioned categories are sorted after these.',
315322
splitCommas: true);
316-
parser.addFlag('auto-include-dependencies',
317-
help:
318-
'Include all the used libraries into the docs, even the ones not in the current package or "include-external"',
319-
negatable: false,
320-
defaultsTo: false);
321323
parser.addFlag('pretty-index-json',
322324
help:
323325
"Generates `index.json` with indentation and newlines. The file is larger, but it's also easier to diff.",
324326
negatable: false,
325327
defaultsTo: false);
326-
parser.addOption('ambiguous-reexport-scorer-min-confidence',
327-
help:
328-
'Minimum scorer confidence to suppress warning on ambiguous reexport.',
329-
defaultsTo: "0.1",
330-
hide: true);
331-
parser.addFlag('verbose-warnings',
332-
help: 'Display extra debugging information and help with warnings.',
333-
negatable: true,
334-
defaultsTo: true);
335-
parser.addFlag('hide-sdk-text',
328+
parser.addOption('rel-canonical-prefix',
329+
help: 'If provided, add a rel="canonical" prefixed with provided value. '
330+
'Consider using if\nbuilding many versions of the docs for public '
331+
'SEO; learn more at https://goo.gl/gktN6F.');
332+
parser.addFlag('sdk-docs',
333+
help: 'Generate ONLY the docs for the Dart SDK.', negatable: false);
334+
parser.addOption('sdk-readme',
335+
help: 'Path to the SDK description file. Deprecated (ignored)');
336+
parser.addOption('sdk-dir',
337+
help: 'Path to the SDK directory',
338+
defaultsTo: defaultSdkDir.absolute.path);
339+
parser.addFlag('show-warnings',
340+
help: 'Display warnings.', negatable: false, defaultsTo: false);
341+
parser.addFlag('show-progress',
342+
help: 'Display progress indications to console stdout', negatable: false);
343+
parser.addFlag('use-categories',
336344
help:
337-
"Drop all text for SDK components. Helpful for integration tests for dartdoc, probably not useful for anything else.",
338-
negatable: true,
339-
defaultsTo: false,
340-
hide: true);
341-
parser.addFlag('json',
342-
help: 'Prints out progress JSON maps. One entry per line.',
343-
defaultsTo: false,
344-
negatable: true);
345+
'Group libraries from the same package in the libraries sidebar. (deprecated, ignored)',
346+
negatable: false,
347+
defaultsTo: false);
345348
parser.addFlag('validate-links',
346349
help:
347350
'Runs the built-in link checker to display Dart context aware warnings for broken links (slow)',
348351
negatable: true,
349352
defaultsTo: true);
353+
parser.addFlag('verbose-warnings',
354+
help: 'Display extra debugging information and help with warnings.',
355+
negatable: true,
356+
defaultsTo: true);
357+
parser.addFlag('version',
358+
help: 'Display the version for $name.', negatable: false);
359+
350360
return parser;
351361
}
352362

lib/dartdoc.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export 'src/element_type.dart';
3232
export 'src/generator.dart';
3333
export 'src/model.dart';
3434
export 'src/package_meta.dart';
35-
export 'src/sdk.dart';
3635

3736
const String name = 'dartdoc';
3837
// Update when pubspec version changes.

lib/src/config.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ library dartdoc.config;
66

77
import 'dart:io';
88

9-
import 'package:analyzer/dart/element/element.dart';
109
import 'package:dartdoc/dartdoc.dart';
1110
import 'package:path/path.dart' as pathLib;
1211

13-
import 'model.dart';
14-
1512
String _resolveTildePath(String originalPath) {
1613
if (originalPath == null || !originalPath.startsWith('~/')) {
1714
return originalPath;
@@ -28,18 +25,6 @@ String _resolveTildePath(String originalPath) {
2825
return pathLib.join(homeDir, originalPath.substring(2));
2926
}
3027

31-
/// Class representing values possibly local to a particular [ModelElement].
32-
class LocalConfig {
33-
final Map<String, Set<String>> categoryMap;
34-
final PackageMeta packageMeta;
35-
36-
LocalConfig._(this.categoryMap, this.packageMeta);
37-
38-
factory LocalConfig.fromLibrary(LibraryElement element) {
39-
return new LocalConfig._({}, new PackageMeta.fromElement(element));
40-
}
41-
}
42-
4328
class DartDocConfig {
4429
final bool addCrossdart;
4530
final bool autoIncludeDependencies;
@@ -167,7 +152,7 @@ class DartDocConfig {
167152
prettyIndexJson,
168153
reexportMinConfidence,
169154
relCanonicalPrefix,
170-
sdkDir ?? getSdkDir(),
155+
sdkDir ?? defaultSdkDir,
171156
sdkVersion,
172157
showWarnings,
173158
validateLinks,

lib/src/model.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@ class Library extends ModelElement with Categorization {
20482048
PackageMeta _packageMeta;
20492049
PackageMeta get packageMeta {
20502050
if (_packageMeta == null) {
2051-
_packageMeta = new PackageMeta.fromElement(element);
2051+
_packageMeta = new PackageMeta.fromElement(element, config);
20522052
}
20532053
return _packageMeta;
20542054
}
@@ -3768,7 +3768,7 @@ class PackageGraph extends Canonicalization
37683768

37693769
// Build [Library] objects, and link them to [Package]s.
37703770
libraryElements.forEach((element) {
3771-
var packageMeta = new PackageMeta.fromElement(element);
3771+
var packageMeta = new PackageMeta.fromElement(element, config);
37723772
var lib = new Library._(
37733773
element, this, new Package.fromPackageMeta(packageMeta, this));
37743774
packageMap[packageMeta.name]._libraries.add(lib);
@@ -4552,7 +4552,7 @@ class PackageGraph extends Canonicalization
45524552
e.library,
45534553
this,
45544554
new Package.fromPackageMeta(
4555-
new PackageMeta.fromElement(e.library), packageGraph));
4555+
new PackageMeta.fromElement(e.library, config), packageGraph));
45564556
allLibraries[e.library] = foundLibrary;
45574557
}
45584558
return foundLibrary;
@@ -5407,7 +5407,7 @@ class PackageBuilder {
54075407
if (library != null) {
54085408
if (!config.isLibraryExcluded(Library.getLibraryName(library)) &&
54095409
!config.excludePackages
5410-
.contains(new PackageMeta.fromElement(library)?.name)) {
5410+
.contains(new PackageMeta.fromElement(library, config)?.name)) {
54115411
libraries.add(library);
54125412
sources.add(source);
54135413
}

0 commit comments

Comments
 (0)