Skip to content

Commit d074f81

Browse files
committed
Remove old resolver.
1 parent 3494d50 commit d074f81

File tree

14 files changed

+127
-358
lines changed

14 files changed

+127
-358
lines changed

build/lib/src/library_cycle_graph/phased_reader.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ abstract class PhasedReader {
2929
/// its content. Note that generation might output nothing, in which case an
3030
/// empty string is returned for its content.
3131
Future<PhasedValue<String>> readPhased(AssetId id);
32+
33+
bool hasChanged(AssetId id, {required int fromPhase});
3234
}

build_resolvers/lib/builder.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import 'dart:async';
66

7+
import 'package:analyzer/dart/analysis/utilities.dart';
8+
import 'package:analyzer/dart/ast/ast.dart';
79
import 'package:build/build.dart';
810
import 'package:convert/convert.dart';
911
import 'package:crypto/crypto.dart';
1012

11-
import 'src/build_asset_uri_resolver.dart';
12-
1313
const transitiveDigestExtension = '.transitive_digest';
1414

1515
Builder transitiveDigestsBuilder(BuilderOptions _) =>
@@ -64,7 +64,7 @@ https://github.com/dart-lang/build/blob/master/docs/faq.md#unable-to-read-asset-
6464
byteSink.add((await buildStep.digest(next)).bytes);
6565

6666
// We know this isn't null since we already checked if we can read `next`.
67-
final deps = (await dependenciesOf(next, buildStep))!;
67+
final deps = _parseDependencies(await buildStep.readAsString(next), next);
6868

6969
// Add all previously unseen deps to the queue.
7070
for (final dep in deps) {
@@ -83,3 +83,17 @@ https://github.com/dart-lang/build/blob/master/docs/faq.md#unable-to-read-asset-
8383
'.dart': ['.dart$transitiveDigestExtension'],
8484
};
8585
}
86+
87+
const _ignoredSchemes = ['dart', 'dart-ext'];
88+
89+
Iterable<AssetId> _parseDependencies(String content, AssetId from) =>
90+
parseString(content: content, throwIfDiagnostics: false).unit.directives
91+
.whereType<UriBasedDirective>()
92+
.map((directive) => directive.uri.stringValue)
93+
// Filter out nulls. uri.stringValue can be null for strings that use
94+
// interpolation.
95+
.whereType<String>()
96+
.where(
97+
(uriContent) => !_ignoredSchemes.any(Uri.parse(uriContent).isScheme),
98+
)
99+
.map((content) => AssetId.resolve(Uri.parse(content), from: from));

build_resolvers/lib/src/analysis_driver.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import 'dart:io';
77
import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
88
// ignore: implementation_imports
99
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart';
10-
import 'package:build/build.dart';
1110
import 'package:package_config/package_config.dart' show PackageConfig;
1211
import 'package:path/path.dart' as p;
1312
import 'package:pub_semver/pub_semver.dart';
1413

14+
import 'analysis_driver_filesystem.dart';
1515
import 'analysis_driver_model.dart';
16-
import 'build_asset_uri_resolver.dart';
1716

1817
/// Builds an [AnalysisDriverForPackageBuild] backed by a summary SDK.
1918
///
@@ -55,10 +54,20 @@ Packages _buildAnalyzerPackages(
5554
// make them match the paths that we give it, so we use the
5655
// `assetPath` function to create those.
5756
rootFolder: resourceProvider.getFolder(
58-
p.url.normalize(assetPath(AssetId(package.name, ''))),
57+
p.url.normalize(
58+
AnalysisDriverFilesystem.assetPathFor(
59+
package: package.name,
60+
path: '',
61+
),
62+
),
5963
),
6064
libFolder: resourceProvider.getFolder(
61-
p.url.normalize(assetPath(AssetId(package.name, 'lib'))),
65+
p.url.normalize(
66+
AnalysisDriverFilesystem.assetPathFor(
67+
package: package.name,
68+
path: 'lib',
69+
),
70+
),
6271
),
6372
),
6473
});

