Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.runner; | 5 package com.google.dart.runner; |
| 6 | 6 |
| 7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
| 8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
| 9 import com.google.common.io.CharStreams; | 9 import com.google.common.io.CharStreams; |
| 10 import com.google.common.io.Files; | 10 import com.google.common.io.Files; |
| 11 import com.google.dart.compiler.Backend; | 11 import com.google.dart.compiler.Backend; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 + dir + ": Permission denied."); | 151 + dir + ": Permission denied."); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 try { | 154 try { |
| 155 Files.write(compiled.js, outFile, Charset.defaultCharset()); | 155 Files.write(compiled.js, outFile, Charset.defaultCharset()); |
| 156 } catch (IOException e) { | 156 } catch (IOException e) { |
| 157 throw new RunnerError(e); | 157 throw new RunnerError(e); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (!options.shouldCompileOnly()) { | 161 if (!options.shouldCompileOnly() && !options.checkOnly()) { |
| 162 runApp(compiled, app.getName(), options, scriptArguments.toArray(new Strin g[0]), | 162 runApp(compiled, app.getName(), options, scriptArguments.toArray(new Strin g[0]), |
| 163 stdout, stderr); | 163 stdout, stderr); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 private static void printUsageAndThrow(CmdLineParser cmdLineParser, String rea son) | 167 private static void printUsageAndThrow(CmdLineParser cmdLineParser, String rea son) |
| 168 throws RunnerError { | 168 throws RunnerError { |
| 169 | 169 |
| 170 StringBuilder usage = new StringBuilder(); | 170 StringBuilder usage = new StringBuilder(); |
| 171 usage.append(reason); | 171 usage.append(reason); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 | 235 |
| 236 public static void compileAndRunApp(LibrarySource app, | 236 public static void compileAndRunApp(LibrarySource app, |
| 237 DartRunnerOptions options, | 237 DartRunnerOptions options, |
| 238 CompilerConfiguration config, | 238 CompilerConfiguration config, |
| 239 DartCompilerListener listener, | 239 DartCompilerListener listener, |
| 240 String[] dartArguments, | 240 String[] dartArguments, |
| 241 PrintStream stdout, | 241 PrintStream stdout, |
| 242 PrintStream stderr) | 242 PrintStream stderr) |
| 243 throws RunnerError { | 243 throws RunnerError { |
| 244 CompilationResult compiled = compileApp( | 244 CompilationResult compiled = compileApp( |
| 245 app, Collections.<LibrarySource>emptyList(), config, listener); | 245 app, Collections.<LibrarySource>emptyList(), config, listener, options); |
| 246 runApp(compiled, app.getName(), options, dartArguments, stdout, stderr); | 246 runApp(compiled, app.getName(), options, dartArguments, stdout, stderr); |
| 247 } | 247 } |
| 248 | 248 |
| 249 private static void runApp(CompilationResult compiled, | 249 private static void runApp(CompilationResult compiled, |
| 250 String sourceName, | 250 String sourceName, |
| 251 DartRunnerOptions options, | 251 DartRunnerOptions options, |
| 252 String[] scriptArguments, | 252 String[] scriptArguments, |
| 253 PrintStream stdout, | 253 PrintStream stdout, |
| 254 PrintStream stderr) | 254 PrintStream stderr) |
| 255 throws RunnerError { | 255 throws RunnerError { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 286 @Override | 286 @Override |
| 287 public boolean expectEntryPoint() { | 287 public boolean expectEntryPoint() { |
| 288 return true; | 288 return true; |
| 289 } | 289 } |
| 290 | 290 |
| 291 @Override | 291 @Override |
| 292 public boolean typeErrorsAreFatal() { | 292 public boolean typeErrorsAreFatal() { |
| 293 return options.typeErrorsAreFatal(); | 293 return options.typeErrorsAreFatal(); |
| 294 } | 294 } |
| 295 }; | 295 }; |
| 296 return compileApp(app, imports, config, listener); | 296 return compileApp(app, imports, config, listener, options); |
| 297 } | 297 } |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * Parses and compiles an application to Javascript. | 300 * Parses and compiles an application to Javascript. |
| 301 */ | 301 */ |
| 302 private static CompilationResult compileApp(LibrarySource app, | 302 private static CompilationResult compileApp(LibrarySource app, |
| 303 List<LibrarySource> imports, | 303 List<LibrarySource> imports, |
| 304 CompilerConfiguration config, | 304 CompilerConfiguration config, |
| 305 DartCompilerListener listener) thr ows RunnerError { | 305 DartCompilerListener listener, |
| 306 final DartRunnerOptions options) t hrows RunnerError { | |
|
scheglov
2012/02/06 13:09:54
Would be good to use same order or arguments as in
zundel
2012/02/06 16:01:56
Done.
| |
| 306 try { | 307 try { |
| 307 final RunnerDartArtifactProvider provider = new RunnerDartArtifactProvider (); | 308 final RunnerDartArtifactProvider provider = new RunnerDartArtifactProvider (); |
| 308 String errmsg = DartCompiler.compileLib(app, imports, config, provider, li stener); | 309 String errmsg = DartCompiler.compileLib(app, imports, config, provider, li stener); |
| 309 if (errmsg != null) { | 310 if (errmsg != null) { |
| 310 throw new RunnerError(errmsg); | 311 throw new RunnerError(errmsg); |
| 311 } | 312 } |
| 312 Backend backend = config.getBackends().get(0); | 313 Backend backend = config.getBackends().get(0); |
| 313 | 314 |
| 314 SourceMapping mapping = null; | 315 SourceMapping mapping = null; |
| 315 if (config.getCompilerOptions().generateSourceMaps()) { | 316 if (config.getCompilerOptions().generateSourceMaps()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 330 | 331 |
| 331 }); | 332 }); |
| 332 } catch (SourceMapParseException e) { | 333 } catch (SourceMapParseException e) { |
| 333 throw new AssertionError(e); | 334 throw new AssertionError(e); |
| 334 } finally { | 335 } finally { |
| 335 mr.close(); | 336 mr.close(); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension()); | 341 if (!options.checkOnly()) { |
| 341 String js = CharStreams.toString(r); | 342 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension() ); |
| 342 r.close(); | 343 String js = CharStreams.toString(r); |
| 343 return new CompilationResult(js, mapping); | 344 r.close(); |
| 345 return new CompilationResult(js, mapping); | |
| 346 } | |
| 347 return null; | |
| 344 } catch (IOException e) { | 348 } catch (IOException e) { |
| 345 // This can't happen; it's just a StringWriter. | 349 // This can't happen; it's just a StringWriter. |
| 346 throw new AssertionError(e); | 350 throw new AssertionError(e); |
| 347 } | 351 } |
| 348 } | 352 } |
| 349 } | 353 } |
| OLD | NEW |