| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library dartino_compiler_blaze; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'dart:convert' show | |
| 10 LineSplitter, | |
| 11 UTF8; | |
| 12 | |
| 13 import 'dart:io'; | |
| 14 | |
| 15 import 'package:dartino_compiler/session.dart' show | |
| 16 Session; | |
| 17 | |
| 18 import 'package:dartino_compiler/src/hub/session_manager.dart'; | |
| 19 | |
| 20 import 'package:dartino_compiler/src/worker/developer.dart' show | |
| 21 Address, | |
| 22 Settings, | |
| 23 SessionState; | |
| 24 | |
| 25 import 'package:dartino_compiler/src/worker/developer.dart' as developer; | |
| 26 | |
| 27 import 'package:dartino_compiler/src/verbs/infrastructure.dart' show | |
| 28 fileUri; | |
| 29 | |
| 30 import 'package:compiler/src/filenames.dart' show | |
| 31 appendSlash; | |
| 32 | |
| 33 class DartinoRunner { | |
| 34 | |
| 35 Future<int> run(List<String> arguments) async { | |
| 36 int debugPort; | |
| 37 String packages; | |
| 38 String snapshot; | |
| 39 String script; | |
| 40 Uri libraryRoot; | |
| 41 Uri dartinoVm; | |
| 42 Uri nativesJson; | |
| 43 | |
| 44 for (int i = 0; i < arguments.length; ++i) { | |
| 45 String arg = arguments[i]; | |
| 46 if (arg == "--debug") { | |
| 47 if (debugPort != null) throw "Cannot supply multiple debug ports"; | |
| 48 debugPort = int.parse(arguments[++i]); | |
| 49 } else if (arg == "--packages") { | |
| 50 if (packages != null) throw "Cannot supply multiple package files"; | |
| 51 packages = arguments[++i]; | |
| 52 } else if (arg == "--snapshot") { | |
| 53 if (snapshot != null) throw "Cannot export to multiple snapshot files"; | |
| 54 snapshot = arguments[++i]; | |
| 55 } else if (arg == "--library-root") { | |
| 56 if (libraryRoot != null) throw "Cannot use multiple library roots"; | |
| 57 libraryRoot = Uri.base.resolve(appendSlash(arguments[++i])); | |
| 58 } else if (arg == "--patch-root") { | |
| 59 throw "--patch-root not supported anymore"; | |
| 60 } else if (arg == "--dartino-vm") { | |
| 61 if (dartinoVm != null) throw "Cannot use multiple Dartino VMs"; | |
| 62 dartinoVm = Uri.base.resolve(arguments[++i]); | |
| 63 } else if (arg == "--natives-json") { | |
| 64 if (nativesJson != null) throw "Cannot use multiple natives json files"; | |
| 65 nativesJson = Uri.base.resolve(arguments[++i]); | |
| 66 } else if (arg.startsWith("-")) { | |
| 67 throw "Unknown option $arg"; | |
| 68 } else { | |
| 69 if (script != null) throw "Cannot run multiple scripts"; | |
| 70 script = arg; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 if (script == null) { | |
| 75 throw "Supply a script to run"; | |
| 76 } | |
| 77 | |
| 78 if (packages == null) { | |
| 79 packages = ".packages"; | |
| 80 } | |
| 81 | |
| 82 Address device = | |
| 83 (debugPort != null) ? new Address("localhost", debugPort) : null; | |
| 84 | |
| 85 Settings settings = new Settings( | |
| 86 fileUri(packages, Uri.base), <String>["--verbose"], null, device, null); | |
| 87 | |
| 88 SessionState state = developer.createSessionState( | |
| 89 "dartino_compiler-blaze", | |
| 90 settings, | |
| 91 libraryRoot: libraryRoot, | |
| 92 dartinoVm: dartinoVm, | |
| 93 nativesJson: nativesJson); | |
| 94 | |
| 95 int result = await developer.compile(fileUri(script, Uri.base), state); | |
| 96 | |
| 97 if (result != 0) { | |
| 98 print(state.getLog()); | |
| 99 return result; | |
| 100 } | |
| 101 | |
| 102 if (device != null) { | |
| 103 await developer.attachToVm(device.host, device.port, state); | |
| 104 state.stdoutSink.attachCommandSender(stdout.add); | |
| 105 state.stderrSink.attachCommandSender(stderr.add); | |
| 106 | |
| 107 Session session = state.session; | |
| 108 for (DartinoDelta delta in state.compilationResults) { | |
| 109 await session.applyDelta(delta); | |
| 110 } | |
| 111 | |
| 112 var input = stdin.transform(UTF8.decoder).transform(new LineSplitter()); | |
| 113 await session.debug(input); | |
| 114 } else { | |
| 115 await developer.startAndAttachDirectly(state); | |
| 116 state.stdoutSink.attachCommandSender(stdout.add); | |
| 117 state.stderrSink.attachCommandSender(stderr.add); | |
| 118 | |
| 119 if (snapshot != null) { | |
| 120 await developer.export(state, fileUri(snapshot, Uri.base)); | |
| 121 } else { | |
| 122 await developer.run(state); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 return result; | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 main(List<String> arguments) async { | |
| 131 return await new DartinoRunner().run(arguments); | |
| 132 } | |
| OLD | NEW |