Skip to content

Commit 377b474

Browse files
authored
Adds a flag, --link-to-external, to interlink packages, SDK together (#1678)
1 parent 9904835 commit 377b474

File tree

118 files changed

+557
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+557
-84
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,21 @@ generates docs.
103103
```yaml
104104
dartdoc:
105105
categoryOrder: ["First Category", "Second Category"]
106+
linkTo:
107+
url: "https://my.dartdocumentationsite.org/dev/%v%"
106108
```
107109
108-
Unrecognized options will be ignored. For now, there's only one supported option:
110+
Unrecognized options will be ignored. Supported options:
109111
110112
* **categoryOrder**: Specify the order of categories, below, for display in the sidebar and
111113
the package page.
114+
* **linkTo**: For other packages depending on this one, if this map is defined those packages
115+
will use the settings here to control how hyperlinks to the package are generated.
116+
This will override the default for packages hosted on pub.dartlang.org.
117+
* url: A string indicating the base URL for documentation of this package. The following
118+
strings will be substituted in to complete the URL:
119+
* `%n%`: The name of this package, as defined in pubspec.yaml.
120+
* `%v%`: The version of this package as defined in pubspec.yaml.
112121

113122
The following are experimental options whose semantics are in flux and may be buggy. If you
114123
use one, please keep a close eye on the changing semantics. In general, paths are relative

bin/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ main(List<String> arguments) async {
6666
startLogging(config);
6767

6868
Directory outputDir = new Directory(config.output);
69-
logInfo("Generating documentation for '${config.packageMeta}' into "
69+
logInfo("Generating documentation for '${config.topLevelPackageMeta}' into "
7070
"${outputDir.absolute.path}${Platform.pathSeparator}");
7171

7272
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(config, outputDir);

lib/dartdoc.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class Dartdoc extends PackageBuilder {
8585
new AnalysisErrorInfoImpl(errorsResult.errors, errorsResult.lineInfo);
8686
List<_Error> errors = [info]
8787
.expand((AnalysisErrorInfo info) {
88-
return info.errors.map((error) =>
89-
new _Error(error, info.lineInfo, config.packageMeta.dir.path));
88+
return info.errors.map((error) => new _Error(
89+
error, info.lineInfo, config.topLevelPackageMeta.dir.path));
9090
})
9191
.where((_Error error) => error.isError)
9292
.toList()
@@ -103,8 +103,8 @@ class Dartdoc extends PackageBuilder {
103103

104104
List<_Error> errors = errorInfos
105105
.expand((AnalysisErrorInfo info) {
106-
return info.errors.map((error) =>
107-
new _Error(error, info.lineInfo, config.packageMeta.dir.path));
106+
return info.errors.map((error) => new _Error(
107+
error, info.lineInfo, config.topLevelPackageMeta.dir.path));
108108
})
109109
.where((_Error error) => error.isError)
110110
// TODO(jcollins-g): remove after conversion to analysis driver
@@ -172,7 +172,8 @@ class Dartdoc extends PackageBuilder {
172172
throw new DartdocFailure("dartdoc encountered errors while processing");
173173
}
174174

175-
return new DartdocResults(config.packageMeta, packageGraph, outputDir);
175+
return new DartdocResults(
176+
config.topLevelPackageMeta, packageGraph, outputDir);
176177
}
177178

178179
/// Warn on file paths.

lib/src/dartdoc_options.dart

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -842,12 +842,25 @@ class DartdocOptionContext {
842842
// ignore: unused_element
843843
String get _input => optionSet['input'].valueAt(context);
844844
String get inputDir => optionSet['inputDir'].valueAt(context);
845+
bool get linkToExternal => optionSet['linkTo']['external'].valueAt(context);
846+
String get linkToExternalUrl =>
847+
optionSet['linkTo']['externalUrl'].valueAt(context);
848+
849+
/// _linkToHosted is only used to construct synthetic options.
850+
// ignore: unused_element
851+
String get _linkToHosted => optionSet['linkTo']['hosted'].valueAt(context);
852+
853+
/// _linkToUrl is only used to construct synthetic options.
854+
// ignore: unused_element
855+
String get _linkToUrl => optionSet['linkTo']['url'].valueAt(context);
845856
String get output => optionSet['output'].valueAt(context);
846-
List<String> get packageOrder => optionSet['packageOrder'].valueAt(context);
847857
PackageMeta get packageMeta => optionSet['packageMeta'].valueAt(context);
858+
List<String> get packageOrder => optionSet['packageOrder'].valueAt(context);
848859
bool get sdkDocs => optionSet['sdkDocs'].valueAt(context);
849860
String get sdkDir => optionSet['sdkDir'].valueAt(context);
850861
bool get showWarnings => optionSet['showWarnings'].valueAt(context);
862+
PackageMeta get topLevelPackageMeta =>
863+
optionSet['topLevelPackageMeta'].valueAt(context);
851864
bool get useCategories => optionSet['useCategories'].valueAt(context);
852865
bool get validateLinks => optionSet['validateLinks'].valueAt(context);
853866
bool get verboseWarnings => optionSet['verboseWarnings'].valueAt(context);
@@ -936,9 +949,59 @@ Future<List<DartdocOption>> createDartdocOptions() async {
936949
help: 'Path to source directory (with override if --sdk-docs)',
937950
isDir: true,
938951
mustExist: true),
952+
new DartdocOptionSet('linkTo')
953+
..addAll([
954+
new DartdocOptionArgOnly<bool>('external', false,
955+
help: 'Allow links to be generated for packages outside this one.',
956+
negatable: true),
957+
new DartdocOptionSynthetic<String>('externalUrl',
958+
(DartdocOptionSynthetic option, Directory dir) {
959+
String url = option.parent['url'].valueAt(dir);
960+
if (url != null) {
961+
return url;
962+
}
963+
String hostedAt =
964+
option.parent.parent['packageMeta'].valueAt(dir).hostedAt;
965+
if (hostedAt != null) {
966+
Map<String, String> hostMap = option.parent['hosted'].valueAt(dir);
967+
if (hostMap.containsKey(hostedAt)) return hostMap[hostedAt];
968+
}
969+
return '';
970+
}, help: 'Url to use for this particular package.'),
971+
new DartdocOptionArgOnly<Map<String, String>>(
972+
'hosted',
973+
{
974+
'pub.dartlang.org':
975+
'https://pub.dartlang.org/documentation/%n%/%v%'
976+
},
977+
help: 'Specify URLs for hosted pub packages'),
978+
new DartdocOptionFileOnly<String>('url', null,
979+
help: 'Use external linkage for this package, with this base url'),
980+
]),
939981
new DartdocOptionArgOnly<String>('output', pathLib.join('doc', 'api'),
940982
isDir: true, help: 'Path to output directory.'),
941-
new DartdocOptionSynthetic<PackageMeta>('packageMeta',
983+
new DartdocOptionSynthetic<PackageMeta>(
984+
'packageMeta',
985+
(DartdocOptionSynthetic option, Directory dir) {
986+
PackageMeta packageMeta = new PackageMeta.fromDir(dir);
987+
if (packageMeta == null) {
988+
throw new DartdocOptionError(
989+
'Unable to determine package for directory: ${dir.path}');
990+
}
991+
return packageMeta;
992+
},
993+
),
994+
new DartdocOptionArgOnly<List<String>>('packageOrder', [],
995+
help:
996+
'A list of package names to place first when grouping libraries in packages. '
997+
'Unmentioned categories are sorted after these.'),
998+
new DartdocOptionArgOnly<bool>('sdkDocs', false,
999+
help: 'Generate ONLY the docs for the Dart SDK.', negatable: false),
1000+
new DartdocOptionArgOnly<String>('sdkDir', defaultSdkDir.absolute.path,
1001+
help: 'Path to the SDK directory.', isDir: true, mustExist: true),
1002+
new DartdocOptionArgOnly<bool>('showWarnings', false,
1003+
help: 'Display all warnings.', negatable: false),
1004+
new DartdocOptionSynthetic<PackageMeta>('topLevelPackageMeta',
9421005
(DartdocOptionSynthetic option, Directory dir) {
9431006
PackageMeta packageMeta = new PackageMeta.fromDir(
9441007
new Directory(option.parent['inputDir'].valueAt(dir)));
@@ -952,16 +1015,6 @@ Future<List<DartdocOption>> createDartdocOptions() async {
9521015
}
9531016
return packageMeta;
9541017
}, help: 'PackageMeta object for the default package.'),
955-
new DartdocOptionArgOnly<List<String>>('packageOrder', [],
956-
help:
957-
'A list of package names to place first when grouping libraries in packages. '
958-
'Unmentioned categories are sorted after these.'),
959-
new DartdocOptionArgOnly<bool>('sdkDocs', false,
960-
help: 'Generate ONLY the docs for the Dart SDK.', negatable: false),
961-
new DartdocOptionArgOnly<String>('sdkDir', defaultSdkDir.absolute.path,
962-
help: 'Path to the SDK directory', isDir: true, mustExist: true),
963-
new DartdocOptionArgOnly<bool>('showWarnings', false,
964-
help: 'Display all warnings.', negatable: false),
9651018
new DartdocOptionArgOnly<bool>('useCategories', true,
9661019
help: 'Display categories in the sidebar of packages',
9671020
negatable: false),

lib/src/io_utils.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class SubprocessLauncher {
126126
/// output of the executable continuously and fail on non-zero exit codes.
127127
/// It will also parse any valid JSON objects (one per line) it encounters
128128
/// on stdout/stderr, and return them. Returns null if no JSON objects
129-
/// were encountered.
129+
/// were encountered, or if DRY_RUN is set to 1 in the execution environment.
130130
///
131131
/// Makes running programs in grinder similar to set -ex for bash, even on
132132
/// Windows (though some of the bashisms will no longer make sense).
@@ -157,8 +157,6 @@ class SubprocessLauncher {
157157
return line.split('\n');
158158
}
159159

160-
Process process = await Process.start(executable, arguments,
161-
workingDirectory: workingDirectory, environment: environment);
162160
stderr.write('$prefix+ ');
163161
if (workingDirectory != null) stderr.write('(cd "$workingDirectory" && ');
164162
if (environment != null) {
@@ -183,6 +181,11 @@ class SubprocessLauncher {
183181
}
184182
if (workingDirectory != null) stderr.write(')');
185183
stderr.write('\n');
184+
185+
if (Platform.environment.containsKey('DRY_RUN')) return null;
186+
187+
Process process = await Process.start(executable, arguments,
188+
workingDirectory: workingDirectory, environment: environment);
186189
_printStream(process.stdout, stdout, prefix: prefix, filter: jsonCallback);
187190
_printStream(process.stderr, stderr, prefix: prefix, filter: jsonCallback);
188191
await process.exitCode;

0 commit comments

Comments
 (0)