| 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 #library("drt_updater"); | 5 #library("drt_updater"); |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("dart:builtin"); | 8 #import("dart:builtin"); |
| 9 | 9 |
| 10 class DumpRenderTreeUpdater { | 10 class _DartiumUpdater { |
| 11 static bool isActive = false; | 11 String name; |
| 12 static bool updated = false; | 12 String script; |
| 13 static List onUpdated; | 13 String option; |
| 14 | 14 |
| 15 static Process _updatingProcess; | 15 bool isActive = false; |
| 16 bool updated = false; |
| 17 List onUpdated; |
| 16 | 18 |
| 17 static void update() { | 19 Process _updatingProcess; |
| 20 |
| 21 _DartiumUpdater(this.name, this.script, [this.option = null]); |
| 22 |
| 23 void update() { |
| 18 if (!isActive) { | 24 if (!isActive) { |
| 19 isActive = true; | 25 isActive = true; |
| 20 print('Updating DumpRenderTree.'); | 26 print('Updating $name.'); |
| 21 onUpdated = [() {updated = true;} ]; | 27 onUpdated = [() {updated = true;} ]; |
| 22 _updatingProcess = new Process.start('python', [_getDrtPath]); | 28 _updatingProcess = new Process.start('python', _getUpdateCommand); |
| 23 _updatingProcess.onExit = _onUpdatedHandler; | 29 _updatingProcess.onExit = _onUpdatedHandler; |
| 24 _updatingProcess.onError = (error) { | 30 _updatingProcess.onError = (error) { |
| 25 print("Error starting get_drt.py process: $error"); | 31 print("Error starting $script process: $error"); |
| 26 _onUpdatedHandler(-1); // Continue anyway. | 32 _onUpdatedHandler(-1); // Continue anyway. |
| 27 }; | 33 }; |
| 28 } | 34 } |
| 29 } | 35 } |
| 30 | 36 |
| 31 static String get _getDrtPath() { | 37 String get _getUpdateCommand() { |
| 32 String scriptPath = new Options().script.replaceAll('\\', '/'); | 38 String scriptPath = new Options().script.replaceAll('\\', '/'); |
| 33 String toolsDir = scriptPath.substring(0, scriptPath.lastIndexOf('/')); | 39 String toolsDir = scriptPath.substring(0, scriptPath.lastIndexOf('/')); |
| 34 return '$toolsDir/get_drt.py'; | 40 List<String> command = ['$toolsDir/$script']; |
| 41 if (null !== option) { |
| 42 command.add(option); |
| 43 } |
| 44 return command; |
| 35 } | 45 } |
| 36 | 46 |
| 37 static void _onUpdatedHandler(int exit_code) { | 47 void _onUpdatedHandler(int exit_code) { |
| 38 print('DumpRenderTree updated ($exit_code)'); | 48 print('$name updated ($exit_code)'); |
| 39 for (var callback in onUpdated ) callback(); | 49 for (var callback in onUpdated ) callback(); |
| 40 } | 50 } |
| 41 } | 51 } |
| 52 |
| 53 _DartiumUpdater _dumpRenderTreeUpdater; |
| 54 _DartiumUpdater _dartiumUpdater; |
| 55 |
| 56 _DartiumUpdater runtimeUpdater(String runtime) { |
| 57 if (runtime == 'drt') { |
| 58 if (_dumpRenderTreeUpdater === null) { |
| 59 _dumpRenderTreeUpdater = new _DartiumUpdater('DumpRenderTree', |
| 60 'get_drt.py'); |
| 61 } |
| 62 return _dumpRenderTreeUpdater; |
| 63 } else if (runtime == 'dartium') { |
| 64 if (_dartiumUpdater === null) { |
| 65 _dartiumUpdater = new _DartiumUpdater('Dartium Chrome', 'get_drt.py', |
| 66 '--dartium'); |
| 67 } |
| 68 return _dartiumUpdater; |
| 69 } else { |
| 70 return null; |
| 71 } |
| 72 } |
| OLD | NEW |