| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.test.memory_compiler; | 5 library dart2js.test.memory_compiler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:compiler/compiler.dart' show | 9 import 'package:compiler/compiler.dart' show |
| 10 DiagnosticHandler; | 10 DiagnosticHandler; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 String text, Diagnostic kind) { | 93 String text, Diagnostic kind) { |
| 94 for (CompilerDiagnostics diagnostics in diagnosticsList) { | 94 for (CompilerDiagnostics diagnostics in diagnosticsList) { |
| 95 diagnostics.report(message, uri, begin, end, text, kind); | 95 diagnostics.report(message, uri, begin, end, text, kind); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 CompilerDiagnostics createCompilerDiagnostics( | 100 CompilerDiagnostics createCompilerDiagnostics( |
| 101 CompilerDiagnostics diagnostics, | 101 CompilerDiagnostics diagnostics, |
| 102 SourceFileProvider provider, | 102 SourceFileProvider provider, |
| 103 bool showDiagnostics) { | 103 {bool showDiagnostics: true, |
| 104 bool verbose: false}) { |
| 104 CompilerDiagnostics handler = diagnostics; | 105 CompilerDiagnostics handler = diagnostics; |
| 105 if (showDiagnostics) { | 106 if (showDiagnostics) { |
| 106 if (diagnostics == null) { | 107 if (diagnostics == null) { |
| 107 handler = new FormattingDiagnosticHandler(provider); | 108 handler = new FormattingDiagnosticHandler(provider)..verbose = verbose; |
| 108 } else { | 109 } else { |
| 109 var formattingHandler = new FormattingDiagnosticHandler(provider); | 110 var formattingHandler = |
| 111 new FormattingDiagnosticHandler(provider)..verbose = verbose; |
| 110 handler = new MultiDiagnostics([diagnostics, formattingHandler]); | 112 handler = new MultiDiagnostics([diagnostics, formattingHandler]); |
| 111 } | 113 } |
| 112 } else if (diagnostics == null) { | 114 } else if (diagnostics == null) { |
| 113 handler = new MultiDiagnostics(); | 115 handler = new MultiDiagnostics(); |
| 114 } | 116 } |
| 115 return handler; | 117 return handler; |
| 116 } | 118 } |
| 117 | 119 |
| 118 Expando<MemorySourceFileProvider> expando = | 120 Expando<MemorySourceFileProvider> expando = |
| 119 new Expando<MemorySourceFileProvider>(); | 121 new Expando<MemorySourceFileProvider>(); |
| 120 | 122 |
| 121 Future<CompilationResult> runCompiler( | 123 Future<CompilationResult> runCompiler( |
| 122 {Map<String, String> memorySourceFiles: const <String, String>{}, | 124 {Map<String, String> memorySourceFiles: const <String, String>{}, |
| 123 Uri entryPoint, | 125 Uri entryPoint, |
| 124 List<Uri> entryPoints, | 126 List<Uri> entryPoints, |
| 125 CompilerDiagnostics diagnosticHandler, | 127 CompilerDiagnostics diagnosticHandler, |
| 126 CompilerOutput outputProvider, | 128 CompilerOutput outputProvider, |
| 127 List<String> options: const <String>[], | 129 List<String> options: const <String>[], |
| 128 Compiler cachedCompiler, | 130 Compiler cachedCompiler, |
| 129 bool showDiagnostics: true, | 131 bool showDiagnostics: true, |
| 130 Uri packageRoot, | 132 Uri packageRoot, |
| 131 Uri packageConfig, | 133 Uri packageConfig, |
| 132 PackagesDiscoveryProvider packagesDiscoveryProvider, | 134 PackagesDiscoveryProvider packagesDiscoveryProvider, |
| 133 void beforeRun(Compiler compiler)}) async { | 135 void beforeRun(Compiler compiler)}) async { |
| 134 if (entryPoint == null) { | 136 if (entryPoint == null) { |
| 135 entryPoint = Uri.parse('memory:main.dart'); | 137 entryPoint = Uri.parse('memory:main.dart'); |
| 136 } | 138 } |
| 137 Compiler compiler = compilerFor( | 139 Compiler compiler = compilerFor( |
| 138 memorySourceFiles, | 140 memorySourceFiles: memorySourceFiles, |
| 139 diagnosticHandler: diagnosticHandler, | 141 diagnosticHandler: diagnosticHandler, |
| 140 outputProvider: outputProvider, | 142 outputProvider: outputProvider, |
| 141 options: options, | 143 options: options, |
| 142 cachedCompiler: cachedCompiler, | 144 cachedCompiler: cachedCompiler, |
| 143 showDiagnostics: showDiagnostics, | 145 showDiagnostics: showDiagnostics, |
| 144 packageRoot: packageRoot, | 146 packageRoot: packageRoot, |
| 145 packageConfig: packageConfig, | 147 packageConfig: packageConfig, |
| 146 packagesDiscoveryProvider: packagesDiscoveryProvider); | 148 packagesDiscoveryProvider: packagesDiscoveryProvider); |
| 147 compiler.librariesToAnalyzeWhenRun = entryPoints; | 149 compiler.librariesToAnalyzeWhenRun = entryPoints; |
| 148 if (beforeRun != null) { | 150 if (beforeRun != null) { |
| 149 beforeRun(compiler); | 151 beforeRun(compiler); |
| 150 } | 152 } |
| 151 bool isSuccess = await compiler.run(entryPoint); | 153 bool isSuccess = await compiler.run(entryPoint); |
| 152 return new CompilationResult(compiler, isSuccess: isSuccess); | 154 return new CompilationResult(compiler, isSuccess: isSuccess); |
| 153 } | 155 } |
| 154 | 156 |
| 155 Compiler compilerFor( | 157 Compiler compilerFor( |
| 156 Map<String, String> memorySourceFiles, | 158 {Map<String, String> memorySourceFiles: const <String, String>{}, |
| 157 {CompilerDiagnostics diagnosticHandler, | 159 CompilerDiagnostics diagnosticHandler, |
| 158 CompilerOutput outputProvider, | 160 CompilerOutput outputProvider, |
| 159 List<String> options: const <String>[], | 161 List<String> options: const <String>[], |
| 160 Compiler cachedCompiler, | 162 Compiler cachedCompiler, |
| 161 bool showDiagnostics: true, | 163 bool showDiagnostics: true, |
| 162 Uri packageRoot, | 164 Uri packageRoot, |
| 163 Uri packageConfig, | 165 Uri packageConfig, |
| 164 PackagesDiscoveryProvider packagesDiscoveryProvider}) { | 166 PackagesDiscoveryProvider packagesDiscoveryProvider}) { |
| 165 Uri libraryRoot = Uri.base.resolve('sdk/'); | 167 Uri libraryRoot = Uri.base.resolve('sdk/'); |
| 166 if (packageRoot == null && | 168 if (packageRoot == null && |
| 167 packageConfig == null && | 169 packageConfig == null && |
| 168 packagesDiscoveryProvider == null) { | 170 packagesDiscoveryProvider == null) { |
| 169 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/')); | 171 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/')); |
| 170 } | 172 } |
| 171 | 173 |
| 172 MemorySourceFileProvider provider; | 174 MemorySourceFileProvider provider; |
| 173 if (cachedCompiler == null) { | 175 if (cachedCompiler == null) { |
| 174 provider = new MemorySourceFileProvider(memorySourceFiles); | 176 provider = new MemorySourceFileProvider(memorySourceFiles); |
| 175 // Saving the provider in case we need it later for a cached compiler. | 177 // Saving the provider in case we need it later for a cached compiler. |
| 176 expando[provider] = provider; | 178 expando[provider] = provider; |
| 177 } else { | 179 } else { |
| 178 // When using a cached compiler, it has read a number of files from disk | 180 // When using a cached compiler, it has read a number of files from disk |
| 179 // already (and will not attempt to read them again due to caching). These | 181 // already (and will not attempt to read them again due to caching). These |
| 180 // files must be available to the new diagnostic handler. | 182 // files must be available to the new diagnostic handler. |
| 181 provider = expando[cachedCompiler.provider]; | 183 provider = expando[cachedCompiler.provider]; |
| 182 provider.memorySourceFiles = memorySourceFiles; | 184 provider.memorySourceFiles = memorySourceFiles; |
| 183 } | 185 } |
| 184 diagnosticHandler = | 186 diagnosticHandler = createCompilerDiagnostics( |
| 185 createCompilerDiagnostics(diagnosticHandler, provider, showDiagnostics); | 187 diagnosticHandler, provider, |
| 188 showDiagnostics: showDiagnostics, |
| 189 verbose: options.contains('-v') || options.contains('--verbose')); |
| 186 | 190 |
| 187 if (outputProvider == null) { | 191 if (outputProvider == null) { |
| 188 outputProvider = const NullCompilerOutput(); | 192 outputProvider = const NullCompilerOutput(); |
| 189 } | 193 } |
| 190 | 194 |
| 191 Compiler compiler = new Compiler( | 195 Compiler compiler = new Compiler( |
| 192 provider, | 196 provider, |
| 193 outputProvider, | 197 outputProvider, |
| 194 diagnosticHandler, | 198 diagnosticHandler, |
| 195 libraryRoot, | 199 libraryRoot, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 327 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 324 | 328 |
| 325 List<Uri> libraries = <Uri>[]; | 329 List<Uri> libraries = <Uri>[]; |
| 326 memorySourceFiles.forEach((String path, _) { | 330 memorySourceFiles.forEach((String path, _) { |
| 327 libraries.add(new Uri(scheme: 'memory', path: path)); | 331 libraries.add(new Uri(scheme: 'memory', path: path)); |
| 328 }); | 332 }); |
| 329 | 333 |
| 330 return analyze(libraries, libraryRoot, packageRoot, | 334 return analyze(libraries, libraryRoot, packageRoot, |
| 331 provider, handler, options); | 335 provider, handler, options); |
| 332 } | 336 } |
| OLD | NEW |