Chromium Code Reviews| Index: sdk/lib/_internal/pub/bin/async_compile.dart |
| diff --git a/sdk/lib/_internal/pub/bin/async_compile.dart b/sdk/lib/_internal/pub/bin/async_compile.dart |
| index 40280a674281cfce611cdd815cdfaa215ccb3827..0b008ab4a16faa130458fd259d72f2a9886af6e8 100644 |
| --- a/sdk/lib/_internal/pub/bin/async_compile.dart |
| +++ b/sdk/lib/_internal/pub/bin/async_compile.dart |
| @@ -4,6 +4,7 @@ |
| import 'dart:io'; |
| +import 'package:async_await/async_await.dart' as async_await; |
| import 'package:path/path.dart' as p; |
| /// The path to pub's root directory (sdk/lib/_internal/pub) in the Dart repo. |
| @@ -17,6 +18,9 @@ final sourceUrl = p.toUri(sourceDir).toString(); |
| /// The directory that compiler output should be written to. |
| String buildDir; |
| +/// `true` if any file failed to compile. |
| +bool hadFailure = false; |
| + |
| /// This runs the async/await compiler on all of the pub source code. |
| /// |
| /// It reads from the repo and writes the compiled output into the given build |
| @@ -62,6 +66,8 @@ void main(List<String> arguments) { |
| } |
| if (!silent) print("Compiled $numCompiled out of $numFiles files."); |
| + |
| + if (hadFailure) exit(1); |
| } |
| final _compilerPattern = new RegExp(r"import '(\.\./)+compiler"); |
| @@ -70,8 +76,30 @@ void compile(String sourcePath, String source, String destPath) { |
| var destDir = new Directory(p.dirname(destPath)); |
| destDir.createSync(recursive: true); |
| - // TODO(rnystrom): Do real async/await transformation here! |
| - source = source.replaceAll("ASYNC!", ""); |
| + if (p.isWithin(p.join(sourceDir, "asset"), sourcePath)) { |
| + // Don't run the async compiler on the special "asset" source files. These |
| + // have preprocessor comments that get discarded by the compiler. |
|
nweiz
2014/08/27 20:10:07
Maybe factor this into a function so you can short
Bob Nystrom
2014/08/27 21:35:31
Done.
|
| + } else { |
| + try { |
| + source = async_await.compile(source); |
| + } catch (ex) { |
| + stderr.writeln("Async compile failed on $sourcePath:\n$ex"); |
| + hadFailure = true; |
| + |
| + // If the async compile fails, delete the file so that we don't try to |
| + // run the stale previous output and so that we try to recompile it later. |
| + try { |
| + new File(destPath).deleteSync(); |
| + } on IOException catch (ex) { |
| + // Do nothing. This may happen if two instances of the compiler are running |
|
nweiz
2014/08/27 20:10:07
Long lines.
Bob Nystrom
2014/08/27 21:35:32
Done.
|
| + // concurrently and compile the same file. The second one to try to write |
| + // the output may fail if the file is still open. Since they are producing |
|
nweiz
2014/08/27 20:10:07
"write the output" -> "delete the file"
Bob Nystrom
2014/08/27 21:35:32
Done.
|
| + // the same output anyway, just ignore it when the second one fails. |
| + } |
| + |
| + return; |
| + } |
| + } |
| // Pub imports dart2js using relative imports that reach outside of pub's |
| // source tree. Since the build directory is in a different location, we need |