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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 var rest = parser.parse(arguments).rest; | 54 var rest = parser.parse(arguments).rest; |
55 if (rest.isEmpty) { | 55 if (rest.isEmpty) { |
56 throw new FormatException('Missing build directory.'); | 56 throw new FormatException('Missing build directory.'); |
57 } else if (rest.length > 1) { | 57 } else if (rest.length > 1) { |
58 throw new FormatException( | 58 throw new FormatException( |
59 'Unexpected arguments: ${rest.skip(1).join(" ")}.'); | 59 'Unexpected arguments: ${rest.skip(1).join(" ")}.'); |
60 } | 60 } |
61 | 61 |
62 buildDir = rest.first; | 62 buildDir = rest.first; |
63 } on FormatException catch (ex) { | 63 } on FormatException catch (ex) { |
64 print(ex); | 64 stderr.writeln(ex); |
65 print(); | 65 stderr.writeln(); |
66 print("Usage: dart async_compile.dart [--verbose] [--force] <build dir>"); | 66 stderr.writeln( |
| 67 "Usage: dart async_compile.dart [--verbose] [--force] <build dir>"); |
67 exit(64); | 68 exit(64); |
68 } | 69 } |
69 | 70 |
70 // See what version (i.e. Git commit) of the async-await compiler we | 71 // See what version (i.e. Git commit) of the async-await compiler we |
71 // currently have. If this is different from the version that was used to | 72 // currently have. If this is different from the version that was used to |
72 // compile the sources, recompile everything. | 73 // compile the sources, recompile everything. |
73 var currentCommit = _getCurrentCommit(); | 74 var currentCommit = _getCurrentCommit(); |
74 | 75 |
75 var readmePath = p.join(generatedDir, "README.md"); | 76 var readmePath = p.join(generatedDir, "README.md"); |
76 var lastCommit; | 77 var lastCommit; |
77 var readme = new File(readmePath).readAsStringSync(); | 78 var readme = new File(readmePath).readAsStringSync(); |
78 var match = _commitPattern.firstMatch(readme); | 79 var match = _commitPattern.firstMatch(readme); |
79 if (match == null) { | 80 if (match == null) { |
80 print("Could not find compiler commit hash in README.md."); | 81 stderr.writeln("Could not find compiler commit hash in README.md."); |
81 exit(1); | 82 exit(1); |
82 } | 83 } |
83 | 84 |
84 lastCommit = match[0]; | 85 lastCommit = match[0]; |
85 | 86 |
86 var numFiles = 0; | 87 var numFiles = 0; |
87 var numCompiled = 0; | 88 var numCompiled = 0; |
88 | 89 |
89 // Compile any modified or missing files. | 90 // Compile any modified or missing files. |
90 var sources = new Set(); | 91 var sources = new Set(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if (Platform.operatingSystem == "windows") { | 144 if (Platform.operatingSystem == "windows") { |
144 command = "cmd"; | 145 command = "cmd"; |
145 args = ["/c", "git"]..addAll(args); | 146 args = ["/c", "git"]..addAll(args); |
146 } | 147 } |
147 | 148 |
148 var result = Process.runSync( | 149 var result = Process.runSync( |
149 command, | 150 command, |
150 args, | 151 args, |
151 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa
it")); | 152 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa
it")); |
152 if (result.exitCode != 0) { | 153 if (result.exitCode != 0) { |
153 print("Could not get Git revision of async_await compiler."); | 154 stderr.writeln("Could not get Git revision of async_await compiler."); |
154 exit(1); | 155 exit(1); |
155 } | 156 } |
156 | 157 |
157 return result.stdout.trim(); | 158 return result.stdout.trim(); |
158 } | 159 } |
159 | 160 |
160 void _compile(String sourcePath, String source, String destPath) { | 161 void _compile(String sourcePath, String source, String destPath) { |
161 var destDir = new Directory(p.dirname(destPath)); | 162 var destDir = new Directory(p.dirname(destPath)); |
162 destDir.createSync(recursive: true); | 163 destDir.createSync(recursive: true); |
163 | 164 |
(...skipping 21 matching lines...) Expand all Loading... |
185 | 186 |
186 try { | 187 try { |
187 source = async_await.compile(source); | 188 source = async_await.compile(source); |
188 | 189 |
189 // Reformat the result since the compiler ditches all whitespace. | 190 // Reformat the result since the compiler ditches all whitespace. |
190 // TODO(rnystrom): Remove when this is fixed: | 191 // TODO(rnystrom): Remove when this is fixed: |
191 // https://github.com/dart-lang/async_await/issues/12 | 192 // https://github.com/dart-lang/async_await/issues/12 |
192 var result = new CodeFormatter().format(CodeKind.COMPILATION_UNIT, source); | 193 var result = new CodeFormatter().format(CodeKind.COMPILATION_UNIT, source); |
193 return result.source; | 194 return result.source; |
194 } catch (ex) { | 195 } catch (ex) { |
195 print("Async compile failed on $sourcePath:\n$ex"); | 196 stderr.writeln("Async compile failed on $sourcePath:\n$ex"); |
196 hadFailure = true; | 197 hadFailure = true; |
197 return null; | 198 return null; |
198 } | 199 } |
199 } | 200 } |
200 | 201 |
201 /// Fix relative imports to dart2js libraries. | 202 /// Fix relative imports to dart2js libraries. |
202 /// | 203 /// |
203 /// Pub imports dart2js using relative imports that reach outside of pub's | 204 /// Pub imports dart2js using relative imports that reach outside of pub's |
204 /// source tree. Since the build directory is in a different location, we need | 205 /// source tree. Since the build directory is in a different location, we need |
205 /// to fix those to be valid relative imports from the build directory. | 206 /// to fix those to be valid relative imports from the build directory. |
(...skipping 12 matching lines...) Expand all Loading... |
218 | 219 |
219 var entrypoint = p.join(generatedDir, 'bin/pub.dart'); | 220 var entrypoint = p.join(generatedDir, 'bin/pub.dart'); |
220 var packageRoot = p.join(buildDir, 'packages'); | 221 var packageRoot = p.join(buildDir, 'packages'); |
221 var snapshot = p.join(buildDir, 'dart-sdk/bin/snapshots/pub.dart.snapshot'); | 222 var snapshot = p.join(buildDir, 'dart-sdk/bin/snapshots/pub.dart.snapshot'); |
222 | 223 |
223 var result = Process.runSync( | 224 var result = Process.runSync( |
224 Platform.executable, | 225 Platform.executable, |
225 ["--package-root=$packageRoot", "--snapshot=$snapshot", entrypoint]); | 226 ["--package-root=$packageRoot", "--snapshot=$snapshot", entrypoint]); |
226 | 227 |
227 if (result.exitCode != 0) { | 228 if (result.exitCode != 0) { |
228 print("Failed to generate snapshot:"); | 229 stderr.writeln("Failed to generate snapshot:"); |
229 if (result.stderr.trim().isNotEmpty) print(result.stderr); | 230 if (result.stderr.trim().isNotEmpty) stderr.writeln(result.stderr); |
230 if (result.stdout.trim().isNotEmpty) print(result.stdout); | 231 if (result.stdout.trim().isNotEmpty) stderr.writeln(result.stdout); |
231 exit(result.exitCode); | 232 exit(result.exitCode); |
232 } | 233 } |
233 | 234 |
234 if (verbose) print("Created pub snapshot"); | 235 if (verbose) print("Created pub snapshot"); |
235 } | 236 } |
236 | 237 |
237 /// Deletes the file at [path], ignoring any IO errors that occur. | 238 /// Deletes the file at [path], ignoring any IO errors that occur. |
238 /// | 239 /// |
239 /// This swallows errors to accommodate multiple compilers running concurrently. | 240 /// This swallows errors to accommodate multiple compilers running concurrently. |
240 /// Since they will produce the same output anyway, a failure of one is fine. | 241 /// Since they will produce the same output anyway, a failure of one is fine. |
241 void _deleteFile(String path) { | 242 void _deleteFile(String path) { |
242 try { | 243 try { |
243 new File(path).deleteSync(); | 244 new File(path).deleteSync(); |
244 } on IOException catch (ex) { | 245 } on IOException catch (ex) { |
245 // Do nothing. | 246 // Do nothing. |
246 } | 247 } |
247 } | 248 } |
248 | 249 |
249 /// Writes [contents] to [path], ignoring any IO errors that occur. | 250 /// Writes [contents] to [path], ignoring any IO errors that occur. |
250 /// | 251 /// |
251 /// This swallows errors to accommodate multiple compilers running concurrently. | 252 /// This swallows errors to accommodate multiple compilers running concurrently. |
252 /// Since they will produce the same output anyway, a failure of one is fine. | 253 /// Since they will produce the same output anyway, a failure of one is fine. |
253 void _writeFile(String path, String contents) { | 254 void _writeFile(String path, String contents) { |
254 try { | 255 try { |
255 new File(path).writeAsStringSync(contents); | 256 new File(path).writeAsStringSync(contents); |
256 } on IOException catch (ex) { | 257 } on IOException catch (ex) { |
257 // Do nothing. | 258 // Do nothing. |
258 } | 259 } |
259 } | 260 } |
OLD | NEW |