| OLD | NEW |
| 1 // Copyright (c) 2012, 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 // TODO(antonm): rename to something like test_runner_updater. | 5 // TODO(antonm): rename to something like test_runner_updater. |
| 6 | 6 |
| 7 library drt_updater; | 7 library drt_updater; |
| 8 | 8 |
| 9 import "dart:async"; | 9 import "dart:async"; |
| 10 import "dart:io"; | 10 import "dart:io"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 List onUpdated; | 21 List onUpdated; |
| 22 | 22 |
| 23 Future<ProcessResult> _updatingProcess; | 23 Future<ProcessResult> _updatingProcess; |
| 24 | 24 |
| 25 _DartiumUpdater(this.name, this.script, [this.option = null]); | 25 _DartiumUpdater(this.name, this.script, [this.option = null]); |
| 26 | 26 |
| 27 void update() { | 27 void update() { |
| 28 if (!isActive) { | 28 if (!isActive) { |
| 29 isActive = true; | 29 isActive = true; |
| 30 print('Updating $name.'); | 30 print('Updating $name.'); |
| 31 onUpdated = [() {updated = true;} ]; | 31 onUpdated = [ |
| 32 () { |
| 33 updated = true; |
| 34 } |
| 35 ]; |
| 32 _updatingProcess = Process.run('python', _getUpdateCommand); | 36 _updatingProcess = Process.run('python', _getUpdateCommand); |
| 33 _updatingProcess.then(_onUpdatedHandler).catchError((e) { | 37 _updatingProcess.then(_onUpdatedHandler).catchError((e) { |
| 34 print("Error starting $script process: $e"); | 38 print("Error starting $script process: $e"); |
| 35 // TODO(floitsch): should we print the stacktrace? | 39 // TODO(floitsch): should we print the stacktrace? |
| 36 return false; | 40 return false; |
| 37 }); | 41 }); |
| 38 } | 42 } |
| 39 } | 43 } |
| 40 | 44 |
| 41 List<String> get _getUpdateCommand { | 45 List<String> get _getUpdateCommand { |
| 42 Uri updateScript = TestUtils.dartDirUri.resolve(script); | 46 Uri updateScript = TestUtils.dartDirUri.resolve(script); |
| 43 List<String> command = [updateScript.toFilePath()]; | 47 List<String> command = [updateScript.toFilePath()]; |
| 44 if (null != option) { | 48 if (null != option) { |
| 45 command.add(option); | 49 command.add(option); |
| 46 } | 50 } |
| 47 return command; | 51 return command; |
| 48 } | 52 } |
| 49 | 53 |
| 50 void _onUpdatedHandler(ProcessResult result) { | 54 void _onUpdatedHandler(ProcessResult result) { |
| 51 if (result.exitCode == 0) { | 55 if (result.exitCode == 0) { |
| 52 print('$name updated'); | 56 print('$name updated'); |
| 53 } else { | 57 } else { |
| 54 print('Failure updating $name'); | 58 print('Failure updating $name'); |
| 55 print(' Exit code: ${result.exitCode}'); | 59 print(' Exit code: ${result.exitCode}'); |
| 56 print(result.stdout); | 60 print(result.stdout); |
| 57 print(result.stderr); | 61 print(result.stderr); |
| 58 exit(1); | 62 exit(1); |
| 59 } | 63 } |
| 60 for (var callback in onUpdated ) callback(); | 64 for (var callback in onUpdated) callback(); |
| 61 } | 65 } |
| 62 } | 66 } |
| 63 | 67 |
| 64 _DartiumUpdater _contentShellUpdater; | 68 _DartiumUpdater _contentShellUpdater; |
| 65 _DartiumUpdater _dartiumUpdater; | 69 _DartiumUpdater _dartiumUpdater; |
| 66 | 70 |
| 67 _DartiumUpdater runtimeUpdater(Map configuration) { | 71 _DartiumUpdater runtimeUpdater(Map configuration) { |
| 68 String runtime = configuration['runtime']; | 72 String runtime = configuration['runtime']; |
| 69 if (runtime == 'drt' && configuration['drt'] == '') { | 73 if (runtime == 'drt' && configuration['drt'] == '') { |
| 70 // Download the default content shell from Google Storage. | 74 // Download the default content shell from Google Storage. |
| 71 if (_contentShellUpdater == null) { | 75 if (_contentShellUpdater == null) { |
| 72 _contentShellUpdater = new _DartiumUpdater('Content Shell', | 76 _contentShellUpdater = |
| 73 'tools/get_archive.py', | 77 new _DartiumUpdater('Content Shell', 'tools/get_archive.py', 'drt'); |
| 74 'drt'); | |
| 75 } | 78 } |
| 76 return _contentShellUpdater; | 79 return _contentShellUpdater; |
| 77 } else if (runtime == 'dartium' && configuration['dartium'] == '') { | 80 } else if (runtime == 'dartium' && configuration['dartium'] == '') { |
| 78 // Download the default Dartium from Google Storage. | 81 // Download the default Dartium from Google Storage. |
| 79 if (_dartiumUpdater == null) { | 82 if (_dartiumUpdater == null) { |
| 80 _dartiumUpdater = new _DartiumUpdater('Dartium Chrome', | 83 _dartiumUpdater = new _DartiumUpdater( |
| 81 'tools/get_archive.py', | 84 'Dartium Chrome', 'tools/get_archive.py', 'dartium'); |
| 82 'dartium'); | |
| 83 } | 85 } |
| 84 return _dartiumUpdater; | 86 return _dartiumUpdater; |
| 85 } else { | 87 } else { |
| 86 return null; | 88 return null; |
| 87 } | 89 } |
| 88 } | 90 } |
| OLD | NEW |