@@ -7,13 +7,11 @@ import 'dart:collection';
7
7
8
8
import 'package:analyzer/dart/analysis/utilities.dart' ;
9
9
import 'package:analyzer/dart/ast/ast.dart' ;
10
- import 'package:analyzer/file_system/memory_file_system.dart' ;
11
10
// ignore: implementation_imports
12
11
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart' ;
13
12
import 'package:build/build.dart' ;
14
- import 'package:path/path.dart' as p;
15
13
16
- import 'analysis_driver_model_uri_resolver .dart' ;
14
+ import 'analysis_driver_filesystem .dart' ;
17
15
18
16
/// Manages analysis driver and related build state.
19
17
///
@@ -31,15 +29,14 @@ import 'analysis_driver_model_uri_resolver.dart';
31
29
/// implementation.
32
30
class AnalysisDriverModel {
33
31
/// In-memory filesystem for the analyzer.
34
- final MemoryResourceProvider resourceProvider =
35
- MemoryResourceProvider (context: p.posix);
32
+ final AnalysisDriverFilesystem filesystem = AnalysisDriverFilesystem ();
36
33
37
34
/// The import graph of all sources needed for analysis.
38
35
final _graph = _Graph ();
39
36
40
37
/// Assets that have been synced into the in-memory filesystem
41
- /// [resourceProvider ] .
42
- final _syncedOntoResourceProvider = < AssetId > {};
38
+ /// [filesystem ] .
39
+ final _syncedOntoFilesystem = < AssetId > {};
43
40
44
41
/// Notifies that [step] has completed.
45
42
///
@@ -51,7 +48,7 @@ class AnalysisDriverModel {
51
48
/// Clear cached information specific to an individual build.
52
49
void reset () {
53
50
_graph.clear ();
54
- _syncedOntoResourceProvider .clear ();
51
+ _syncedOntoFilesystem .clear ();
55
52
}
56
53
57
54
/// Attempts to parse [uri] into an [AssetId] and returns it if it is cached.
@@ -61,16 +58,16 @@ class AnalysisDriverModel {
61
58
///
62
59
/// Returns null if the `Uri` cannot be parsed or is not cached.
63
60
AssetId ? lookupCachedAsset (Uri uri) {
64
- final assetId = AnalysisDriverModelUriResolver .parseAsset (uri);
61
+ final assetId = AnalysisDriverFilesystem .parseAsset (uri);
65
62
// TODO(davidmorgan): not clear if this is the right "exists" check.
66
- if (assetId == null || ! resourceProvider .getFile (assetId.asPath).exists) {
63
+ if (assetId == null || ! filesystem .getFile (assetId.asPath).exists) {
67
64
return null ;
68
65
}
69
66
70
67
return assetId;
71
68
}
72
69
73
- /// Updates [resourceProvider ] and the analysis driver given by
70
+ /// Updates [filesystem ] and the analysis driver given by
74
71
/// `withDriverResource` with updated versions of [entryPoints] .
75
72
///
76
73
/// If [transitive] , then all the transitive imports from [entryPoints] are
@@ -107,14 +104,14 @@ class AnalysisDriverModel {
107
104
FutureOr <void > Function (AnalysisDriverForPackageBuild ))
108
105
withDriverResource,
109
106
{required bool transitive}) async {
110
- var idsToSyncOntoResourceProvider = entryPoints;
107
+ var idsToSyncOntoFilesystem = entryPoints;
111
108
Iterable <AssetId > inputIds = entryPoints;
112
109
113
110
// If requested, find transitive imports.
114
111
if (transitive) {
115
112
final previouslyMissingFiles = await _graph.load (buildStep, entryPoints);
116
- _syncedOntoResourceProvider .removeAll (previouslyMissingFiles);
117
- idsToSyncOntoResourceProvider = _graph.nodes.keys.toList ();
113
+ _syncedOntoFilesystem .removeAll (previouslyMissingFiles);
114
+ idsToSyncOntoFilesystem = _graph.nodes.keys.toList ();
118
115
inputIds = _graph.inputsFor (entryPoints);
119
116
}
120
117
@@ -124,39 +121,23 @@ class AnalysisDriverModel {
124
121
}
125
122
126
123
// Sync changes onto the "URI resolver", the in-memory filesystem.
127
- final changedIds = < AssetId > [];
128
- for (final id in idsToSyncOntoResourceProvider) {
129
- if (! _syncedOntoResourceProvider.add (id)) continue ;
124
+ for (final id in idsToSyncOntoFilesystem) {
125
+ if (! _syncedOntoFilesystem.add (id)) continue ;
130
126
final content =
131
127
await buildStep.canRead (id) ? await buildStep.readAsString (id) : null ;
132
- final inMemoryFile = resourceProvider.getFile (id.asPath);
133
- final inMemoryContent =
134
- inMemoryFile.exists ? inMemoryFile.readAsStringSync () : null ;
135
-
136
- if (content != inMemoryContent) {
137
- if (content == null ) {
138
- // TODO(davidmorgan): per "globallySeenAssets" in
139
- // BuildAssetUriResolver, deletes should only be applied at the end
140
- // of the build, in case the file is actually there but not visible
141
- // to the current reader.
142
- resourceProvider.deleteFile (id.asPath);
143
- changedIds.add (id);
144
- } else {
145
- if (inMemoryContent == null ) {
146
- resourceProvider.newFile (id.asPath, content);
147
- } else {
148
- resourceProvider.modifyFile (id.asPath, content);
149
- }
150
- changedIds.add (id);
151
- }
128
+ if (content == null ) {
129
+ filesystem.deleteFile (id.asPath);
130
+ } else {
131
+ filesystem.writeFile (id.asPath, content);
152
132
}
153
133
}
154
134
155
135
// Notify the analyzer of changes and wait for it to update its internal
156
136
// state.
157
- for (final id in changedIds ) {
158
- driver.changeFile (id.asPath );
137
+ for (final path in filesystem.changedPaths ) {
138
+ driver.changeFile (path );
159
139
}
140
+ filesystem.clearChangedPaths ();
160
141
await driver.applyPendingFileChanges ();
161
142
}
162
143
}
@@ -181,7 +162,7 @@ List<AssetId> _parseDependencies(String content, AssetId from) =>
181
162
182
163
extension _AssetIdExtensions on AssetId {
183
164
/// Asset path for the in-memory filesystem.
184
- String get asPath => AnalysisDriverModelUriResolver .assetPath (this );
165
+ String get asPath => AnalysisDriverFilesystem .assetPath (this );
185
166
}
186
167
187
168
/// The directive graph of all known sources.
0 commit comments