@@ -8,15 +8,16 @@ import 'package:build/build.dart';
8
8
import 'package:built_collection/built_collection.dart' ;
9
9
import 'package:watcher/watcher.dart' ;
10
10
11
+ import '../bootstrap/build_script_generate.dart' ;
11
12
import '../build_plan/build_directory.dart' ;
12
13
import '../build_plan/build_filter.dart' ;
13
14
import '../build_plan/build_plan.dart' ;
14
15
import '../commands/watch/asset_change.dart' ;
15
16
import '../constants.dart' ;
16
17
import '../io/asset_tracker.dart' ;
17
- import '../io/build_output_reader.dart' ;
18
18
import '../io/filesystem_cache.dart' ;
19
19
import '../io/reader_writer.dart' ;
20
+ import '../logging/build_log.dart' ;
20
21
import 'asset_graph/graph.dart' ;
21
22
import 'asset_graph/node.dart' ;
22
23
import 'build.dart' ;
@@ -35,11 +36,10 @@ import 'build_result.dart';
35
36
/// this serialized state is not actually used: the `AssetGraph` instance
36
37
/// already in memory is used directly.
37
38
class BuildSeries {
38
- final BuildPlan _buildPlan;
39
+ BuildPlan _buildPlan;
40
+ AssetGraph _assetGraph;
41
+ ReaderWriter _readerWriter;
39
42
40
- final AssetGraph _assetGraph;
41
-
42
- final ReaderWriter _readerWriter;
43
43
final ResourceManager _resourceManager = ResourceManager ();
44
44
45
45
/// For the first build only, updates from the previous serialized build
@@ -105,19 +105,21 @@ class BuildSeries {
105
105
return false ;
106
106
}
107
107
108
- final node =
109
- _assetGraph.contains (change.id) ? _assetGraph.get (change.id) : null ;
108
+ final id = change.id;
109
+ if (_isBuildConfiguration (id)) return true ;
110
+
111
+ final node = _assetGraph.contains (id) ? _assetGraph.get (id) : null ;
110
112
111
113
// Changes to files that are not currently part of the build.
112
114
if (node == null ) {
113
115
// Ignore under `.dart_tool/build`.
114
- if (change. id.path.startsWith (cacheDir)) return false ;
116
+ if (id.path.startsWith (cacheDir)) return false ;
115
117
116
118
// Ignore modifications and deletes.
117
119
if (change.type != ChangeType .ADD ) return false ;
118
120
119
121
// It's an add: return whether it's a new input.
120
- return _buildPlan.targetGraph.anyMatchesAsset (change. id);
122
+ return _buildPlan.targetGraph.anyMatchesAsset (id);
121
123
}
122
124
123
125
// Changes to files that are part of the build.
@@ -136,15 +138,21 @@ class BuildSeries {
136
138
137
139
// For modifications, confirm that the content actually changed.
138
140
if (change.type == ChangeType .MODIFY ) {
139
- _readerWriter.cache.invalidate ([change. id]);
140
- final newDigest = await _readerWriter.digest (change. id);
141
+ _readerWriter.cache.invalidate ([id]);
142
+ final newDigest = await _readerWriter.digest (id);
141
143
return node.digest != newDigest;
142
144
}
143
145
144
146
// It's an add of "missing source" node or a deletion of an input.
145
147
return true ;
146
148
}
147
149
150
+ bool _isBuildConfiguration (AssetId id) =>
151
+ id.path == 'build.yaml' ||
152
+ id.path.endsWith ('.build.yaml' ) ||
153
+ (id.package == _buildPlan.packageGraph.root.name &&
154
+ id.path == 'build.${_buildPlan .buildOptions .configKey }.yaml' );
155
+
148
156
Future <List <WatchEvent >> checkForChanges () async {
149
157
final updates = await AssetTracker (
150
158
_buildPlan.readerWriter,
@@ -178,14 +186,29 @@ class BuildSeries {
178
186
BuiltSet <BuildFilter >? buildFilters,
179
187
}) async {
180
188
if (_hasBuildScriptChanged (updates.keys.toSet ())) {
181
- return BuildResult (
182
- status: BuildStatus .failure,
183
- failureType: FailureType .buildScriptChanged,
184
- buildOutputReader: BuildOutputReader (
185
- buildPlan: _buildPlan,
186
- readerWriter: _readerWriter,
187
- assetGraph: _assetGraph,
188
- ),
189
+ return BuildResult .buildScriptChanged ();
190
+ }
191
+
192
+ if (updates.keys.any (_isBuildConfiguration)) {
193
+ _buildPlan = await _buildPlan.reload ();
194
+ await _buildPlan.deleteFilesAndFolders ();
195
+ // A config change might have caused new builders to be needed, which
196
+ // needs a restart to change the build script.
197
+ if (_buildPlan.restartIsNeeded) {
198
+ return BuildResult .buildScriptChanged ();
199
+ }
200
+ // A config change might have changed builder factories, which needs a
201
+ // restart to change the build script.
202
+ if (await hasGeneratedBuildScriptChanged ()) {
203
+ return BuildResult .buildScriptChanged ();
204
+ }
205
+ _assetGraph = _buildPlan.takeAssetGraph ();
206
+ _readerWriter = _buildPlan.readerWriter.copyWith (
207
+ generatedAssetHider: _assetGraph,
208
+ cache:
209
+ _buildPlan.buildOptions.enableLowResourcesMode
210
+ ? const PassthroughFilesystemCache ()
211
+ : InMemoryFilesystemCache (),
189
212
);
190
213
}
191
214
@@ -202,6 +225,7 @@ class BuildSeries {
202
225
}
203
226
}
204
227
228
+ if (! firstBuild) buildLog.nextBuild ();
205
229
final build = Build (
206
230
buildPlan: _buildPlan.copyWith (
207
231
buildDirs: buildDirs,
0 commit comments