@@ -8,8 +8,6 @@ import 'dart:io';
88import 'package:args/args.dart' ;
99import 'package:args/command_runner.dart' ;
1010import 'package:build_runner_core/build_runner_core.dart' ;
11- // ignore: implementation_imports
12- import 'package:build_runner_core/src/asset_graph/graph.dart' ;
1311
1412import 'base_command.dart' ;
1513
@@ -22,70 +20,19 @@ class CleanCommand extends Command<int> {
2220
2321 @override
2422 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.' ;
2724
2825 @override
2926 Future <int > run () async {
30- await cleanFor (assetGraphPath );
27+ clean ( );
3128 return 0 ;
3229 }
3330}
3431
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.' );
8734 var generatedDir = Directory (cacheDir);
88- if (await generatedDir.exists ()) {
89- await generatedDir.delete (recursive: true );
35+ if (generatedDir.existsSync ()) {
36+ generatedDir.deleteSync (recursive: true );
9037 }
9138}
0 commit comments