Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: sdk/lib/_internal/pub_generated/bin/async_compile.dart

Issue 542193005: Delete stale compiled files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise! Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 import 'dart:io'; 1 import 'dart:io';
2 import 'package:args/args.dart'; 2 import 'package:args/args.dart';
3 import 'package:analyzer/src/services/formatter_impl.dart'; 3 import 'package:analyzer/src/services/formatter_impl.dart';
4 import 'package:async_await/async_await.dart' as async_await; 4 import 'package:async_await/async_await.dart' as async_await;
5 import 'package:path/path.dart' as p; 5 import 'package:path/path.dart' as p;
6 final sourceDir = p.dirname(p.dirname(p.fromUri(Platform.script))); 6 final sourceDir = p.dirname(p.dirname(p.fromUri(Platform.script)));
7 final sourceUrl = p.toUri(sourceDir).toString(); 7 final sourceUrl = p.toUri(sourceDir).toString();
8 final generatedDir = p.join(p.dirname(sourceDir), 'pub_generated'); 8 final generatedDir = p.join(p.dirname(sourceDir), 'pub_generated');
9 bool hadFailure = false; 9 bool hadFailure = false;
10 bool verbose = false; 10 bool verbose = false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 var lastCommit; 45 var lastCommit;
46 var readme = new File(readmePath).readAsStringSync(); 46 var readme = new File(readmePath).readAsStringSync();
47 var match = _commitPattern.firstMatch(readme); 47 var match = _commitPattern.firstMatch(readme);
48 if (match == null) { 48 if (match == null) {
49 stderr.writeln("Could not find compiler commit hash in README.md."); 49 stderr.writeln("Could not find compiler commit hash in README.md.");
50 exit(1); 50 exit(1);
51 } 51 }
52 lastCommit = match[0]; 52 lastCommit = match[0];
53 var numFiles = 0; 53 var numFiles = 0;
54 var numCompiled = 0; 54 var numCompiled = 0;
55 var sources = new Set<String>();
55 for (var entry in new Directory(sourceDir).listSync(recursive: true)) { 56 for (var entry in new Directory(sourceDir).listSync(recursive: true)) {
56 if (p.extension(entry.path) != ".dart") continue; 57 if (p.extension(entry.path) != ".dart") continue;
57 numFiles++; 58 numFiles++;
58 var relative = p.relative(entry.path, from: sourceDir); 59 var relative = p.relative(entry.path, from: sourceDir);
60 sources.add(relative);
59 var sourceFile = entry as File; 61 var sourceFile = entry as File;
60 var destPath = p.join(generatedDir, relative); 62 var destPath = p.join(generatedDir, relative);
61 var destFile = new File(destPath); 63 var destFile = new File(destPath);
62 if (force || 64 if (force ||
63 currentCommit != lastCommit || 65 currentCommit != lastCommit ||
64 !destFile.existsSync() || 66 !destFile.existsSync() ||
65 entry.lastModifiedSync().isAfter(destFile.lastModifiedSync())) { 67 entry.lastModifiedSync().isAfter(destFile.lastModifiedSync())) {
66 _compile(sourceFile.path, sourceFile.readAsStringSync(), destPath); 68 _compile(sourceFile.path, sourceFile.readAsStringSync(), destPath);
67 numCompiled++; 69 numCompiled++;
68 if (verbose) print("Compiled $relative"); 70 if (verbose) print("Compiled $relative");
69 } 71 }
70 } 72 }
73 for (var entry in new Directory(generatedDir).listSync(recursive: true)) {
74 if (p.extension(entry.path) != ".dart") continue;
75 var relative = p.relative(entry.path, from: generatedDir);
76 if (!sources.contains(relative)) {
77 _deleteFile(entry.path);
78 if (verbose) print("Deleted $relative");
79 }
80 }
71 if (currentCommit != lastCommit) { 81 if (currentCommit != lastCommit) {
72 readme = readme.replaceAll(_commitPattern, currentCommit); 82 readme = readme.replaceAll(_commitPattern, currentCommit);
73 _writeFile(readmePath, readme); 83 _writeFile(readmePath, readme);
84 if (verbose) print("Updated README.md");
74 } 85 }
86 if (numCompiled > 0) _generateSnapshot(buildDir);
75 if (verbose) print("Compiled $numCompiled out of $numFiles files"); 87 if (verbose) print("Compiled $numCompiled out of $numFiles files");
76 if (numCompiled > 0) _generateSnapshot(buildDir);
77 if (hadFailure) exit(1); 88 if (hadFailure) exit(1);
78 } 89 }
79 void _compile(String sourcePath, String source, String destPath) { 90 void _compile(String sourcePath, String source, String destPath) {
80 var destDir = new Directory(p.dirname(destPath)); 91 var destDir = new Directory(p.dirname(destPath));
81 destDir.createSync(recursive: true); 92 destDir.createSync(recursive: true);
82 source = _translateAsyncAwait(sourcePath, source); 93 source = _translateAsyncAwait(sourcePath, source);
83 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath); 94 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath);
84 if (source == null) { 95 if (source == null) {
85 _deleteFile(destPath); 96 _deleteFile(destPath);
86 } else { 97 } else {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void _deleteFile(String path) { 137 void _deleteFile(String path) {
127 try { 138 try {
128 new File(path).deleteSync(); 139 new File(path).deleteSync();
129 } on IOException catch (ex) {} 140 } on IOException catch (ex) {}
130 } 141 }
131 void _writeFile(String path, String contents) { 142 void _writeFile(String path, String contents) {
132 try { 143 try {
133 new File(path).writeAsStringSync(contents); 144 new File(path).writeAsStringSync(contents);
134 } on IOException catch (ex) {} 145 } on IOException catch (ex) {}
135 } 146 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/bin/async_compile.dart ('k') | sdk/lib/_internal/pub_generated/lib/src/barback/asset_environment.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698