| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 final String cit = Platform.isWindows ? 'cit.bat' : 'cit'; |
| 10 |
| 9 class LogdogException implements Exception { | 11 class LogdogException implements Exception { |
| 10 final int errorCode; | 12 final int errorCode; |
| 11 final String stdout; | 13 final String stdout; |
| 12 final String stderr; | 14 final String stderr; |
| 13 | 15 |
| 14 LogdogException(this.errorCode, this.stdout, this.stderr); | 16 LogdogException(this.errorCode, this.stdout, this.stderr); |
| 15 LogdogException.fromProcessResult(ProcessResult result) | 17 LogdogException.fromProcessResult(ProcessResult result) |
| 16 : this(result.exitCode, result.stdout, result.stderr); | 18 : this(result.exitCode, result.stdout, result.stderr); |
| 17 | 19 |
| 18 toString() => "Error during logdog execution:\n$stderr"; | 20 toString() => "Error during logdog execution:\n$stderr"; |
| 19 } | 21 } |
| 20 | 22 |
| 21 bool logdogCheckDone = false; | 23 bool logdogCheckDone = false; |
| 22 | 24 |
| 23 void checkLogdog({bool tryToInstall: true}) { | 25 void checkLogdog({bool tryToInstall: true}) { |
| 24 if (logdogCheckDone) return; | 26 if (logdogCheckDone) return; |
| 25 var result = Process.runSync("cit", []); | 27 var result = Process.runSync(cit, []); |
| 26 if (result.exitCode != 0) { | 28 if (result.exitCode != 0) { |
| 27 print("cit (from depot_tools) must be in the path."); | 29 print("cit (from depot_tools) must be in the path."); |
| 28 throw new StateError("cit not accessible"); | 30 throw new StateError("cit not accessible"); |
| 29 } | 31 } |
| 30 String stdout = result.stdout; | 32 String stdout = result.stdout; |
| 31 if (stdout.contains("logdog")) { | 33 if (stdout.contains("logdog")) { |
| 32 logdogCheckDone = true; | 34 logdogCheckDone = true; |
| 33 return; | 35 return; |
| 34 } | 36 } |
| 35 if (tryToInstall) { | 37 if (tryToInstall) { |
| 36 print("logdog isn't yet installed. Installation might take some time"); | 38 print("logdog isn't yet installed. Installation might take some time"); |
| 37 result = Process.runSync("cit", ["logdog"]); | 39 result = Process.runSync(cit, ["logdog"]); |
| 38 checkLogdog(tryToInstall: false); | 40 checkLogdog(tryToInstall: false); |
| 39 } else { | 41 } else { |
| 40 print("Couldn't install logdog"); | 42 print("Couldn't install logdog"); |
| 41 throw new StateError("logdog not accessible"); | 43 throw new StateError("logdog not accessible"); |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 String logdog(List<String> args) { | 47 String logdog(List<String> args) { |
| 46 checkLogdog(); | 48 checkLogdog(); |
| 47 args = args.toList()..insert(0, "logdog"); | 49 args = args.toList()..insert(0, "logdog"); |
| 48 var result = Process.runSync("cit", args); | 50 var result = Process.runSync(cit, args); |
| 49 if (result.exitCode == 0) return result.stdout; | 51 if (result.exitCode == 0) return result.stdout; |
| 50 throw new LogdogException.fromProcessResult(result); | 52 throw new LogdogException.fromProcessResult(result); |
| 51 } | 53 } |
| 52 | 54 |
| 53 String cat(String log) { | 55 String cat(String log) { |
| 54 return logdog(["cat", "-raw", log]); | 56 return logdog(["cat", "-raw", log]); |
| 55 } | 57 } |
| 56 | 58 |
| 59 /// Returns the content for [path], for instance the available build numbers |
| 60 /// for 'dart2js-linux-chromeff-1-4-be' using the path |
| 61 /// `chromium/bb/client.dart/dart2js-linux-chromeff-1-4-be`. |
| 62 String ls(String path) { |
| 63 return logdog(["ls", path]); |
| 64 } |
| 65 |
| 57 class LogResult<T> { | 66 class LogResult<T> { |
| 58 final String log; | 67 final String log; |
| 59 final T result; | 68 final T result; |
| 60 | 69 |
| 61 LogResult(this.log, this.result); | 70 LogResult(this.log, this.result); |
| 62 } | 71 } |
| 63 | 72 |
| 64 const int maxConcurrentLogdogs = 20; | 73 const int maxConcurrentLogdogs = 20; |
| 65 | 74 |
| 66 /// Fetches the given [logs] concurrently using [logdog]. | 75 /// Fetches the given [logs] concurrently using [logdog]. |
| 67 /// | 76 /// |
| 68 /// At most [maxConcurrentLogdogs] connections are opened at the same time. | 77 /// At most [maxConcurrentLogdogs] connections are opened at the same time. |
| 69 /// | 78 /// |
| 70 /// The resulting [LogResult] has a [LogResult.result] equal to `null` if | 79 /// The resulting [LogResult] has a [LogResult.result] equal to `null` if |
| 71 /// the log didn't exist. | 80 /// the log didn't exist. |
| 72 Stream<LogResult<String>> catN(Iterable<String> logs) async* { | 81 Stream<LogResult<String>> catN(Iterable<String> logs) async* { |
| 73 var queue = new Queue<Future<LogResult<ProcessResult>>>(); | 82 var queue = new Queue<Future<LogResult<ProcessResult>>>(); |
| 74 var it = logs.iterator; | 83 var it = logs.iterator; |
| 75 | 84 |
| 76 // Launches a new logdog to fetch the next log. | 85 // Launches a new logdog to fetch the next log. |
| 77 // Returns false when nothing was left to enqueue. | 86 // Returns false when nothing was left to enqueue. |
| 78 bool enqueueNext() { | 87 bool enqueueNext() { |
| 79 if (!it.moveNext()) return false; | 88 if (!it.moveNext()) return false; |
| 80 var log = it.current; | 89 var log = it.current; |
| 81 queue.add(new Future.sync(() async { | 90 queue.add(new Future.sync(() async { |
| 82 var logPath = log.substring(0, log.lastIndexOf("/")); | 91 var logPath = log.substring(0, log.lastIndexOf("/")); |
| 83 var lsResult = await Process.run("cit", ["logdog", "ls", logPath]); | 92 var lsResult = await Process.run(cit, ["logdog", "ls", logPath]); |
| 84 if (lsResult.exitCode != 0) return new LogResult(log, lsResult); | 93 if (lsResult.exitCode != 0) return new LogResult(log, lsResult); |
| 85 if (lsResult.stdout == "") return new LogResult(log, null); | 94 if (lsResult.stdout == "") return new LogResult(log, null); |
| 86 return new LogResult( | 95 return new LogResult( |
| 87 log, await Process.run("cit", ["logdog", "cat", "-raw", log])); | 96 log, await Process.run(cit, ["logdog", "cat", "-raw", log])); |
| 88 })); | 97 })); |
| 89 return true; | 98 return true; |
| 90 } | 99 } |
| 91 | 100 |
| 92 for (int i = 0; i < maxConcurrentLogdogs; i++) { | 101 for (int i = 0; i < maxConcurrentLogdogs; i++) { |
| 93 enqueueNext(); | 102 enqueueNext(); |
| 94 } | 103 } |
| 95 | 104 |
| 96 while (queue.isNotEmpty) { | 105 while (queue.isNotEmpty) { |
| 97 var logResult = | 106 var logResult = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 117 "/+/recipes/steps/dart2js_ie11_tests/0/stdout"; | 126 "/+/recipes/steps/dart2js_ie11_tests/0/stdout"; |
| 118 })).listen((logResult) { | 127 })).listen((logResult) { |
| 119 print("--------------------------"); | 128 print("--------------------------"); |
| 120 if (logResult.result == null) { | 129 if (logResult.result == null) { |
| 121 print("${logResult.log} - empty"); | 130 print("${logResult.log} - empty"); |
| 122 } else { | 131 } else { |
| 123 print(logResult.result.substring(0, 200)); | 132 print(logResult.result.substring(0, 200)); |
| 124 } | 133 } |
| 125 }); | 134 }); |
| 126 } | 135 } |
| 127 */ | 136 */ |
| OLD | NEW |