OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
8 import 'package:analyzer/src/services/formatter_impl.dart'; | 8 import 'package:analyzer/src/services/formatter_impl.dart'; |
9 import 'package:async_await/async_await.dart' as async_await; | 9 import 'package:async_await/async_await.dart' as async_await; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 stderr.writeln("Could not find compiler commit hash in README.md."); | 88 stderr.writeln("Could not find compiler commit hash in README.md."); |
89 exit(1); | 89 exit(1); |
90 } | 90 } |
91 | 91 |
92 lastCommit = match[0]; | 92 lastCommit = match[0]; |
93 | 93 |
94 var numFiles = 0; | 94 var numFiles = 0; |
95 var numCompiled = 0; | 95 var numCompiled = 0; |
96 | 96 |
97 // Compile any modified or missing files. | 97 // Compile any modified or missing files. |
98 var sources = new Set<String>(); | |
nweiz
2014/09/10 21:08:18
Nit: I wouldn't type this.
Bob Nystrom
2014/09/10 22:42:34
Done.
| |
98 for (var entry in new Directory(sourceDir).listSync(recursive: true)) { | 99 for (var entry in new Directory(sourceDir).listSync(recursive: true)) { |
99 if (p.extension(entry.path) != ".dart") continue; | 100 if (p.extension(entry.path) != ".dart") continue; |
100 | 101 |
101 numFiles++; | 102 numFiles++; |
102 var relative = p.relative(entry.path, from: sourceDir); | 103 var relative = p.relative(entry.path, from: sourceDir); |
104 sources.add(relative); | |
103 | 105 |
104 var sourceFile = entry as File; | 106 var sourceFile = entry as File; |
105 var destPath = p.join(generatedDir, relative); | 107 var destPath = p.join(generatedDir, relative); |
106 var destFile = new File(destPath); | 108 var destFile = new File(destPath); |
107 if (force || | 109 if (force || |
108 currentCommit != lastCommit || | 110 currentCommit != lastCommit || |
109 !destFile.existsSync() || | 111 !destFile.existsSync() || |
110 entry.lastModifiedSync().isAfter(destFile.lastModifiedSync())) { | 112 entry.lastModifiedSync().isAfter(destFile.lastModifiedSync())) { |
111 _compile(sourceFile.path, sourceFile.readAsStringSync(), destPath); | 113 _compile(sourceFile.path, sourceFile.readAsStringSync(), destPath); |
112 numCompiled++; | 114 numCompiled++; |
113 if (verbose) print("Compiled $relative"); | 115 if (verbose) print("Compiled $relative"); |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
119 // Delete any previously compiled files whose source no longer exists. | |
120 for (var entry in new Directory(generatedDir).listSync(recursive: true)) { | |
121 if (p.extension(entry.path) != ".dart") continue; | |
nweiz
2014/09/10 21:08:18
If there are specific non-Dart files we don't want
Bob Nystrom
2014/09/10 22:42:34
I think it's better to whitelist this. The compile
| |
122 | |
123 var relative = p.relative(entry.path, from: generatedDir); | |
124 | |
125 if (!sources.contains(relative)) { | |
126 _deleteFile(entry.path); | |
127 if (verbose) print("Deleted $relative"); | |
128 } | |
129 } | |
130 | |
117 // Update the README. | 131 // Update the README. |
118 if (currentCommit != lastCommit) { | 132 if (currentCommit != lastCommit) { |
119 readme = readme.replaceAll(_commitPattern, currentCommit); | 133 readme = readme.replaceAll(_commitPattern, currentCommit); |
120 _writeFile(readmePath, readme); | 134 _writeFile(readmePath, readme); |
135 if (verbose) print("Updated README.md"); | |
121 } | 136 } |
122 | 137 |
138 if (numCompiled > 0) _generateSnapshot(buildDir); | |
139 | |
123 if (verbose) print("Compiled $numCompiled out of $numFiles files"); | 140 if (verbose) print("Compiled $numCompiled out of $numFiles files"); |
124 | 141 |
125 if (numCompiled > 0) _generateSnapshot(buildDir); | |
126 | |
127 if (hadFailure) exit(1); | 142 if (hadFailure) exit(1); |
128 } | 143 } |
129 | 144 |
130 void _compile(String sourcePath, String source, String destPath) { | 145 void _compile(String sourcePath, String source, String destPath) { |
131 var destDir = new Directory(p.dirname(destPath)); | 146 var destDir = new Directory(p.dirname(destPath)); |
132 destDir.createSync(recursive: true); | 147 destDir.createSync(recursive: true); |
133 | 148 |
134 source = _translateAsyncAwait(sourcePath, source); | 149 source = _translateAsyncAwait(sourcePath, source); |
135 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath); | 150 if (source != null) source = _fixDart2jsImports(sourcePath, source, destPath); |
136 | 151 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 /// | 237 /// |
223 /// This swallows errors to accommodate multiple compilers running concurrently. | 238 /// This swallows errors to accommodate multiple compilers running concurrently. |
224 /// Since they will produce the same output anyway, a failure of one is fine. | 239 /// Since they will produce the same output anyway, a failure of one is fine. |
225 void _writeFile(String path, String contents) { | 240 void _writeFile(String path, String contents) { |
226 try { | 241 try { |
227 new File(path).writeAsStringSync(contents); | 242 new File(path).writeAsStringSync(contents); |
228 } on IOException catch (ex) { | 243 } on IOException catch (ex) { |
229 // Do nothing. | 244 // Do nothing. |
230 } | 245 } |
231 } | 246 } |
OLD | NEW |