@@ -11,14 +11,15 @@ import 'package:build/build.dart';
11
11
import 'package:build/experiments.dart' as experiments_zone;
12
12
// ignore: implementation_imports
13
13
import 'package:build/src/internal.dart' ;
14
- import 'package:convert/convert .dart' ;
14
+ import 'package:built_collection/built_collection .dart' ;
15
15
import 'package:crypto/crypto.dart' ;
16
16
import 'package:glob/glob.dart' ;
17
17
import 'package:package_config/package_config.dart' ;
18
18
import 'package:watcher/watcher.dart' ;
19
19
20
+ import '../../build_runner_core.dart' ;
21
+ import '../generate/build_phases.dart' ;
20
22
import '../generate/phase.dart' ;
21
- import '../package_graph/package_graph.dart' ;
22
23
import '../util/constants.dart' ;
23
24
import 'exceptions.dart' ;
24
25
import 'node.dart' ;
@@ -41,9 +42,9 @@ class AssetGraph implements GeneratedAssetHider {
41
42
42
43
/// The Dart language experiments that were enabled when this graph was
43
44
/// originally created from the [build] constructor.
44
- final List <String > enabledExperiments;
45
+ final BuiltList <String > enabledExperiments;
45
46
46
- final Map <String , LanguageVersion ?> packageLanguageVersions;
47
+ final BuiltMap <String , LanguageVersion ?> packageLanguageVersions;
47
48
48
49
AssetGraph ._(
49
50
this .buildPhasesDigest,
@@ -57,21 +58,17 @@ class AssetGraph implements GeneratedAssetHider {
57
58
_AssetGraphDeserializer (serializedGraph).deserialize ();
58
59
59
60
static Future <AssetGraph > build (
60
- List < BuildPhase > buildPhases,
61
+ BuildPhases buildPhases,
61
62
Set <AssetId > sources,
62
63
Set <AssetId > internalSources,
63
64
PackageGraph packageGraph,
64
65
AssetReader digestReader,
65
66
) async {
66
- var packageLanguageVersions = {
67
- for (var pkg in packageGraph.allPackages.values)
68
- pkg.name: pkg.languageVersion,
69
- };
70
67
var graph = AssetGraph ._(
71
- computeBuildPhasesDigest ( buildPhases) ,
68
+ buildPhases.digest ,
72
69
Platform .version,
73
- packageLanguageVersions ,
74
- experiments_zone.enabledExperiments,
70
+ packageGraph.languageVersions ,
71
+ experiments_zone.enabledExperiments. build () ,
75
72
);
76
73
var placeholders = graph._addPlaceHolderNodes (packageGraph);
77
74
graph._addSources (sources);
@@ -191,7 +188,7 @@ class AssetGraph implements GeneratedAssetHider {
191
188
}
192
189
193
190
/// Adds [AssetNode.builderOptions] for all [buildPhases] to this graph.
194
- void _addBuilderOptionsNodes (List < BuildPhase > buildPhases) {
191
+ void _addBuilderOptionsNodes (BuildPhases buildPhases) {
195
192
for (var phaseNum = 0 ; phaseNum < buildPhases.length; phaseNum++ ) {
196
193
var phase = buildPhases[phaseNum];
197
194
if (phase is InBuildPhase ) {
@@ -335,7 +332,7 @@ class AssetGraph implements GeneratedAssetHider {
335
332
///
336
333
/// Returns the list of [AssetId] s that were invalidated.
337
334
Future <Set <AssetId >> updateAndInvalidate (
338
- List < BuildPhase > buildPhases,
335
+ BuildPhases buildPhases,
339
336
Map <AssetId , ChangeType > updates,
340
337
String rootPackage,
341
338
Future Function (AssetId id) delete,
@@ -531,7 +528,7 @@ class AssetGraph implements GeneratedAssetHider {
531
528
/// If [placeholders] is supplied they will be added to [newSources] to create
532
529
/// the full input set.
533
530
Set <AssetId > _addOutputsForSources (
534
- List < BuildPhase > buildPhases,
531
+ BuildPhases buildPhases,
535
532
Set <AssetId > newSources,
536
533
String rootPackage, {
537
534
Set <AssetId >? placeholders,
@@ -570,7 +567,7 @@ class AssetGraph implements GeneratedAssetHider {
570
567
InBuildPhase phase,
571
568
int phaseNum,
572
569
Set <AssetId > allInputs,
573
- List < BuildPhase > buildPhases,
570
+ BuildPhases buildPhases,
574
571
String rootPackage,
575
572
) {
576
573
var phaseOutputs = < AssetId > {};
@@ -640,7 +637,7 @@ class AssetGraph implements GeneratedAssetHider {
640
637
Iterable <AssetId > outputs,
641
638
int phaseNumber,
642
639
AssetNode builderOptionsNode,
643
- List < BuildPhase > buildPhases,
640
+ BuildPhases buildPhases,
644
641
String rootPackage, {
645
642
required AssetId primaryInput,
646
643
required bool isHidden,
@@ -733,17 +730,35 @@ class AssetGraph implements GeneratedAssetHider {
733
730
}
734
731
return id;
735
732
}
736
- }
737
733
738
- /// Computes a [Digest] for [buildPhases] which can be used to compare one set
739
- /// of [BuildPhase] s against another.
740
- Digest computeBuildPhasesDigest (Iterable <BuildPhase > buildPhases) {
741
- var digestSink = AccumulatorSink <Digest >();
742
- md5.startChunkedConversion (digestSink)
743
- ..add (buildPhases.map ((phase) => phase.identity).toList ())
744
- ..close ();
745
- assert (digestSink.events.length == 1 );
746
- return digestSink.events.first;
734
+ /// Deletes outputs that were written to the source tree.
735
+ ///
736
+ /// Returns the assets that were deleted.
737
+ Future <Iterable <AssetId >> deleteOutputs (
738
+ PackageGraph packageGraph,
739
+ RunnerAssetWriter writer,
740
+ ) async {
741
+ var deletedSources = < AssetId > [];
742
+ // Delete all the non-hidden outputs.
743
+ for (final id in outputs) {
744
+ var node = get (id)! ;
745
+ final nodeConfiguration = node.generatedNodeConfiguration! ;
746
+ final nodeState = node.generatedNodeState! ;
747
+ if (nodeState.wasOutput && ! nodeConfiguration.isHidden) {
748
+ var idToDelete = id;
749
+ // If the package no longer exists, then the user must have
750
+ // renamed the root package.
751
+ //
752
+ // In that case we change `idToDelete` to be in the root package.
753
+ if (packageGraph[id.package] == null ) {
754
+ idToDelete = AssetId (packageGraph.root.name, id.path);
755
+ }
756
+ deletedSources.add (idToDelete);
757
+ await writer.delete (idToDelete);
758
+ }
759
+ }
760
+ return deletedSources;
761
+ }
747
762
}
748
763
749
764
Digest computeBuilderOptionsDigest (BuilderOptions options) =>
0 commit comments