Skip to content

Commit

Permalink
Notify the analyzer of deleted files (#3584)
Browse files Browse the repository at this point in the history
Related to dart-lang/source_gen#682.

Deleted files were never getting a changeFile call and so they were still available in the analyzer. This exposed in particular old generated part files to subsequent builds which could cause weird errors.
  • Loading branch information
jakemac53 authored Sep 28, 2023
1 parent bbd32a1 commit e2c837b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions build_resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.4.1-wip

- Fix an issue where deleted files were not removed from the analysis engine,
and were still accessible via the analyzer apis.

## 2.4.0

- Deprecate the unnamed `AnalyzerResolvers` constructor, an replace it with the
Expand Down
1 change: 1 addition & 0 deletions build_resolvers/lib/src/build_asset_uri_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class BuildAssetUriResolver extends UriResolver {
_cachedAssetDigests.remove(id);
if (resourceProvider.getFile(path).exists) {
resourceProvider.deleteFile(path);
_needsChangeFile.add(path);
}
return _AssetState(path, const {});
}
Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_resolvers
version: 2.4.0
version: 2.4.1-wip
description: Resolve Dart code in a Builder
repository: https://github.com/dart-lang/build/tree/master/build_resolvers

Expand Down
46 changes: 46 additions & 0 deletions build_resolvers/test/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,52 @@ void main() {
}, resolvers: resolvers);
});

test('handles removing deleted parts', () async {
var resolvers = AnalyzerResolvers();
await resolveSources({
'a|web/main.dart': '''
part 'main.g.dart';
class A implements B {}
''',
'a|web/main.g.dart': '''
part of 'main.dart';
class B {}
''',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
var clazz = lib.getClass('A');
expect(clazz, isNotNull);
expect(clazz!.interfaces, hasLength(1));
expect(clazz.interfaces.first.getDisplayString(withNullability: false),
'B');
}, resolvers: resolvers);

// `resolveSources` actually completes prior to the build step being
// done, which causes this `reset` call to fail. After a few microtasks
// it succeeds though.
var tries = 0;
while (tries++ < 5) {
await Future.value(null);
try {
resolvers.reset();
} catch (_) {}
}

await resolveSources({
'a|web/main.dart': '''
part 'main.g.dart';
class A implements B {}
''',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
var clazz = lib.getClass('A');
expect(clazz, isNotNull);
expect(clazz!.interfaces, isEmpty);
}, resolvers: resolvers);
});

test('should list all libraries', () {
return resolveSources({
'a|web/main.dart': '''
Expand Down

0 comments on commit e2c837b

Please sign in to comment.