From 7168a37a941fe67a15fd44e170f012943926d81f Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 25 Oct 2024 16:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9hvigorw=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=9A=84=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../flutter_tools/lib/src/ohos/hvigor.dart | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/ohos/hvigor.dart b/packages/flutter_tools/lib/src/ohos/hvigor.dart index 76765f4b15..9619e58d9c 100644 --- a/packages/flutter_tools/lib/src/ohos/hvigor.dart +++ b/packages/flutter_tools/lib/src/ohos/hvigor.dart @@ -13,6 +13,7 @@ * limitations under the License. */ +import 'dart:convert'; import 'dart:io'; import 'package:json5/json5.dart'; @@ -157,15 +158,53 @@ void replaceKey(File file, File target, String key, String value) { target.writeAsStringSync(content); } +Future invokeCmd( + {required List command, + required String workDirectory, + required ProcessManager processManager, + Logger? logger}) async { + final String cmd = command.join(' '); + logger?.printTrace('Invoke cmd: $cmd'); + final Process server = + await processManager.start(command, workingDirectory: workDirectory); + + server.stderr + .transform(utf8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + if (line.toLowerCase().contains('error:')) { + logger?.printError(line); + } else { + logger?.printTrace(line); + } + }); + server.stdout + .transform(utf8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + logger?.printTrace(line); + }); + final int exitCode = await server.exitCode; + if (exitCode == 0) { + logger?.printTrace('Invoke success: $cmd'); + } else { + logger?.printError('Invoke error: $cmd'); + } + return exitCode; +} + ///hvigorw任务 Future hvigorwTask(List taskCommand, {required ProcessUtils processUtils, required String workPath, required String hvigorwPath, Logger? logger}) async { - final RunResult result = processUtils.runSync(taskCommand, - workingDirectory: workPath, throwOnError: true); - return result.exitCode; + final int code = await invokeCmd( + command: taskCommand, + workDirectory: workPath, + processManager: globals.processManager, + logger: logger); + return code; } Future assembleHap( -- Gitee