@@ -8,8 +8,6 @@ import 'dart:io';
8
8
import 'package:args/args.dart' ;
9
9
import 'package:args/command_runner.dart' ;
10
10
import 'package:build_runner_core/build_runner_core.dart' ;
11
- // ignore: implementation_imports
12
- import 'package:build_runner_core/src/asset_graph/graph.dart' ;
13
11
14
12
import 'base_command.dart' ;
15
13
@@ -22,70 +20,19 @@ class CleanCommand extends Command<int> {
22
20
23
21
@override
24
22
String get description =>
25
- 'Cleans up output from previous builds. Does not clean up --output '
26
- 'directories.' ;
23
+ 'Deletes the build cache. The next build will be a full build.' ;
27
24
28
25
@override
29
26
Future <int > run () async {
30
- await cleanFor (assetGraphPath );
27
+ clean ( );
31
28
return 0 ;
32
29
}
33
30
}
34
31
35
- Future <void > cleanFor (String assetGraphPath) async {
36
- buildLog.warning (
37
- 'Deleting cache and generated source files.\n '
38
- 'This shouldn\' t be necessary for most applications, unless you have '
39
- 'made intentional edits to generated files (i.e. for testing). '
40
- 'Consider filing a bug at '
41
- 'https://github.com/dart-lang/build/issues/new if you are using this '
42
- 'to work around an apparent (and reproducible) bug.' ,
43
- );
44
-
45
- var assetGraphFile = File (assetGraphPath);
46
- if (! assetGraphFile.existsSync ()) {
47
- buildLog.warning (
48
- 'No asset graph found. '
49
- 'Skipping cleanup of generated files in source directories.' ,
50
- );
51
- return ;
52
- }
53
- AssetGraph assetGraph;
54
- try {
55
- assetGraph = AssetGraph .deserialize (await assetGraphFile.readAsBytes ());
56
- } catch (_) {
57
- buildLog.warning (
58
- 'Failed to deserialize AssetGraph. '
59
- 'Skipping cleanup of generated files in source directories.' ,
60
- );
61
- return ;
62
- }
63
- var packageGraph = await PackageGraph .forThisPackage ();
64
- await _cleanUpSourceOutputs (assetGraph, packageGraph);
65
- await _cleanUpGeneratedDirectory ();
66
- }
67
-
68
- Future <void > _cleanUpSourceOutputs (
69
- AssetGraph assetGraph,
70
- PackageGraph packageGraph,
71
- ) async {
72
- var writer = ReaderWriter (packageGraph);
73
- for (var id in assetGraph.outputs) {
74
- if (id.package != packageGraph.root.name) continue ;
75
- var node = assetGraph.get (id)! ;
76
- if (node.wasOutput) {
77
- // Note that this does a file.exists check in the root package and
78
- // only tries to delete the file if it exists. This way we only
79
- // actually delete to_source outputs, without reading in the build
80
- // actions.
81
- await writer.delete (id);
82
- }
83
- }
84
- }
85
-
86
- Future <void > _cleanUpGeneratedDirectory () async {
32
+ void clean () {
33
+ buildLog.doing ('Deleting the build cache.' );
87
34
var generatedDir = Directory (cacheDir);
88
- if (await generatedDir.exists ()) {
89
- await generatedDir.delete (recursive: true );
35
+ if (generatedDir.existsSync ()) {
36
+ generatedDir.deleteSync (recursive: true );
90
37
}
91
38
}
0 commit comments