OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 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 | 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 fletchc.worker.developer; | 5 library dartino_compiler.worker.developer; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future, | 8 Future, |
9 Stream, | 9 Stream, |
10 StreamController, | 10 StreamController, |
11 Timer; | 11 Timer; |
12 | 12 |
13 import 'dart:convert' show | 13 import 'dart:convert' show |
14 JSON, | 14 JSON, |
15 JsonEncoder, | 15 JsonEncoder, |
16 UTF8; | 16 UTF8; |
17 | 17 |
18 import 'dart:io' show | 18 import 'dart:io' show |
19 Directory, | 19 Directory, |
20 File, | 20 File, |
21 FileSystemEntity, | 21 FileSystemEntity, |
22 InternetAddress, | 22 InternetAddress, |
23 Platform, | 23 Platform, |
24 Process, | 24 Process, |
25 Socket, | 25 Socket, |
26 SocketException; | 26 SocketException; |
27 | 27 |
28 import 'package:sdk_library_metadata/libraries.dart' show | 28 import 'package:sdk_library_metadata/libraries.dart' show |
29 Category; | 29 Category; |
30 | 30 |
31 import 'package:sdk_services/sdk_services.dart' show | 31 import 'package:sdk_services/sdk_services.dart' show |
32 OutputService, | 32 OutputService, |
33 SDKServices; | 33 SDKServices; |
34 | 34 |
35 import 'package:fletch_agent/agent_connection.dart' show | 35 import 'package:dartino_agent/agent_connection.dart' show |
36 AgentConnection, | 36 AgentConnection, |
37 AgentException, | 37 AgentException, |
38 VmData; | 38 VmData; |
39 | 39 |
40 import 'package:fletch_agent/messages.dart' show | 40 import 'package:dartino_agent/messages.dart' show |
41 AGENT_DEFAULT_PORT, | 41 AGENT_DEFAULT_PORT, |
42 MessageDecodeException; | 42 MessageDecodeException; |
43 | 43 |
44 import 'package:mdns/mdns.dart' show | 44 import 'package:mdns/mdns.dart' show |
45 MDnsClient, | 45 MDnsClient, |
46 ResourceRecord, | 46 ResourceRecord, |
47 RRType; | 47 RRType; |
48 | 48 |
49 import 'package:path/path.dart' show | 49 import 'package:path/path.dart' show |
50 join; | 50 join; |
(...skipping 11 matching lines...) Expand all Loading... |
62 WriteSnapshotResult; | 62 WriteSnapshotResult; |
63 | 63 |
64 import '../../program_info.dart' show | 64 import '../../program_info.dart' show |
65 Configuration, | 65 Configuration, |
66 ProgramInfo, | 66 ProgramInfo, |
67 ProgramInfoBinary, | 67 ProgramInfoBinary, |
68 ProgramInfoJson, | 68 ProgramInfoJson, |
69 buildProgramInfo; | 69 buildProgramInfo; |
70 | 70 |
71 import '../hub/session_manager.dart' show | 71 import '../hub/session_manager.dart' show |
72 FletchVm, | 72 DartinoVm, |
73 SessionState, | 73 SessionState, |
74 Sessions; | 74 Sessions; |
75 | 75 |
76 import '../hub/client_commands.dart' show | 76 import '../hub/client_commands.dart' show |
77 ClientCommandCode, | 77 ClientCommandCode, |
78 handleSocketErrors; | 78 handleSocketErrors; |
79 | 79 |
80 import '../verbs/infrastructure.dart' show | 80 import '../verbs/infrastructure.dart' show |
81 ClientCommand, | 81 ClientCommand, |
82 CommandSender, | 82 CommandSender, |
83 DiagnosticKind, | 83 DiagnosticKind, |
84 FletchCompiler, | 84 DartinoCompiler, |
85 FletchDelta, | 85 DartinoDelta, |
86 IncrementalCompiler, | 86 IncrementalCompiler, |
87 WorkerConnection, | 87 WorkerConnection, |
88 IsolatePool, | 88 IsolatePool, |
89 Session, | 89 Session, |
90 SharedTask, | 90 SharedTask, |
91 StreamIterator, | 91 StreamIterator, |
92 throwFatalError; | 92 throwFatalError; |
93 | 93 |
94 import '../../incremental/fletchc_incremental.dart' show | 94 import '../../incremental/dartino_compiler_incremental.dart' show |
95 IncrementalCompilationFailed, | 95 IncrementalCompilationFailed, |
96 IncrementalMode, | 96 IncrementalMode, |
97 parseIncrementalMode, | 97 parseIncrementalMode, |
98 unparseIncrementalMode; | 98 unparseIncrementalMode; |
99 | 99 |
100 export '../../incremental/fletchc_incremental.dart' show | 100 export '../../incremental/dartino_compiler_incremental.dart' show |
101 IncrementalMode; | 101 IncrementalMode; |
102 | 102 |
103 import '../../fletch_compiler.dart' show fletchDeviceType; | 103 import '../../dartino_compiler.dart' show dartinoDeviceType; |
104 | 104 |
105 import '../hub/exit_codes.dart' as exit_codes; | 105 import '../hub/exit_codes.dart' as exit_codes; |
106 | 106 |
107 import '../../fletch_system.dart' show | 107 import '../../dartino_system.dart' show |
108 FletchFunction, | 108 DartinoFunction, |
109 FletchSystem; | 109 DartinoSystem; |
110 | 110 |
111 import '../../bytecodes.dart' show | 111 import '../../bytecodes.dart' show |
112 Bytecode, | 112 Bytecode, |
113 MethodEnd; | 113 MethodEnd; |
114 | 114 |
115 import '../diagnostic.dart' show | 115 import '../diagnostic.dart' show |
116 throwInternalError; | 116 throwInternalError; |
117 | 117 |
118 import '../guess_configuration.dart' show | 118 import '../guess_configuration.dart' show |
119 executable, | 119 executable, |
120 fletchVersion, | 120 dartinoVersion, |
121 guessFletchVm; | 121 guessDartinoVm; |
122 | 122 |
123 import '../device_type.dart' show | 123 import '../device_type.dart' show |
124 DeviceType, | 124 DeviceType, |
125 parseDeviceType, | 125 parseDeviceType, |
126 unParseDeviceType; | 126 unParseDeviceType; |
127 | 127 |
128 export '../device_type.dart' show | 128 export '../device_type.dart' show |
129 DeviceType; | 129 DeviceType; |
130 | 130 |
131 import '../please_report_crash.dart' show | 131 import '../please_report_crash.dart' show |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 disconnectFromAgent(connection); | 198 disconnectFromAgent(connection); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 void disconnectFromAgent(AgentConnection connection) { | 202 void disconnectFromAgent(AgentConnection connection) { |
203 assert(connection.socket != null); | 203 assert(connection.socket != null); |
204 connection.socket.close(); | 204 connection.socket.close(); |
205 } | 205 } |
206 | 206 |
207 Future<Null> checkAgentVersion(Uri base, SessionState state) async { | 207 Future<Null> checkAgentVersion(Uri base, SessionState state) async { |
208 String deviceFletchVersion = await withAgentConnection(state, | 208 String deviceDartinoVersion = await withAgentConnection(state, |
209 (connection) => connection.fletchVersion()); | 209 (connection) => connection.dartinoVersion()); |
210 Uri packageFile = await lookForAgentPackage(base, version: fletchVersion); | 210 Uri packageFile = await lookForAgentPackage(base, version: dartinoVersion); |
211 String fixit; | 211 String fixit; |
212 if (packageFile != null) { | 212 if (packageFile != null) { |
213 fixit = "Try running\n" | 213 fixit = "Try running\n" |
214 " 'fletch x-upgrade agent in session ${state.name}'."; | 214 " 'dartino x-upgrade agent in session ${state.name}'."; |
215 } else { | 215 } else { |
216 fixit = "Try downloading a matching SDK and running\n" | 216 fixit = "Try downloading a matching SDK and running\n" |
217 " 'fletch x-upgrade agent in session ${state.name}'\n" | 217 " 'dartino x-upgrade agent in session ${state.name}'\n" |
218 "from the SDK's root directory."; | 218 "from the SDK's root directory."; |
219 } | 219 } |
220 | 220 |
221 if (fletchVersion != deviceFletchVersion) { | 221 if (dartinoVersion != deviceDartinoVersion) { |
222 throwFatalError(DiagnosticKind.agentVersionMismatch, | 222 throwFatalError(DiagnosticKind.agentVersionMismatch, |
223 userInput: fletchVersion, | 223 userInput: dartinoVersion, |
224 additionalUserInput: deviceFletchVersion, | 224 additionalUserInput: deviceDartinoVersion, |
225 fixit: fixit); | 225 fixit: fixit); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 Future<Null> startAndAttachViaAgent(Uri base, SessionState state) async { | 229 Future<Null> startAndAttachViaAgent(Uri base, SessionState state) async { |
230 // TODO(wibling): integrate with the FletchVm class, e.g. have a | 230 // TODO(wibling): integrate with the DartinoVm class, e.g. have a |
231 // AgentFletchVm and LocalFletchVm that both share the same interface | 231 // AgentDartinoVm and LocalDartinoVm that both share the same interface |
232 // where the former is interacting with the agent. | 232 // where the former is interacting with the agent. |
233 await checkAgentVersion(base, state); | 233 await checkAgentVersion(base, state); |
234 VmData vmData = await withAgentConnection(state, | 234 VmData vmData = await withAgentConnection(state, |
235 (connection) => connection.startVm()); | 235 (connection) => connection.startVm()); |
236 state.fletchAgentVmId = vmData.id; | 236 state.dartinoAgentVmId = vmData.id; |
237 String host = state.settings.deviceAddress.host; | 237 String host = state.settings.deviceAddress.host; |
238 await attachToVm(host, vmData.port, state); | 238 await attachToVm(host, vmData.port, state); |
239 await state.session.disableVMStandardOutput(); | 239 await state.session.disableVMStandardOutput(); |
240 } | 240 } |
241 | 241 |
242 Future<Null> startAndAttachDirectly(SessionState state, Uri base) async { | 242 Future<Null> startAndAttachDirectly(SessionState state, Uri base) async { |
243 String fletchVmPath = state.compilerHelper.fletchVm.toFilePath(); | 243 String dartinoVmPath = state.compilerHelper.dartinoVm.toFilePath(); |
244 state.fletchVm = await FletchVm.start(fletchVmPath, workingDirectory: base); | 244 state.dartinoVm = await DartinoVm.start(dartinoVmPath, workingDirectory: base)
; |
245 await attachToVm(state.fletchVm.host, state.fletchVm.port, state); | 245 await attachToVm(state.dartinoVm.host, state.dartinoVm.port, state); |
246 await state.session.disableVMStandardOutput(); | 246 await state.session.disableVMStandardOutput(); |
247 } | 247 } |
248 | 248 |
249 Future<Null> attachToVm(String host, int port, SessionState state) async { | 249 Future<Null> attachToVm(String host, int port, SessionState state) async { |
250 Socket socket = await connect( | 250 Socket socket = await connect( |
251 host, port, DiagnosticKind.socketVmConnectError, "vmSocket", state); | 251 host, port, DiagnosticKind.socketVmConnectError, "vmSocket", state); |
252 | 252 |
253 Session session = new Session(socket, state.compiler, state.stdoutSink, | 253 Session session = new Session(socket, state.compiler, state.stdoutSink, |
254 state.stderrSink, null); | 254 state.stderrSink, null); |
255 | 255 |
256 // Perform handshake with VM which validates that VM and compiler | 256 // Perform handshake with VM which validates that VM and compiler |
257 // have the same versions. | 257 // have the same versions. |
258 HandShakeResult handShakeResult = await session.handShake(fletchVersion); | 258 HandShakeResult handShakeResult = await session.handShake(dartinoVersion); |
259 if (handShakeResult == null) { | 259 if (handShakeResult == null) { |
260 throwFatalError(DiagnosticKind.handShakeFailed, address: '$host:$port'); | 260 throwFatalError(DiagnosticKind.handShakeFailed, address: '$host:$port'); |
261 } | 261 } |
262 if (!handShakeResult.success) { | 262 if (!handShakeResult.success) { |
263 throwFatalError(DiagnosticKind.versionMismatch, | 263 throwFatalError(DiagnosticKind.versionMismatch, |
264 address: '$host:$port', | 264 address: '$host:$port', |
265 userInput: fletchVersion, | 265 userInput: dartinoVersion, |
266 additionalUserInput: handShakeResult.version); | 266 additionalUserInput: handShakeResult.version); |
267 } | 267 } |
268 | 268 |
269 // Enable debugging to be able to communicate with VM when there | 269 // Enable debugging to be able to communicate with VM when there |
270 // are errors. | 270 // are errors. |
271 await session.runCommand(const Debugging()); | 271 await session.runCommand(const Debugging()); |
272 | 272 |
273 state.session = session; | 273 state.session = session; |
274 } | 274 } |
275 | 275 |
276 Future<int> compile( | 276 Future<int> compile( |
277 Uri script, | 277 Uri script, |
278 SessionState state, | 278 SessionState state, |
279 Uri base, | 279 Uri base, |
280 {bool analyzeOnly: false, | 280 {bool analyzeOnly: false, |
281 bool fatalIncrementalFailures: false}) async { | 281 bool fatalIncrementalFailures: false}) async { |
282 IncrementalCompiler compiler = state.compiler; | 282 IncrementalCompiler compiler = state.compiler; |
283 if (!compiler.isProductionModeEnabled) { | 283 if (!compiler.isProductionModeEnabled) { |
284 state.resetCompiler(); | 284 state.resetCompiler(); |
285 } | 285 } |
286 Uri firstScript = state.script; | 286 Uri firstScript = state.script; |
287 List<FletchDelta> previousResults = state.compilationResults; | 287 List<DartinoDelta> previousResults = state.compilationResults; |
288 | 288 |
289 FletchDelta newResult; | 289 DartinoDelta newResult; |
290 try { | 290 try { |
291 if (analyzeOnly) { | 291 if (analyzeOnly) { |
292 state.resetCompiler(); | 292 state.resetCompiler(); |
293 state.log("Analyzing '$script'"); | 293 state.log("Analyzing '$script'"); |
294 return await compiler.analyze(script, base); | 294 return await compiler.analyze(script, base); |
295 } else if (previousResults.isEmpty) { | 295 } else if (previousResults.isEmpty) { |
296 state.script = script; | 296 state.script = script; |
297 await compiler.compile(script, base); | 297 await compiler.compile(script, base); |
298 newResult = compiler.computeInitialDelta(); | 298 newResult = compiler.computeInitialDelta(); |
299 } else { | 299 } else { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 352 |
353 Future<Settings> createSettings( | 353 Future<Settings> createSettings( |
354 String sessionName, | 354 String sessionName, |
355 Uri uri, | 355 Uri uri, |
356 Uri cwd, | 356 Uri cwd, |
357 Uri configFileUri, | 357 Uri configFileUri, |
358 CommandSender commandSender, | 358 CommandSender commandSender, |
359 StreamIterator<ClientCommand> commandIterator) async { | 359 StreamIterator<ClientCommand> commandIterator) async { |
360 bool userProvidedSettings = uri != null; | 360 bool userProvidedSettings = uri != null; |
361 if (!userProvidedSettings) { | 361 if (!userProvidedSettings) { |
362 // Try to find a $sessionName.fletch-settings file starting from the current | 362 // Try to find a $sessionName.dartino-settings file starting from the curren
t |
363 // working directory and walking up its parent directories. | 363 // working directory and walking up its parent directories. |
364 uri = await findFile(cwd, '$sessionName.fletch-settings'); | 364 uri = await findFile(cwd, '$sessionName.dartino-settings'); |
365 | 365 |
366 // If no $sessionName.fletch-settings file is found, try to find the | 366 // If no $sessionName.dartino-settings file is found, try to find the |
367 // settings template file (in the SDK or git repo) by looking for a | 367 // settings template file (in the SDK or git repo) by looking for a |
368 // .fletch-settings file starting from the fletch executable's directory | 368 // .dartino-settings file starting from the dartino executable's directory |
369 // and walking up its parent directory chain. | 369 // and walking up its parent directory chain. |
370 if (uri == null) { | 370 if (uri == null) { |
371 uri = await findFile(executable, '.fletch-settings'); | 371 uri = await findFile(executable, '.dartino-settings'); |
372 if (uri != null) print('Using template settings file $uri'); | 372 if (uri != null) print('Using template settings file $uri'); |
373 } | 373 } |
374 } | 374 } |
375 | 375 |
376 Settings settings = new Settings.empty(); | 376 Settings settings = new Settings.empty(); |
377 if (uri != null) { | 377 if (uri != null) { |
378 String jsonLikeData = await new File.fromUri(uri).readAsString(); | 378 String jsonLikeData = await new File.fromUri(uri).readAsString(); |
379 settings = parseSettings(jsonLikeData, uri); | 379 settings = parseSettings(jsonLikeData, uri); |
380 } | 380 } |
381 if (userProvidedSettings) return settings; | 381 if (userProvidedSettings) return settings; |
382 | 382 |
383 // TODO(wibling): get rid of below special handling of the sessions 'remote' | 383 // TODO(wibling): get rid of below special handling of the sessions 'remote' |
384 // and 'local' and come up with a fletch project concept that can contain | 384 // and 'local' and come up with a dartino project concept that can contain |
385 // these settings. | 385 // these settings. |
386 Uri packagesUri; | 386 Uri packagesUri; |
387 Address address; | 387 Address address; |
388 switch (sessionName) { | 388 switch (sessionName) { |
389 case "remote": | 389 case "remote": |
390 uri = configFileUri.resolve("remote.fletch-settings"); | 390 uri = configFileUri.resolve("remote.dartino-settings"); |
391 Settings remoteSettings = await readSettings(uri); | 391 Settings remoteSettings = await readSettings(uri); |
392 if (remoteSettings != null) return remoteSettings; | 392 if (remoteSettings != null) return remoteSettings; |
393 packagesUri = executable.resolve("fletch-sdk.packages"); | 393 packagesUri = executable.resolve("dartino-sdk.packages"); |
394 address = await readAddressFromUser(commandSender, commandIterator); | 394 address = await readAddressFromUser(commandSender, commandIterator); |
395 if (address == null) { | 395 if (address == null) { |
396 // Assume user aborted data entry. | 396 // Assume user aborted data entry. |
397 return settings; | 397 return settings; |
398 } | 398 } |
399 break; | 399 break; |
400 | 400 |
401 case "local": | 401 case "local": |
402 uri = configFileUri.resolve("local.fletch-settings"); | 402 uri = configFileUri.resolve("local.dartino-settings"); |
403 Settings localSettings = await readSettings(uri); | 403 Settings localSettings = await readSettings(uri); |
404 if (localSettings != null) return localSettings; | 404 if (localSettings != null) return localSettings; |
405 // TODO(ahe): Use mock packages here. | 405 // TODO(ahe): Use mock packages here. |
406 packagesUri = executable.resolve("fletch-sdk.packages"); | 406 packagesUri = executable.resolve("dartino-sdk.packages"); |
407 break; | 407 break; |
408 | 408 |
409 default: | 409 default: |
410 return settings; | 410 return settings; |
411 } | 411 } |
412 | 412 |
413 if (!await new File.fromUri(packagesUri).exists()) { | 413 if (!await new File.fromUri(packagesUri).exists()) { |
414 packagesUri = null; | 414 packagesUri = null; |
415 } | 415 } |
416 settings = settings.copyWith(packages: packagesUri, deviceAddress: address); | 416 settings = settings.copyWith(packages: packagesUri, deviceAddress: address); |
(...skipping 25 matching lines...) Expand all Loading... |
442 // session because we use canonical input processing (Unix line | 442 // session because we use canonical input processing (Unix line |
443 // buffering), but it doesn't work in general. So we should fix that. | 443 // buffering), but it doesn't work in general. So we should fix that. |
444 String line = UTF8.decode(command.data).trim(); | 444 String line = UTF8.decode(command.data).trim(); |
445 if (line.isEmpty && devices.isEmpty) { | 445 if (line.isEmpty && devices.isEmpty) { |
446 commandSender.sendStdout("\n"); | 446 commandSender.sendStdout("\n"); |
447 // [discoverDevices] will print out the list of device with their | 447 // [discoverDevices] will print out the list of device with their |
448 // IP address, hostname, and agent version. | 448 // IP address, hostname, and agent version. |
449 devices = await discoverDevices(prefixWithNumber: true); | 449 devices = await discoverDevices(prefixWithNumber: true); |
450 if (devices.isEmpty) { | 450 if (devices.isEmpty) { |
451 commandSender.sendStdout( | 451 commandSender.sendStdout( |
452 "Couldn't find Fletch capable devices\n"); | 452 "Couldn't find Dartino capable devices\n"); |
453 commandSender.sendStdout(message); | 453 commandSender.sendStdout(message); |
454 } else { | 454 } else { |
455 if (devices.length == 1) { | 455 if (devices.length == 1) { |
456 commandSender.sendStdout("\n"); | 456 commandSender.sendStdout("\n"); |
457 commandSender.sendStdout("Press Enter to use this device"); | 457 commandSender.sendStdout("Press Enter to use this device"); |
458 } else { | 458 } else { |
459 commandSender.sendStdout("\n"); | 459 commandSender.sendStdout("\n"); |
460 commandSender.sendStdout( | 460 commandSender.sendStdout( |
461 "Found ${devices.length} Fletch capable devices\n"); | 461 "Found ${devices.length} Dartino capable devices\n"); |
462 commandSender.sendStdout( | 462 commandSender.sendStdout( |
463 "Please enter the number or the IP address of " | 463 "Please enter the number or the IP address of " |
464 "the remote device you would like to use " | 464 "the remote device you would like to use " |
465 "(press Enter to use the first device): "); | 465 "(press Enter to use the first device): "); |
466 } | 466 } |
467 } | 467 } |
468 } else { | 468 } else { |
469 bool checkedIndex = false; | 469 bool checkedIndex = false; |
470 if (devices.length > 0) { | 470 if (devices.length > 0) { |
471 if (line.isEmpty) { | 471 if (line.isEmpty) { |
(...skipping 24 matching lines...) Expand all Loading... |
496 return null; | 496 return null; |
497 } | 497 } |
498 } | 498 } |
499 return null; | 499 return null; |
500 } | 500 } |
501 | 501 |
502 SessionState createSessionState( | 502 SessionState createSessionState( |
503 String name, | 503 String name, |
504 Settings settings, | 504 Settings settings, |
505 {Uri libraryRoot, | 505 {Uri libraryRoot, |
506 Uri fletchVm, | 506 Uri dartinoVm, |
507 Uri nativesJson}) { | 507 Uri nativesJson}) { |
508 if (settings == null) { | 508 if (settings == null) { |
509 settings = const Settings.empty(); | 509 settings = const Settings.empty(); |
510 } | 510 } |
511 List<String> compilerOptions = const bool.fromEnvironment("fletchc-verbose") | 511 List<String> compilerOptions = const bool.fromEnvironment("dartino_compiler-ve
rbose") |
512 ? <String>['--verbose'] : <String>[]; | 512 ? <String>['--verbose'] : <String>[]; |
513 compilerOptions.addAll(settings.options); | 513 compilerOptions.addAll(settings.options); |
514 Uri packageConfig = settings.packages; | 514 Uri packageConfig = settings.packages; |
515 if (packageConfig == null) { | 515 if (packageConfig == null) { |
516 packageConfig = executable.resolve("fletch-sdk.packages"); | 516 packageConfig = executable.resolve("dartino-sdk.packages"); |
517 } | 517 } |
518 | 518 |
519 DeviceType deviceType = settings.deviceType ?? | 519 DeviceType deviceType = settings.deviceType ?? |
520 parseDeviceType(fletchDeviceType); | 520 parseDeviceType(dartinoDeviceType); |
521 | 521 |
522 String platform = (deviceType == DeviceType.embedded) | 522 String platform = (deviceType == DeviceType.embedded) |
523 ? "fletch_embedded.platform" | 523 ? "dartino_embedded.platform" |
524 : "fletch_mobile.platform"; | 524 : "dartino_mobile.platform"; |
525 | 525 |
526 FletchCompiler compilerHelper = new FletchCompiler( | 526 DartinoCompiler compilerHelper = new DartinoCompiler( |
527 options: compilerOptions, | 527 options: compilerOptions, |
528 packageConfig: packageConfig, | 528 packageConfig: packageConfig, |
529 environment: settings.constants, | 529 environment: settings.constants, |
530 platform: platform, | 530 platform: platform, |
531 libraryRoot: libraryRoot, | 531 libraryRoot: libraryRoot, |
532 fletchVm: fletchVm, | 532 dartinoVm: dartinoVm, |
533 nativesJson: nativesJson); | 533 nativesJson: nativesJson); |
534 | 534 |
535 return new SessionState( | 535 return new SessionState( |
536 name, compilerHelper, | 536 name, compilerHelper, |
537 compilerHelper.newIncrementalCompiler(settings.incrementalMode), | 537 compilerHelper.newIncrementalCompiler(settings.incrementalMode), |
538 settings); | 538 settings); |
539 } | 539 } |
540 | 540 |
541 Future runWithDebugger( | 541 Future runWithDebugger( |
542 List<String> commands, | 542 List<String> commands, |
(...skipping 14 matching lines...) Expand all Loading... |
557 session.debug(inputGenerator(), Uri.base, state, echo: true) : | 557 session.debug(inputGenerator(), Uri.base, state, echo: true) : |
558 session.debug( | 558 session.debug( |
559 new Stream<String>.fromIterable(commands), Uri.base, state, | 559 new Stream<String>.fromIterable(commands), Uri.base, state, |
560 echo: true); | 560 echo: true); |
561 } | 561 } |
562 | 562 |
563 Future<int> run( | 563 Future<int> run( |
564 SessionState state, | 564 SessionState state, |
565 {List<String> testDebuggerCommands, | 565 {List<String> testDebuggerCommands, |
566 bool terminateDebugger: true}) async { | 566 bool terminateDebugger: true}) async { |
567 List<FletchDelta> compilationResults = state.compilationResults; | 567 List<DartinoDelta> compilationResults = state.compilationResults; |
568 Session session = state.session; | 568 Session session = state.session; |
569 | 569 |
570 for (FletchDelta delta in compilationResults) { | 570 for (DartinoDelta delta in compilationResults) { |
571 await session.applyDelta(delta); | 571 await session.applyDelta(delta); |
572 } | 572 } |
573 | 573 |
574 if (testDebuggerCommands != null) { | 574 if (testDebuggerCommands != null) { |
575 await runWithDebugger(testDebuggerCommands, session, state); | 575 await runWithDebugger(testDebuggerCommands, session, state); |
576 return 0; | 576 return 0; |
577 } | 577 } |
578 | 578 |
579 session.silent = true; | 579 session.silent = true; |
580 | 580 |
581 await session.enableDebugger(); | 581 await session.enableDebugger(); |
582 await session.spawnProcess(); | 582 await session.spawnProcess(); |
583 var command = await session.debugRun(); | 583 var command = await session.debugRun(); |
584 | 584 |
585 int exitCode = exit_codes.COMPILER_EXITCODE_CRASH; | 585 int exitCode = exit_codes.COMPILER_EXITCODE_CRASH; |
586 if (command == null) { | 586 if (command == null) { |
587 await session.kill(); | 587 await session.kill(); |
588 await session.shutdown(); | 588 await session.shutdown(); |
589 throwInternalError("No command received from Fletch VM"); | 589 throwInternalError("No command received from Dartino VM"); |
590 } | 590 } |
591 | 591 |
592 Future printException() async { | 592 Future printException() async { |
593 if (!session.loaded) { | 593 if (!session.loaded) { |
594 print('### process not loaded, cannot print uncaught exception'); | 594 print('### process not loaded, cannot print uncaught exception'); |
595 return; | 595 return; |
596 } | 596 } |
597 debug.RemoteObject exception = await session.uncaughtException(); | 597 debug.RemoteObject exception = await session.uncaughtException(); |
598 if (exception != null) { | 598 if (exception != null) { |
599 print(session.exceptionToString(exception)); | 599 print(session.exceptionToString(exception)); |
(...skipping 26 matching lines...) Expand all Loading... |
626 exitCode = exit_codes.DART_VM_EXITCODE_COMPILE_TIME_ERROR; | 626 exitCode = exit_codes.DART_VM_EXITCODE_COMPILE_TIME_ERROR; |
627 await printTrace(); | 627 await printTrace(); |
628 // TODO(ahe): Continue to unwind stack? | 628 // TODO(ahe): Continue to unwind stack? |
629 break; | 629 break; |
630 | 630 |
631 case VmCommandCode.ProcessTerminated: | 631 case VmCommandCode.ProcessTerminated: |
632 exitCode = 0; | 632 exitCode = 0; |
633 break; | 633 break; |
634 | 634 |
635 case VmCommandCode.ConnectionError: | 635 case VmCommandCode.ConnectionError: |
636 state.log("Error on connection to Fletch VM: ${command.error}"); | 636 state.log("Error on connection to Dartino VM: ${command.error}"); |
637 exitCode = exit_codes.COMPILER_EXITCODE_CONNECTION_ERROR; | 637 exitCode = exit_codes.COMPILER_EXITCODE_CONNECTION_ERROR; |
638 break; | 638 break; |
639 | 639 |
640 default: | 640 default: |
641 throwInternalError("Unexpected result from Fletch VM: '$command'"); | 641 throwInternalError("Unexpected result from Dartino VM: '$command'"); |
642 break; | 642 break; |
643 } | 643 } |
644 } finally { | 644 } finally { |
645 if (terminateDebugger) { | 645 if (terminateDebugger) { |
646 await state.terminateSession(); | 646 await state.terminateSession(); |
647 } else { | 647 } else { |
648 // If the session terminated due to a ConnectionError or the program | 648 // If the session terminated due to a ConnectionError or the program |
649 // finished don't reuse the state's session. | 649 // finished don't reuse the state's session. |
650 if (session.terminated) { | 650 if (session.terminated) { |
651 state.session = null; | 651 state.session = null; |
652 } | 652 } |
653 session.silent = false; | 653 session.silent = false; |
654 } | 654 } |
655 }; | 655 }; |
656 | 656 |
657 return exitCode; | 657 return exitCode; |
658 } | 658 } |
659 | 659 |
660 Future<int> export(SessionState state, | 660 Future<int> export(SessionState state, |
661 Uri snapshot, | 661 Uri snapshot, |
662 {bool binaryProgramInfo: false}) async { | 662 {bool binaryProgramInfo: false}) async { |
663 List<FletchDelta> compilationResults = state.compilationResults; | 663 List<DartinoDelta> compilationResults = state.compilationResults; |
664 Session session = state.session; | 664 Session session = state.session; |
665 state.session = null; | 665 state.session = null; |
666 | 666 |
667 for (FletchDelta delta in compilationResults) { | 667 for (DartinoDelta delta in compilationResults) { |
668 await session.applyDelta(delta); | 668 await session.applyDelta(delta); |
669 } | 669 } |
670 | 670 |
671 var result = await session.writeSnapshot(snapshot.toFilePath()); | 671 var result = await session.writeSnapshot(snapshot.toFilePath()); |
672 if (result is WriteSnapshotResult) { | 672 if (result is WriteSnapshotResult) { |
673 WriteSnapshotResult snapshotResult = result; | 673 WriteSnapshotResult snapshotResult = result; |
674 | 674 |
675 await session.shutdown(); | 675 await session.shutdown(); |
676 | 676 |
677 ProgramInfo info = | 677 ProgramInfo info = |
(...skipping 18 matching lines...) Expand all Loading... |
696 Future<int> compileAndAttachToVmThen( | 696 Future<int> compileAndAttachToVmThen( |
697 CommandSender commandSender, | 697 CommandSender commandSender, |
698 StreamIterator<ClientCommand> commandIterator, | 698 StreamIterator<ClientCommand> commandIterator, |
699 SessionState state, | 699 SessionState state, |
700 Uri script, | 700 Uri script, |
701 Uri base, | 701 Uri base, |
702 bool waitForVmExit, | 702 bool waitForVmExit, |
703 Future<int> action(), | 703 Future<int> action(), |
704 {ClientEventHandler eventHandler}) async { | 704 {ClientEventHandler eventHandler}) async { |
705 bool startedVmDirectly = false; | 705 bool startedVmDirectly = false; |
706 List<FletchDelta> compilationResults = state.compilationResults; | 706 List<DartinoDelta> compilationResults = state.compilationResults; |
707 if (compilationResults.isEmpty || script != null) { | 707 if (compilationResults.isEmpty || script != null) { |
708 if (script == null) { | 708 if (script == null) { |
709 throwFatalError(DiagnosticKind.noFileTarget); | 709 throwFatalError(DiagnosticKind.noFileTarget); |
710 } | 710 } |
711 int exitCode = await compile(script, state, base); | 711 int exitCode = await compile(script, state, base); |
712 if (exitCode != 0) return exitCode; | 712 if (exitCode != 0) return exitCode; |
713 compilationResults = state.compilationResults; | 713 compilationResults = state.compilationResults; |
714 assert(compilationResults != null); | 714 assert(compilationResults != null); |
715 } | 715 } |
716 | 716 |
717 Session session = state.session; | 717 Session session = state.session; |
718 if (session != null && session.loaded) { | 718 if (session != null && session.loaded) { |
719 // We cannot reuse a session that has already been loaded. Loading | 719 // We cannot reuse a session that has already been loaded. Loading |
720 // currently implies that some of the code has been run. | 720 // currently implies that some of the code has been run. |
721 if (state.explicitAttach) { | 721 if (state.explicitAttach) { |
722 // If the user explicitly called 'fletch attach' we cannot | 722 // If the user explicitly called 'dartino attach' we cannot |
723 // create a new VM session since we don't know if the vm is | 723 // create a new VM session since we don't know if the vm is |
724 // running locally or remotely and if running remotely there | 724 // running locally or remotely and if running remotely there |
725 // is no guarantee there is an agent to start a new vm. | 725 // is no guarantee there is an agent to start a new vm. |
726 // | 726 // |
727 // The UserSession is invalid in its current state as the | 727 // The UserSession is invalid in its current state as the |
728 // vm session (aka. session in the code here) has already | 728 // vm session (aka. session in the code here) has already |
729 // been loaded and run some code. | 729 // been loaded and run some code. |
730 throwFatalError(DiagnosticKind.sessionInvalidState, | 730 throwFatalError(DiagnosticKind.sessionInvalidState, |
731 sessionName: state.name); | 731 sessionName: state.name); |
732 } | 732 } |
733 state.log('Cannot reuse existing VM session, creating new.'); | 733 state.log('Cannot reuse existing VM session, creating new.'); |
734 await state.terminateSession(); | 734 await state.terminateSession(); |
735 session = null; | 735 session = null; |
736 } | 736 } |
737 if (session == null) { | 737 if (session == null) { |
738 if (state.settings.deviceAddress != null) { | 738 if (state.settings.deviceAddress != null) { |
739 await startAndAttachViaAgent(base, state); | 739 await startAndAttachViaAgent(base, state); |
740 // TODO(wibling): read stdout from agent. | 740 // TODO(wibling): read stdout from agent. |
741 } else { | 741 } else { |
742 startedVmDirectly = true; | 742 startedVmDirectly = true; |
743 await startAndAttachDirectly(state, base); | 743 await startAndAttachDirectly(state, base); |
744 state.fletchVm.stdoutLines.listen((String line) { | 744 state.dartinoVm.stdoutLines.listen((String line) { |
745 commandSender.sendStdout("$line\n"); | 745 commandSender.sendStdout("$line\n"); |
746 }); | 746 }); |
747 state.fletchVm.stderrLines.listen((String line) { | 747 state.dartinoVm.stderrLines.listen((String line) { |
748 commandSender.sendStderr("$line\n"); | 748 commandSender.sendStderr("$line\n"); |
749 }); | 749 }); |
750 } | 750 } |
751 session = state.session; | 751 session = state.session; |
752 assert(session != null); | 752 assert(session != null); |
753 } | 753 } |
754 | 754 |
755 eventHandler ??= defaultClientEventHandler(state, commandIterator); | 755 eventHandler ??= defaultClientEventHandler(state, commandIterator); |
756 setupClientInOut(state, commandSender, eventHandler); | 756 setupClientInOut(state, commandSender, eventHandler); |
757 | 757 |
758 int exitCode = exit_codes.COMPILER_EXITCODE_CRASH; | 758 int exitCode = exit_codes.COMPILER_EXITCODE_CRASH; |
759 try { | 759 try { |
760 exitCode = await action(); | 760 exitCode = await action(); |
761 } catch (error, trace) { | 761 } catch (error, trace) { |
762 print(error); | 762 print(error); |
763 if (trace != null) { | 763 if (trace != null) { |
764 print(trace); | 764 print(trace); |
765 } | 765 } |
766 } finally { | 766 } finally { |
767 if (waitForVmExit && startedVmDirectly) { | 767 if (waitForVmExit && startedVmDirectly) { |
768 exitCode = await state.fletchVm.exitCode; | 768 exitCode = await state.dartinoVm.exitCode; |
769 } | 769 } |
770 state.detachCommandSender(); | 770 state.detachCommandSender(); |
771 } | 771 } |
772 return exitCode; | 772 return exitCode; |
773 } | 773 } |
774 | 774 |
775 void setupClientInOut( | 775 void setupClientInOut( |
776 SessionState state, | 776 SessionState state, |
777 CommandSender commandSender, | 777 CommandSender commandSender, |
778 ClientEventHandler eventHandler) { | 778 ClientEventHandler eventHandler) { |
779 // Forward output going into the state's outputSink using the passed in | 779 // Forward output going into the state's outputSink using the passed in |
780 // commandSender. This typically forwards output to the hub (main isolate) | 780 // commandSender. This typically forwards output to the hub (main isolate) |
781 // which forwards it on to stdout of the Fletch C++ client. | 781 // which forwards it on to stdout of the Dartino C++ client. |
782 state.attachCommandSender(commandSender); | 782 state.attachCommandSender(commandSender); |
783 | 783 |
784 // Start event handling for input passed from the Fletch C++ client. | 784 // Start event handling for input passed from the Dartino C++ client. |
785 eventHandler(state.session); | 785 eventHandler(state.session); |
786 | 786 |
787 // Let the hub (main isolate) know that event handling has been started. | 787 // Let the hub (main isolate) know that event handling has been started. |
788 commandSender.sendEventLoopStarted(); | 788 commandSender.sendEventLoopStarted(); |
789 } | 789 } |
790 | 790 |
791 /// Return a default client event handler bound to the current session's | 791 /// Return a default client event handler bound to the current session's |
792 /// commandIterator and state. | 792 /// commandIterator and state. |
793 /// This handler only takes care of signals coming from the client. | 793 /// This handler only takes care of signals coming from the client. |
794 ClientEventHandler defaultClientEventHandler( | 794 ClientEventHandler defaultClientEventHandler( |
795 SessionState state, | 795 SessionState state, |
796 StreamIterator<ClientCommand> commandIterator) { | 796 StreamIterator<ClientCommand> commandIterator) { |
797 return (Session session) async { | 797 return (Session session) async { |
798 while (await commandIterator.moveNext()) { | 798 while (await commandIterator.moveNext()) { |
799 ClientCommand command = commandIterator.current; | 799 ClientCommand command = commandIterator.current; |
800 switch (command.code) { | 800 switch (command.code) { |
801 case ClientCommandCode.Signal: | 801 case ClientCommandCode.Signal: |
802 int signalNumber = command.data; | 802 int signalNumber = command.data; |
803 handleSignal(state, signalNumber); | 803 handleSignal(state, signalNumber); |
804 break; | 804 break; |
805 default: | 805 default: |
806 state.log("Unhandled command from client: $command"); | 806 state.log("Unhandled command from client: $command"); |
807 } | 807 } |
808 } | 808 } |
809 }; | 809 }; |
810 } | 810 } |
811 | 811 |
812 void handleSignal(SessionState state, int signalNumber) { | 812 void handleSignal(SessionState state, int signalNumber) { |
813 state.log("Received signal $signalNumber"); | 813 state.log("Received signal $signalNumber"); |
814 if (!state.hasRemoteVm && state.fletchVm == null) { | 814 if (!state.hasRemoteVm && state.dartinoVm == null) { |
815 // This can happen if a user has attached to a vm using the "attach" verb | 815 // This can happen if a user has attached to a vm using the "attach" verb |
816 // in which case we don't forward the signal to the vm. | 816 // in which case we don't forward the signal to the vm. |
817 // TODO(wibling): Determine how to interpret the signal for the persistent | 817 // TODO(wibling): Determine how to interpret the signal for the persistent |
818 // process. | 818 // process. |
819 state.log('Signal $signalNumber ignored. VM was manually attached.'); | 819 state.log('Signal $signalNumber ignored. VM was manually attached.'); |
820 print('Signal $signalNumber ignored. VM was manually attached.'); | 820 print('Signal $signalNumber ignored. VM was manually attached.'); |
821 return; | 821 return; |
822 } | 822 } |
823 if (state.hasRemoteVm) { | 823 if (state.hasRemoteVm) { |
824 signalAgentVm(state, signalNumber); | 824 signalAgentVm(state, signalNumber); |
825 } else { | 825 } else { |
826 assert(state.fletchVm.process != null); | 826 assert(state.dartinoVm.process != null); |
827 int vmPid = state.fletchVm.process.pid; | 827 int vmPid = state.dartinoVm.process.pid; |
828 Process.runSync("kill", ["-$signalNumber", "$vmPid"]); | 828 Process.runSync("kill", ["-$signalNumber", "$vmPid"]); |
829 } | 829 } |
830 } | 830 } |
831 | 831 |
832 Future signalAgentVm(SessionState state, int signalNumber) async { | 832 Future signalAgentVm(SessionState state, int signalNumber) async { |
833 await withAgentConnection(state, (connection) { | 833 await withAgentConnection(state, (connection) { |
834 return connection.signalVm(state.fletchAgentVmId, signalNumber); | 834 return connection.signalVm(state.dartinoAgentVmId, signalNumber); |
835 }); | 835 }); |
836 } | 836 } |
837 | 837 |
838 String extractVersion(Uri uri) { | 838 String extractVersion(Uri uri) { |
839 List<String> nameParts = uri.pathSegments.last.split('_'); | 839 List<String> nameParts = uri.pathSegments.last.split('_'); |
840 if (nameParts.length != 3 || nameParts[0] != 'fletch-agent') { | 840 if (nameParts.length != 3 || nameParts[0] != 'dartino-agent') { |
841 throwFatalError(DiagnosticKind.upgradeInvalidPackageName); | 841 throwFatalError(DiagnosticKind.upgradeInvalidPackageName); |
842 } | 842 } |
843 String version = nameParts[1]; | 843 String version = nameParts[1]; |
844 // create_debian_packages.py adds a '-1' after the hash in the package name. | 844 // create_debian_packages.py adds a '-1' after the hash in the package name. |
845 if (version.endsWith('-1')) { | 845 if (version.endsWith('-1')) { |
846 version = version.substring(0, version.length - 2); | 846 version = version.substring(0, version.length - 2); |
847 } | 847 } |
848 return version; | 848 return version; |
849 } | 849 } |
850 | 850 |
851 /// Try to locate an Fletch agent package file assuming the normal SDK layout | 851 /// Try to locate an Dartino agent package file assuming the normal SDK layout |
852 /// with SDK base directory [base]. | 852 /// with SDK base directory [base]. |
853 /// | 853 /// |
854 /// If the parameter [version] is passed, the Uri is only returned, if | 854 /// If the parameter [version] is passed, the Uri is only returned, if |
855 /// the version matches. | 855 /// the version matches. |
856 Future<Uri> lookForAgentPackage(Uri base, {String version}) async { | 856 Future<Uri> lookForAgentPackage(Uri base, {String version}) async { |
857 String platform = "raspberry-pi2"; | 857 String platform = "raspberry-pi2"; |
858 Uri platformUri = base.resolve("platforms/$platform"); | 858 Uri platformUri = base.resolve("platforms/$platform"); |
859 Directory platformDir = new Directory.fromUri(platformUri); | 859 Directory platformDir = new Directory.fromUri(platformUri); |
860 | 860 |
861 // Try to locate the agent package in the SDK for the selected platform. | 861 // Try to locate the agent package in the SDK for the selected platform. |
862 Uri sdkAgentPackage; | 862 Uri sdkAgentPackage; |
863 if (await platformDir.exists()) { | 863 if (await platformDir.exists()) { |
864 for (FileSystemEntity entry in platformDir.listSync()) { | 864 for (FileSystemEntity entry in platformDir.listSync()) { |
865 Uri uri = entry.uri; | 865 Uri uri = entry.uri; |
866 String name = uri.pathSegments.last; | 866 String name = uri.pathSegments.last; |
867 if (name.startsWith('fletch-agent') && | 867 if (name.startsWith('dartino-agent') && |
868 name.endsWith('.deb') && | 868 name.endsWith('.deb') && |
869 (version == null || extractVersion(uri) == version)) { | 869 (version == null || extractVersion(uri) == version)) { |
870 return uri; | 870 return uri; |
871 } | 871 } |
872 } | 872 } |
873 } | 873 } |
874 return null; | 874 return null; |
875 } | 875 } |
876 | 876 |
877 Future<Uri> readPackagePathFromUser( | 877 Future<Uri> readPackagePathFromUser( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 | 1000 |
1001 if (!await new File.fromUri(packageUri).exists()) { | 1001 if (!await new File.fromUri(packageUri).exists()) { |
1002 print('File not found: $packageUri'); | 1002 print('File not found: $packageUri'); |
1003 return 1; | 1003 return 1; |
1004 } | 1004 } |
1005 | 1005 |
1006 Version version = parseVersion(extractVersion(packageUri)); | 1006 Version version = parseVersion(extractVersion(packageUri)); |
1007 | 1007 |
1008 Version existingVersion = parseVersion( | 1008 Version existingVersion = parseVersion( |
1009 await withAgentConnection(state, | 1009 await withAgentConnection(state, |
1010 (connection) => connection.fletchVersion())); | 1010 (connection) => connection.dartinoVersion())); |
1011 | 1011 |
1012 if (existingVersion == version) { | 1012 if (existingVersion == version) { |
1013 print('Target device is already at $version'); | 1013 print('Target device is already at $version'); |
1014 return 0; | 1014 return 0; |
1015 } | 1015 } |
1016 | 1016 |
1017 print("Attempting to upgrade device from " | 1017 print("Attempting to upgrade device from " |
1018 "$existingVersion to $version"); | 1018 "$existingVersion to $version"); |
1019 | 1019 |
1020 if (existingVersion.isGreaterThan(version)) { | 1020 if (existingVersion.isGreaterThan(version)) { |
(...skipping 18 matching lines...) Expand all Loading... |
1039 break; | 1039 break; |
1040 | 1040 |
1041 default: | 1041 default: |
1042 throwInternalError("Unexpected ${command.code}"); | 1042 throwInternalError("Unexpected ${command.code}"); |
1043 return null; | 1043 return null; |
1044 } | 1044 } |
1045 } | 1045 } |
1046 } | 1046 } |
1047 | 1047 |
1048 List<int> data = await new File.fromUri(packageUri).readAsBytes(); | 1048 List<int> data = await new File.fromUri(packageUri).readAsBytes(); |
1049 print("Sending package to fletch agent"); | 1049 print("Sending package to dartino agent"); |
1050 await withAgentConnection(state, | 1050 await withAgentConnection(state, |
1051 (connection) => connection.upgradeAgent(version.toString(), data)); | 1051 (connection) => connection.upgradeAgent(version.toString(), data)); |
1052 print("Transfer complete, waiting for the Fletch agent to restart. " | 1052 print("Transfer complete, waiting for the Dartino agent to restart. " |
1053 "This can take a few seconds."); | 1053 "This can take a few seconds."); |
1054 | 1054 |
1055 Version newVersion; | 1055 Version newVersion; |
1056 int remainingTries = 20; | 1056 int remainingTries = 20; |
1057 // Wait for the agent to come back online to verify the version. | 1057 // Wait for the agent to come back online to verify the version. |
1058 while (--remainingTries > 0) { | 1058 while (--remainingTries > 0) { |
1059 await new Future.delayed(const Duration(seconds: 1)); | 1059 await new Future.delayed(const Duration(seconds: 1)); |
1060 try { | 1060 try { |
1061 // TODO(karlklose): this functionality should be shared with connect. | 1061 // TODO(karlklose): this functionality should be shared with connect. |
1062 Socket socket = await Socket.connect( | 1062 Socket socket = await Socket.connect( |
1063 state.settings.deviceAddress.host, | 1063 state.settings.deviceAddress.host, |
1064 state.settings.deviceAddress.port); | 1064 state.settings.deviceAddress.port); |
1065 handleSocketErrors(socket, "pollAgentVersion", log: (String info) { | 1065 handleSocketErrors(socket, "pollAgentVersion", log: (String info) { |
1066 state.log("Connected to TCP waitForAgentUpgrade $info"); | 1066 state.log("Connected to TCP waitForAgentUpgrade $info"); |
1067 }); | 1067 }); |
1068 AgentConnection connection = new AgentConnection(socket); | 1068 AgentConnection connection = new AgentConnection(socket); |
1069 newVersion = parseVersion(await connection.fletchVersion()); | 1069 newVersion = parseVersion(await connection.dartinoVersion()); |
1070 disconnectFromAgent(connection); | 1070 disconnectFromAgent(connection); |
1071 if (newVersion != existingVersion) { | 1071 if (newVersion != existingVersion) { |
1072 break; | 1072 break; |
1073 } | 1073 } |
1074 } on SocketException catch (e) { | 1074 } on SocketException catch (e) { |
1075 // Ignore this error and keep waiting. | 1075 // Ignore this error and keep waiting. |
1076 } | 1076 } |
1077 } | 1077 } |
1078 | 1078 |
1079 if (newVersion == existingVersion) { | 1079 if (newVersion == existingVersion) { |
1080 print("Failed to upgrade: the device is still at the old version."); | 1080 print("Failed to upgrade: the device is still at the old version."); |
1081 print("Try running x-upgrade again. " | 1081 print("Try running x-upgrade again. " |
1082 "If the upgrade fails again, try rebooting the device."); | 1082 "If the upgrade fails again, try rebooting the device."); |
1083 return 1; | 1083 return 1; |
1084 } else if (newVersion == null) { | 1084 } else if (newVersion == null) { |
1085 print("Could not connect to Fletch agent after upgrade."); | 1085 print("Could not connect to Dartino agent after upgrade."); |
1086 print("Try running 'fletch show devices' later to see if it has been" | 1086 print("Try running 'dartino show devices' later to see if it has been" |
1087 " restarted. If the device does not show up, try rebooting it."); | 1087 " restarted. If the device does not show up, try rebooting it."); |
1088 return 1; | 1088 return 1; |
1089 } else { | 1089 } else { |
1090 print("Upgrade successful."); | 1090 print("Upgrade successful."); |
1091 } | 1091 } |
1092 | 1092 |
1093 return 0; | 1093 return 0; |
1094 } | 1094 } |
1095 | 1095 |
1096 Future<int> downloadTools( | 1096 Future<int> downloadTools( |
(...skipping 19 matching lines...) Expand all Loading... |
1116 throwUnsupportedPlatform(); | 1116 throwUnsupportedPlatform(); |
1117 } | 1117 } |
1118 if (result.exitCode != 0) { | 1118 if (result.exitCode != 0) { |
1119 throwInternalError( | 1119 throwInternalError( |
1120 "Failed to decompress ${zipFile.path} to ${destination.path}, " | 1120 "Failed to decompress ${zipFile.path} to ${destination.path}, " |
1121 "error = ${result.exitCode}"); | 1121 "error = ${result.exitCode}"); |
1122 } | 1122 } |
1123 } | 1123 } |
1124 | 1124 |
1125 const String gcsRoot = "https://storage.googleapis.com"; | 1125 const String gcsRoot = "https://storage.googleapis.com"; |
1126 String gcsBucket = "fletch-archive"; | 1126 String gcsBucket = "dartino-archive"; |
1127 | 1127 |
1128 Future downloadTool(String gcsPath, String zipFile, String toolName) async { | 1128 Future downloadTool(String gcsPath, String zipFile, String toolName) async { |
1129 Uri url = Uri.parse("$gcsRoot/$gcsBucket/$gcsPath/$zipFile"); | 1129 Uri url = Uri.parse("$gcsRoot/$gcsBucket/$gcsPath/$zipFile"); |
1130 Directory tmpDir = Directory.systemTemp.createTempSync("fletch_download"); | 1130 Directory tmpDir = Directory.systemTemp.createTempSync("fletch_download"); |
1131 File tmpZip = new File(join(tmpDir.path, zipFile)); | 1131 File tmpZip = new File(join(tmpDir.path, zipFile)); |
1132 | 1132 |
1133 OutputService outputService = | 1133 OutputService outputService = |
1134 new OutputService(commandSender.sendStdout, state.log); | 1134 new OutputService(commandSender.sendStdout, state.log); |
1135 SDKServices service = new SDKServices(outputService); | 1135 SDKServices service = new SDKServices(outputService); |
1136 print("Downloading: $toolName"); | 1136 print("Downloading: $toolName"); |
1137 state.log("Downloading $toolName from $url to $tmpZip"); | 1137 state.log("Downloading $toolName from $url to $tmpZip"); |
1138 await service.downloadWithProgress(url, tmpZip); | 1138 await service.downloadWithProgress(url, tmpZip); |
1139 print(""); // service.downloadWithProgress does not write newline when done. | 1139 print(""); // service.downloadWithProgress does not write newline when done. |
1140 | 1140 |
1141 // In the SDK, the tools directory is at the same level as the | 1141 // In the SDK, the tools directory is at the same level as the |
1142 // internal (and bin) directory. | 1142 // internal (and bin) directory. |
1143 Directory toolsDirectory = | 1143 Directory toolsDirectory = |
1144 new Directory.fromUri(executable.resolve('../tools')); | 1144 new Directory.fromUri(executable.resolve('../tools')); |
1145 state.log("Decompressing ${tmpZip.path} to ${toolsDirectory.path}"); | 1145 state.log("Decompressing ${tmpZip.path} to ${toolsDirectory.path}"); |
1146 await decompressFile(tmpZip, toolsDirectory); | 1146 await decompressFile(tmpZip, toolsDirectory); |
1147 state.log("Deleting temporary directory ${tmpDir.path}"); | 1147 state.log("Deleting temporary directory ${tmpDir.path}"); |
1148 await tmpDir.delete(recursive: true); | 1148 await tmpDir.delete(recursive: true); |
1149 } | 1149 } |
1150 | 1150 |
1151 String gcsPath; | 1151 String gcsPath; |
1152 | 1152 |
1153 Version version = parseVersion(fletchVersion); | 1153 Version version = parseVersion(dartinoVersion); |
1154 if (version.isEdgeVersion) { | 1154 if (version.isEdgeVersion) { |
1155 print("WARNING: For bleeding edge a fixed image is used."); | 1155 print("WARNING: For bleeding edge a fixed image is used."); |
1156 // For edge versions download use a well known version for now. | 1156 // For edge versions download use a well known version for now. |
1157 var knownVersion = "0.3.0-edge.3c85dbafe006eb2ce16545aaf3df1352fa7a4500"; | 1157 var knownVersion = "0.3.0-edge.3c85dbafe006eb2ce16545aaf3df1352fa7a4500"; |
1158 gcsBucket = "fletch-temporary"; | 1158 gcsBucket = "dartino-temporary"; |
1159 gcsPath = "channels/be/raw/$knownVersion/sdk"; | 1159 gcsPath = "channels/be/raw/$knownVersion/sdk"; |
1160 } else if (version.isDevVersion) { | 1160 } else if (version.isDevVersion) { |
1161 // TODO(sgjesse): Change this to channels/dev/release at some point. | 1161 // TODO(sgjesse): Change this to channels/dev/release at some point. |
1162 gcsPath = "channels/dev/raw/$version/sdk"; | 1162 gcsPath = "channels/dev/raw/$version/sdk"; |
1163 } else { | 1163 } else { |
1164 print("Stable version not supported. Got version $version."); | 1164 print("Stable version not supported. Got version $version."); |
1165 } | 1165 } |
1166 | 1166 |
1167 String osName; | 1167 String osName; |
1168 if (Platform.isLinux) { | 1168 if (Platform.isLinux) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 Future<String> getAgentVersion(InternetAddress host, int port) async { | 1225 Future<String> getAgentVersion(InternetAddress host, int port) async { |
1226 Socket socket; | 1226 Socket socket; |
1227 try { | 1227 try { |
1228 socket = await Socket.connect(host, port); | 1228 socket = await Socket.connect(host, port); |
1229 handleSocketErrors(socket, "getAgentVersionSocket"); | 1229 handleSocketErrors(socket, "getAgentVersionSocket"); |
1230 } on SocketException catch (e) { | 1230 } on SocketException catch (e) { |
1231 return 'Error: no agent: $e'; | 1231 return 'Error: no agent: $e'; |
1232 } | 1232 } |
1233 try { | 1233 try { |
1234 AgentConnection connection = new AgentConnection(socket); | 1234 AgentConnection connection = new AgentConnection(socket); |
1235 return await connection.fletchVersion(); | 1235 return await connection.dartinoVersion(); |
1236 } finally { | 1236 } finally { |
1237 socket.close(); | 1237 socket.close(); |
1238 } | 1238 } |
1239 } | 1239 } |
1240 | 1240 |
1241 Future<List<InternetAddress>> discoverDevices( | 1241 Future<List<InternetAddress>> discoverDevices( |
1242 {bool prefixWithNumber: false}) async { | 1242 {bool prefixWithNumber: false}) async { |
1243 const ipV4AddressLength = 'xxx.xxx.xxx.xxx'.length; | 1243 const ipV4AddressLength = 'xxx.xxx.xxx.xxx'.length; |
1244 print("Looking for Dartino capable devices (will search for 5 seconds)..."); | 1244 print("Looking for Dartino capable devices (will search for 5 seconds)..."); |
1245 MDnsClient client = new MDnsClient(); | 1245 MDnsClient client = new MDnsClient(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 "device_type", | 1560 "device_type", |
1561 deviceType == null ? null : unParseDeviceType(deviceType)); | 1561 deviceType == null ? null : unParseDeviceType(deviceType)); |
1562 addIfNotNull( | 1562 addIfNotNull( |
1563 "incremental_mode", | 1563 "incremental_mode", |
1564 incrementalMode == null | 1564 incrementalMode == null |
1565 ? null : unparseIncrementalMode(incrementalMode)); | 1565 ? null : unparseIncrementalMode(incrementalMode)); |
1566 | 1566 |
1567 return result; | 1567 return result; |
1568 } | 1568 } |
1569 } | 1569 } |
OLD | NEW |