build_resolvers/lib/src/analysis_driver_filesystem.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class AnalysisDriverFilesystem implements UriResolver, ResourceProvider {
100100
static String assetPath(AssetId assetId) =>
101101
'/${assetId.package}/${assetId.path}';
102102

103+
/// Path of the asset with [package] and [path] for the in-memory filesystem.
104+
static String assetPathFor({required String package, required String path}) =>
105+
'/$package/$path';
106+
103107
/// Attempts to parse [uri] into an [AssetId].
104108
///
105109
/// Handles 'package:' or 'asset:' URIs, as well as 'file:' URIs that have the

build_resolvers/lib/src/analysis_driver_model.dart

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import 'analysis_driver_filesystem.dart';
2929
/// anywhere; finish it. See `build_asset_uri_resolver.dart` for the current
3030
/// implementation.
3131
class AnalysisDriverModel {
32+
/// The instance used by the shared `AnalyzerResolvers` instance.
33+
static AnalysisDriverModel sharedInstance = AnalysisDriverModel();
34+
3235
/// In-memory filesystem for the analyzer.
3336
final AnalysisDriverFilesystem filesystem = AnalysisDriverFilesystem();
3437

@@ -37,7 +40,7 @@ class AnalysisDriverModel {
3740

3841
/// Assets that have been synced into the in-memory filesystem
3942
/// [filesystem].
40-
final _syncedOntoFilesystem = <AssetId>{};
43+
final _syncedOntoFilesystemAtPhase = <AssetId, int>{};
4144

4245
/// Notifies that [step] has completed.
4346
///
@@ -49,7 +52,7 @@ class AnalysisDriverModel {
4952
/// Clear cached information specific to an individual build.
5053
void reset() {
5154
_graphLoader.clear();
52-
_syncedOntoFilesystem.clear();
55+
_syncedOntoFilesystemAtPhase.clear();
5356
}
5457

5558
/// Attempts to parse [uri] into an [AssetId] and returns it if it is cached.
@@ -86,25 +89,17 @@ class AnalysisDriverModel {
8689
withDriverResource, {
8790
required bool transitive,
8891
}) async {
89-
// Immediately take the lock on `driver` so that the whole class state,
90-
// is only mutated by one build step at a time.
91-
await withDriverResource((driver) async {
92-
// TODO(davidmorgan): it looks like this is only ever called with a single
93-
// entrypoint, consider doing a breaking release to simplify the API.
94-
for (final entrypoint in entrypoints) {
95-
await _performResolve(
96-
driver,
97-
buildStep as BuildStepImpl,
98-
entrypoint,
99-
withDriverResource,
100-
transitive: transitive,
101-
);
102-
}
103-
});
92+
for (final entrypoint in entrypoints) {
93+
await _performResolve(
94+
buildStep as BuildStepImpl,
95+
entrypoint,
96+
withDriverResource,
97+
transitive: transitive,
98+
);
99+
}
104100
}
105101

106102
Future<void> _performResolve(
107-
AnalysisDriverForPackageBuild driver,
108103
BuildStepImpl buildStep,
109104
AssetId entrypoint,
110105
Future<void> Function(
@@ -133,27 +128,36 @@ class AnalysisDriverModel {
133128
inputs: inputIds,
134129
);
135130

136-
// Sync changes onto the "URI resolver", the in-memory filesystem.
137-
for (final id in idsToSyncOntoFilesystem) {
138-
if (!_syncedOntoFilesystem.add(id)) {
139-
continue;
140-
}
141-
final content =
142-
await buildStep.canRead(id) ? await buildStep.readAsString(id) : null;
143-
if (content == null) {
144-
filesystem.deleteFile(id.asPath);
145-
} else {
146-
filesystem.writeFile(id.asPath, content);
131+
await withDriverResource((driver) async {
132+
// Sync changes onto the "URI resolver", the in-memory filesystem.
133+
final phase = buildStep.phasedReader.phase;
134+
for (final id in idsToSyncOntoFilesystem) {
135+
final wasSyncedAt = _syncedOntoFilesystemAtPhase[id];
136+
if (wasSyncedAt != null) {
137+
if (!buildStep.phasedReader.hasChanged(id, fromPhase: wasSyncedAt)) {
138+
continue;
139+
}
140+
}
141+
_syncedOntoFilesystemAtPhase[id] = phase;
142+
final content =
143+
await buildStep.canRead(id)
144+
? await buildStep.readAsString(id)
145+
: null;
146+
if (content == null) {
147+
filesystem.deleteFile(id.asPath);
148+
} else {
149+
filesystem.writeFile(id.asPath, content);
150+
}
147151
}
148-
}
149152

150-
// Notify the analyzer of changes and wait for it to update its internal
151-
// state.
152-
for (final path in filesystem.changedPaths) {
153-
driver.changeFile(path);
154-
}
155-
filesystem.clearChangedPaths();
156-
await driver.applyPendingFileChanges();
153+
// Notify the analyzer of changes and wait for it to update its internal
154+
// state.
155+
for (final path in filesystem.changedPaths) {
156+
driver.changeFile(path);
157+
}
158+
filesystem.clearChangedPaths();
159+
await driver.applyPendingFileChanges();
160+
});
157161
}
158162
}
159163

0 commit comments

Comments
 (0)