Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library rasta.rastask; | 5 library rasta.rastask; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:io' show | 10 import 'dart:io' show |
| 11 File, | 11 File, |
| 12 IOSink; | 12 IOSink; |
| 13 | 13 |
| 14 import 'package:compiler/compiler_new.dart' show | |
| 15 Diagnostic; | |
| 16 | |
| 17 import 'package:compiler/src/diagnostics/diagnostic_listener.dart' show | |
| 18 DiagnosticMessage; | |
| 19 | |
| 14 import 'package:compiler/src/common/tasks.dart' show | 20 import 'package:compiler/src/common/tasks.dart' show |
| 15 CompilerTask; | 21 CompilerTask; |
| 16 | 22 |
| 17 import 'package:compiler/src/elements/elements.dart' show | 23 import 'package:compiler/src/elements/elements.dart' show |
| 18 CompilationUnitElement, | 24 CompilationUnitElement, |
| 25 Element, | |
| 19 LibraryElement; | 26 LibraryElement; |
| 20 | 27 |
| 21 import 'package:kernel/ast.dart' as ir; | 28 import 'package:kernel/ast.dart' as ir; |
| 22 | 29 |
| 23 import 'package:kernel/binary/ast_to_binary.dart' show | 30 import 'package:kernel/binary/ast_to_binary.dart' show |
| 24 BinaryPrinter; | 31 BinaryPrinter; |
| 25 | 32 |
| 26 import 'package:kernel/text/ast_to_text.dart' show | 33 import 'package:kernel/text/ast_to_text.dart' show |
| 27 Printer; | 34 Printer; |
| 28 | 35 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 54 } | 61 } |
| 55 print("Wrote $uri"); | 62 print("Wrote $uri"); |
| 56 } | 63 } |
| 57 | 64 |
| 58 abstract class Rastask extends CompilerTask { | 65 abstract class Rastask extends CompilerTask { |
| 59 final Stopwatch wallClock; | 66 final Stopwatch wallClock; |
| 60 final Options globalOptions; | 67 final Options globalOptions; |
| 61 Duration setupDuration; | 68 Duration setupDuration; |
| 62 Kernel kernel; | 69 Kernel kernel; |
| 63 ir.Library coreLibrary; | 70 ir.Library coreLibrary; |
| 71 bool hasCompileTimeErrors = false; | |
| 64 | 72 |
| 65 Rastask(CustomCompiler compiler, this.wallClock, this.globalOptions) | 73 Rastask(CustomCompiler compiler, this.wallClock, this.globalOptions) |
| 66 : super(compiler); | 74 : super(compiler); |
| 67 | 75 |
| 68 String get name => "rastak"; | 76 String get name => "rastak"; |
| 69 | 77 |
| 70 CustomCompiler get compiler => super.compiler; | 78 CustomCompiler get compiler => super.compiler; |
| 71 | 79 |
| 72 Future run(); | 80 Future run(); |
| 73 | 81 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 86 "${(wallClock.elapsedMilliseconds).toStringAsFixed(3)}ms"); | 94 "${(wallClock.elapsedMilliseconds).toStringAsFixed(3)}ms"); |
| 87 } | 95 } |
| 88 | 96 |
| 89 Future<ir.Library> loadLibrary(Uri uri) async { | 97 Future<ir.Library> loadLibrary(Uri uri) async { |
| 90 ir.Library library = await kernel.loadLibrary(uri); | 98 ir.Library library = await kernel.loadLibrary(uri); |
| 91 kernel.processWorkQueue(); | 99 kernel.processWorkQueue(); |
| 92 return library; | 100 return library; |
| 93 } | 101 } |
| 94 | 102 |
| 95 Future<ir.TreeNode> runOne(Options options) async { | 103 Future<ir.TreeNode> runOne(Options options) async { |
| 104 hasCompileTimeErrors = false; | |
| 96 ir.Library library = await loadLibrary(options.input); | 105 ir.Library library = await loadLibrary(options.input); |
| 97 | 106 |
| 98 bool generateLibrary = options.generateLibrary; | 107 bool generateLibrary = options.generateLibrary; |
| 99 if (generateLibrary == null) { | 108 if (generateLibrary == null) { |
| 100 generateLibrary = !kernel.hasMainMethod(options.input); | 109 generateLibrary = !kernel.hasMainMethod(options.input); |
| 101 } | 110 } |
| 102 if (!generateLibrary && !kernel.hasMainMethod(options.input)) { | 111 if (!generateLibrary && !kernel.hasMainMethod(options.input)) { |
| 103 throw "No main method in ${options.input}."; | 112 throw "No main method in ${options.input}."; |
| 104 } | 113 } |
| 105 | 114 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 134 if (options.dependenciesFile != null) { | 143 if (options.dependenciesFile != null) { |
| 135 await openWrite(options.dependenciesFile, (IOSink sink) { | 144 await openWrite(options.dependenciesFile, (IOSink sink) { |
| 136 void writeCompilationUnit(CompilationUnitElement unit) { | 145 void writeCompilationUnit(CompilationUnitElement unit) { |
| 137 sink.write("${unit.script.resourceUri}\n"); | 146 sink.write("${unit.script.resourceUri}\n"); |
| 138 } | 147 } |
| 139 kernel.forEachLibraryElement((LibraryElement library) { | 148 kernel.forEachLibraryElement((LibraryElement library) { |
| 140 library.compilationUnits.forEach(writeCompilationUnit); | 149 library.compilationUnits.forEach(writeCompilationUnit); |
| 141 }); | 150 }); |
| 142 }); | 151 }); |
| 143 } | 152 } |
| 153 Set<ir.Library> libraries = new Set<ir.Library>.from( | |
| 154 generateLibrary ? <ir.Library>[library] : program.libraries); | |
| 155 compiler.elementsWithCompileTimeErrors.forEach( | |
| 156 (Element element, List<DiagnosticMessage> messages) { | |
| 157 ir.Library library = kernel.libraries[element.library]; | |
| 158 if (libraries.contains(library)) { | |
| 159 for (DiagnosticMessage diagnostic in messages) { | |
|
kasperl
2016/08/04 11:14:13
Can messages be empty? Maybe move hasCompileTimeEr
ahe
2016/08/04 11:32:45
I'll address this in a follow-up CL.
ahe
2016/08/04 12:15:32
Thank you, I've created CL 2213913002 for this.
| |
| 160 hasCompileTimeErrors = true; | |
| 161 compiler.reportDiagnostic( | |
| 162 diagnostic, const <DiagnosticMessage>[], Diagnostic.ERROR); | |
| 163 } | |
| 164 } | |
| 165 }); | |
| 144 return generateLibrary ? library : program; | 166 return generateLibrary ? library : program; |
| 145 } | 167 } |
| 146 | 168 |
| 147 static Future<Rastask> create( | 169 static Future<Rastask> create( |
| 148 Stopwatch wallClock, | 170 Stopwatch wallClock, |
| 149 List<String> arguments) async { | 171 List<String> arguments) async { |
| 150 Options options = await new OptionParser(arguments, Uri.base).parse(); | 172 Options options = await new OptionParser(arguments, Uri.base).parse(); |
| 151 List<String> compilerOptions = | 173 List<String> compilerOptions = |
| 152 options.isVerbose ? <String>['--verbose'] : <String>[]; | 174 options.isVerbose ? <String>['--verbose'] : <String>[]; |
| 153 IoCompilerFactory factory = new IoCompilerFactory( | 175 IoCompilerFactory factory = new IoCompilerFactory( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 165 Rastask task; | 187 Rastask task; |
| 166 if (options.isBatch) { | 188 if (options.isBatch) { |
| 167 task = new RunBatch(compiler, wallClock, options); | 189 task = new RunBatch(compiler, wallClock, options); |
| 168 } else { | 190 } else { |
| 169 task = new RunSingle(compiler, wallClock, options); | 191 task = new RunSingle(compiler, wallClock, options); |
| 170 } | 192 } |
| 171 compiler.tasks.add(task); | 193 compiler.tasks.add(task); |
| 172 return task; | 194 return task; |
| 173 } | 195 } |
| 174 } | 196 } |
| OLD | NEW |