Skip to content
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

migrate off of library.parts #3342

Merged
merged 11 commits into from Jul 25, 2022
308 changes: 188 additions & 120 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions build_resolvers/CHANGELOG.md
@@ -1,3 +1,10 @@
## 2.0.10-dev

- Migrate from `LibraryElement#parts` to `LibraryElement#parts2`.
- Update min sdk constraint to `2.17.0` since this is the minimum selectable
(and testable) sdk.
- Use a constructor tearoff since our min sdk now supports them.

## 2.0.9

- Fix a new case of `InconsistentAnalysisException` errors that can occur with
Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/lib/src/build_asset_uri_resolver.dart
Expand Up @@ -63,7 +63,7 @@ class BuildAssetUriResolver extends UriResolver {
withDriverResource,
{required bool transitive}) async {
final transitivelyResolved = _buildStepTransitivelyResolvedAssets
.putIfAbsent(buildStep, () => HashSet());
.putIfAbsent(buildStep, HashSet.new);
bool notCrawled(AssetId asset) => !transitivelyResolved.contains(asset);

final uncrawledIds = entryPoints.where(notCrawled);
Expand Down
20 changes: 11 additions & 9 deletions build_resolvers/lib/src/resolver.dart
Expand Up @@ -254,17 +254,19 @@ class AnalyzerResolver implements ReleasableResolver {
///
/// This includes the main library and existing part files.
Future<List<ErrorsResult>> _syntacticErrorsFor(LibraryElement element) async {
final existingElements = [
element,
for (final part in element.parts)
// The source may be null if the part doesn't exist. That's not
// important for us since we only care about syntax
if (part.source.exists()) part,
];
final existingSources = [element.source];

for (final part in element.parts2) {
var uri = part.uri;
// The source may be null if the part doesn't exist. That's not
jakemac53 marked this conversation as resolved.
Show resolved Hide resolved
// important for us since we only care about syntax
if (uri is! DirectiveUriWithSource) continue;
existingSources.add(uri.source);
}

// Map from elements to absolute paths
final paths = existingElements
.map((part) => _uriResolver.lookupCachedAsset(part.source.uri))
final paths = existingSources
.map((source) => _uriResolver.lookupCachedAsset(source.uri))
.whereType<AssetId>() // filter out nulls
.map(assetPath);

Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/mono_pkg.yaml
@@ -1,5 +1,5 @@
sdk:
- 2.14.0
- 2.17.0
- dev

stages:
Expand Down
6 changes: 3 additions & 3 deletions build_resolvers/pubspec.yaml
@@ -1,13 +1,13 @@
name: build_resolvers
version: 2.0.9
version: 2.0.10-dev
description: Resolve Dart code in a Builder
repository: https://github.com/dart-lang/build/tree/master/build_resolvers

environment:
sdk: ">=2.14.0 <3.0.0"
sdk: ">=2.17.0 <3.0.0"

dependencies:
analyzer: ">=3.4.1 <5.0.0"
analyzer: ">=4.3.0 <5.0.0"
async: ^2.5.0
build: ^2.0.0
crypto: ^3.0.0
Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/test/resolver_test.dart
Expand Up @@ -238,7 +238,7 @@ void main() {
} ''',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
expect(lib.imports.length, 2);
expect(lib.libraryImports.length, 2);
jakemac53 marked this conversation as resolved.
Show resolved Hide resolved
// TODO(scheglov) Use `parts2` when it is available.
//expect(lib.parts2, isEmpty);
}, resolvers: AnalyzerResolvers());
Expand Down
5 changes: 1 addition & 4 deletions build_runner_core/test/generate/resolution_test.dart
Expand Up @@ -43,10 +43,7 @@ class ListClassesAndHierarchyBuilder implements Builder {
}
// Process both the main and part files of a given library.
final library = await buildStep.inputLibrary;
final types = [
library.definingCompilationUnit.classes,
library.parts.map((p) => p.classes).expand((t) => t),
].expand((t) => t);
final types = library.units.expand((element) => element.classes);
final output = StringBuffer();
final outputId = buildStep.inputId.changeExtension('.txt');
for (final type in types) {
Expand Down