Skip to content

Add an option to skip unreachable SDK libraries #2912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import 'package:dartdoc/src/package_meta.dart'
import 'package:dartdoc/src/quiver.dart' as quiver;
import 'package:dartdoc/src/render/renderer_factory.dart';
import 'package:dartdoc/src/special_elements.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path show Context;

/// Everything you need to instantiate a PackageGraph object for documenting.
Expand All @@ -49,7 +50,9 @@ class PubPackageBuilder implements PackageBuilder {
final PackageConfigProvider packageConfigProvider;

PubPackageBuilder(
this.config, this.packageMetaProvider, this.packageConfigProvider);
this.config, this.packageMetaProvider, this.packageConfigProvider,
{@visibleForTesting skipUnreachableSdkLibraries = false})
: _skipUnreachableSdkLibraries = skipUnreachableSdkLibraries;

@override
Future<PackageGraph> buildPackageGraph() async {
Expand Down Expand Up @@ -131,7 +134,7 @@ class PubPackageBuilder implements PackageBuilder {
);

/// Returns an Iterable with the SDK files we should parse.
Iterable<String> getSdkFilesToDocument() sync* {
Iterable<String> _getSdkFilesToDocument() sync* {
for (var sdkLib in sdk.sdkLibraries) {
var source = sdk.mapDartUri(sdkLib.shortName)!;
yield source.fullName;
Expand Down Expand Up @@ -175,6 +178,15 @@ class PubPackageBuilder implements PackageBuilder {
}
}

/// Whether to skip unreachable libraries when gathering all of the libraries
/// for the package graph.
///
/// **TESTING ONLY**
///
/// When generating dartdoc for any package, this flag should be `false`. This
/// is used in tests to dramatically speed up unit tests.
final bool _skipUnreachableSdkLibraries;

/// Parses libraries with the analyzer and invokes [addLibrary] with each
/// result.
///
Expand Down Expand Up @@ -219,7 +231,9 @@ class PubPackageBuilder implements PackageBuilder {
// for that package.
for (var meta in current.difference(lastPass)) {
if (meta.isSdk) {
files.addAll(getSdkFilesToDocument());
if (!_skipUnreachableSdkLibraries) {
files.addAll(_getSdkFilesToDocument());
}
} else {
files.addAll(await findFilesToDocumentInPackage(meta.dir.path,
autoIncludeDependencies: false, filterExcludes: false)
Expand Down Expand Up @@ -330,7 +344,7 @@ class PubPackageBuilder implements PackageBuilder {
Future<Set<String>> _getFiles() async {
Iterable<String> files;
if (config.topLevelPackageMeta.isSdk) {
files = getSdkFilesToDocument();
files = _getSdkFilesToDocument();
} else {
files = await findFilesToDocumentInPackage(config.inputDir,
autoIncludeDependencies: config.autoIncludeDependencies)
Expand Down
3 changes: 2 additions & 1 deletion test/end2end/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void main() {
return await Dartdoc.fromContext(
context,
PubPackageBuilder(
context, pubPackageMetaProvider, PhysicalPackageConfigProvider()),
context, pubPackageMetaProvider, PhysicalPackageConfigProvider(),
skipUnreachableSdkLibraries: true),
);
}

Expand Down
3 changes: 2 additions & 1 deletion test/mustachio/renderers_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void main() {
var dartdoc = await Dartdoc.fromContext(
context,
PubPackageBuilder(
context, pubPackageMetaProvider, PhysicalPackageConfigProvider()),
context, pubPackageMetaProvider, PhysicalPackageConfigProvider(),
skipUnreachableSdkLibraries: true),
);

var packageGraph = await dartdoc.packageBuilder.buildPackageGraph();
Expand Down
3 changes: 2 additions & 1 deletion test/warnings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class Lib2Class {}
var dartdoc = await Dartdoc.fromContext(
context,
PubPackageBuilder(
context, pubPackageMetaProvider, PhysicalPackageConfigProvider()),
context, pubPackageMetaProvider, PhysicalPackageConfigProvider(),
skipUnreachableSdkLibraries: true),
);

var packageGraph = await dartdoc.packageBuilder.buildPackageGraph();
Expand Down