Skip to content

Commit 41709a9

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer_utilities] Ensure just one context when generating api.txt.
When generating `api.txt` files, it's important to verify that the `AnalysisContextCollection` contains just a single analysis context, otherwise `publicApi.build` won't see all the files in the package, and some parts of the API will be left out. This change switches to `collection.contexts.single` instead of `collection.contexts.first`, so that if something goes wrong and the collection contains more than one analysis context, an error will occur rather than silent misbehavior. Change-Id: I6a6a69647f5cd957a1a04bbb54940f48eefce3f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444860 Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 966500e commit 41709a9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/analyzer_utilities/lib/tool/api.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ List<GeneratedContent> allTargetsForPackage(String pkgName) => [
2828
includedPaths: [join(pkgRoot, pkgName)],
2929
resourceProvider: provider,
3030
);
31-
var context = collection.contexts.first;
31+
// Use `.single` to make sure that `collection` just contains a single
32+
// context. This ensures that `publicApi.build` will see all the files in
33+
// the package.
34+
var context = collection.contexts.single;
3235
var publicApi = ApiDescription(pkgName);
3336
var stringBuffer = StringBuffer();
3437
_printNodes(stringBuffer, await publicApi.build(context));

0 commit comments

Comments
 (0)