Skip to content

Commit 143d4b2

Browse files
authored
Add arbitrary pub package serving to grinder and ignore URI_HAS_NOT_BEEN_GENERATED (#1599)
* first version, start of tests * pubspec change * add grinder tools to CONTRIBUTING * review comment * remove unused function
1 parent a077767 commit 143d4b2

File tree

5 files changed

+78
-13
lines changed

5 files changed

+78
-13
lines changed

CONTRIBUTING.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,31 @@ yet in the issue tracker, start by opening an issue. Thanks!
2424
1. `grind` is needed to run dartdoc integration tests, see installed via `pub global activate grinder`.
2525
2. When a change is user-facing, please add a new entry to the [changelog](https://github.com/dart-lang/dartdoc/blob/master/CHANGELOG.md)
2626
3. Please include a test for your change. `dartdoc` has both `package:test`-style unittests as well as integration tests. To run the unittests, use `dart test/all.dart`. Most changes can be tested via a unittest, but some require modifying the [test_package](https://github.com/dart-lang/dartdoc/tree/master/testing/test_package) and regenerating its docs via `grind update-test-package-docs`.
27-
4. Be sure to format your Dart code using `dartfmt -w`, otherwise travis will complain.
28-
5. Post your change via a pull request for review and integration!
27+
4. For major changes, run `grind compare-sdk-warnings` and include the summary results in your pull request.
28+
5. Be sure to format your Dart code using `dartfmt -w`, otherwise travis will complain.
29+
6. Post your change via a pull request for review and integration!
30+
31+
## Testing
32+
33+
dartdoc has a number of grinder utility methods that can be used to check for behavior changes
34+
or try out your change on arbitrary packages.
35+
36+
```bash
37+
# Serve the latest version of the given package locally on port 9000.
38+
PACKAGE_NAME=angular_components grind serve-pub-package
39+
40+
# Build the SDK docs with the head version and compare its warning
41+
# output and (rough) performance to the main version.
42+
grind compare-sdk-warnings
43+
44+
# Serve the flutter docs built with the head version on port 8001.
45+
grind serve-flutter-docs
46+
47+
# Serve the test package (testing/test_package) on port 8002
48+
grind serve-test-package-docs
49+
```
50+
51+
There are more added all the time -- run `grind --help` to see them all.
2952

3053
## License
3154

lib/dartdoc.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class DartDoc extends PackageBuilder {
131131
new _Error(error, info.lineInfo, packageMeta.dir.path));
132132
})
133133
.where((_Error error) => error.isError)
134+
// TODO(jcollins-g): remove after conversion to analysis driver
135+
.where((_Error error) => error.error.errorCode != CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED)
134136
.toList()
135137
..sort();
136138

lib/src/io_utils.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ final RegExp quotables = new RegExp(r'[ "\r\n\$]');
6767

6868
class SubprocessLauncher {
6969
final String context;
70-
Map<String, String> _environment;
71-
72-
Map<String, String> get environment => _environment;
70+
final Map<String, String> environment;
7371

7472
String get prefix => context.isNotEmpty ? '$context: ' : '';
7573

@@ -90,13 +88,8 @@ class SubprocessLauncher {
9088
});
9189
}
9290

93-
SubprocessLauncher(this.context, [Map<String, String> environment]) {
94-
if (environment == null) {
95-
this._environment = new Map();
96-
} else {
97-
this._environment = environment;
98-
}
99-
}
91+
SubprocessLauncher(this.context, [Map<String, String> environment]) :
92+
this.environment = environment ?? <String, String>{};
10093

10194
/// A wrapper around start/await process.exitCode that will display the
10295
/// output of the executable continuously and fail on non-zero exit codes.

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,4 @@ packages:
415415
source: hosted
416416
version: "2.1.13"
417417
sdks:
418-
dart: ">=1.23.0 <=2.0.0-dev.16.0"
418+
dart: ">=1.23.0 <=2.0.0-dev.20.0"

tool/grind.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ Future serveTestPackageDocs() async {
200200
]);
201201
}
202202

203+
_serveDocsFrom(String servePath, int port, String context) async {
204+
log('launching dhttpd on port $port for $context');
205+
var launcher = new SubprocessLauncher(context);
206+
await launcher.runStreamed(sdkBin('pub'), ['get']);
207+
await launcher.runStreamed(sdkBin('pub'), ['global', 'activate', 'dhttpd']);
208+
await launcher.runStreamed(sdkBin('pub'), [
209+
'run',
210+
'dhttpd',
211+
'--port',
212+
'$port',
213+
'--path',
214+
servePath
215+
]);
216+
}
217+
203218
@Task('Serve generated SDK docs locally with dhttpd on port 8000')
204219
@Depends(buildSdkDocs)
205220
Future serveSdkDocs() async {
@@ -279,6 +294,38 @@ Future _buildFlutterDocs(String flutterPath, [String label]) async {
279294
);
280295
}
281296

297+
/// Returns the directory in which we generated documentation.
298+
Future<String> _buildPubPackageDocs(String pubPackageName, [String version, String label]) async {
299+
Map<String, String> env = _createThrowawayPubCache();
300+
var launcher = new SubprocessLauncher(
301+
'build-${pubPackageName}${version == null ? "" : "-$version"}${label == null ? "" : "-$label"}', env);
302+
List<String> args = <String>['cache', 'add'];
303+
if (version != null) args.addAll(<String>['-v', version]);
304+
args.add(pubPackageName);
305+
await launcher.runStreamed('pub', args);
306+
Directory cache = new Directory(path.join(env['PUB_CACHE'], 'hosted', 'pub.dartlang.org'));
307+
Directory pubPackageDir = cache.listSync().firstWhere((e) => e.path.contains(pubPackageName));
308+
await launcher.runStreamed('pub', ['get'], workingDirectory: pubPackageDir.absolute.path);
309+
await launcher.runStreamed(
310+
Platform.resolvedExecutable,
311+
[
312+
'--checked',
313+
path.join(Directory.current.absolute.path, 'bin', 'dartdoc.dart'),
314+
'--json',
315+
'--show-progress',
316+
],
317+
workingDirectory: pubPackageDir.absolute.path);
318+
return path.join(pubPackageDir.absolute.path, 'doc', 'api');
319+
}
320+
321+
@Task('Serve an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION environment variables')
322+
servePubPackage() async {
323+
assert(Platform.environment.containsKey('PACKAGE_NAME'));
324+
String packageName = Platform.environment['PACKAGE_NAME'];
325+
String version = Platform.environment['PACKAGE_VERSION'];
326+
_serveDocsFrom(await _buildPubPackageDocs(packageName, version), 9000, 'serve-pub-package');
327+
}
328+
282329
@Task('Checks that CHANGELOG mentions current version')
283330
checkChangelogHasVersion() async {
284331
var changelog = new File('CHANGELOG.md');

0 commit comments

Comments
 (0)