From 7e8731ff980132ae07cfcefd5fce45ee3d119fe1 Mon Sep 17 00:00:00 2001 From: rainy liu Date: Fri, 3 Apr 2026 16:28:41 +0800 Subject: [PATCH 1/2] fix(run_process): add encoding parameter to runProcess for consistent output decoding --- lib/src/native_toolchain/msvc.dart | 2 + lib/src/utils/run_process.dart | 60 +++++++++++++++--------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/src/native_toolchain/msvc.dart b/lib/src/native_toolchain/msvc.dart index cbe4082..dc4343c 100644 --- a/lib/src/native_toolchain/msvc.dart +++ b/lib/src/native_toolchain/msvc.dart @@ -269,6 +269,7 @@ class VisualStudioResolver implements ToolResolver { arguments: arguments, logger: logger, environment: environment, + encoding: utf8, ); var toolInfos = json.decode(vswhereResult.stdout) as List; // Try again including prerelease versions if no stable versions found. @@ -278,6 +279,7 @@ class VisualStudioResolver implements ToolResolver { arguments: [...arguments, '-prerelease'], logger: logger, environment: environment, + encoding: utf8, ); toolInfos = json.decode(vswhereResult.stdout) as List; } diff --git a/lib/src/utils/run_process.dart b/lib/src/utils/run_process.dart index 3b156b9..c9682ef 100644 --- a/lib/src/utils/run_process.dart +++ b/lib/src/utils/run_process.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:logging/logging.dart'; @@ -21,6 +22,7 @@ Future runProcess({ bool captureOutput = true, int expectedExitCode = 0, bool throwOnUnexpectedExitCode = false, + Encoding encoding = systemEncoding, }) async { final printWorkingDir = workingDirectory != null && workingDirectory != Directory.current.uri; final commandString = [ @@ -42,37 +44,36 @@ Future runProcess({ runInShell: false, ); - final stdoutSub = process.stdout.listen( - (List data) { - try { - final decodedData = systemEncoding.decode(data); - logger?.fine(decodedData); - if (captureOutput) { - stdoutBuffer.write(decodedData); - } - } catch (e) { - logger?.warning('Failed to decode stdout: $e'); - stdoutBuffer.write('Failed to decode stdout: $e'); + final stdoutSub = process.stdout.listen((List data) { + try { + final decodedData = encoding.decode(data); + logger?.fine(decodedData); + if (captureOutput) { + stdoutBuffer.write(decodedData); } - }, - ); - final stderrSub = process.stderr.listen( - (List data) { - try { - final decodedData = systemEncoding.decode(data); - logger?.severe(decodedData); - if (captureOutput) { - stderrBuffer.write(decodedData); - } - } catch (e) { - logger?.severe('Failed to decode stderr: $e'); - stderrBuffer.write('Failed to decode stderr: $e'); + } catch (e) { + logger?.warning('Failed to decode stdout: $e'); + stdoutBuffer.write('Failed to decode stdout: $e'); + } + }); + final stderrSub = process.stderr.listen((List data) { + try { + final decodedData = encoding.decode(data); + logger?.severe(decodedData); + if (captureOutput) { + stderrBuffer.write(decodedData); } - }, - ); + } catch (e) { + logger?.severe('Failed to decode stderr: $e'); + stderrBuffer.write('Failed to decode stderr: $e'); + } + }); - final (exitCode, _, _) = - await (process.exitCode, stdoutSub.asFuture(), stderrSub.asFuture()).wait; + final (exitCode, _, _) = await ( + process.exitCode, + stdoutSub.asFuture(), + stderrSub.asFuture(), + ).wait; await stdoutSub.cancel(); await stderrSub.cancel(); @@ -172,7 +173,8 @@ class RunProcessResult { }); @override - String toString() => '''command: $command + String toString() => + '''command: $command exitCode: $exitCode stdout: $stdout stderr: $stderr'''; From 1053e56e3a4ba7da0a8915f34819fe3cff40f1b4 Mon Sep 17 00:00:00 2001 From: rainy liu Date: Fri, 3 Apr 2026 16:31:06 +0800 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12a9aec..d9a423e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # native_toolchain_cmake +## 0.2.5 + +- fix: add encoding parameter (default is `systemEncoding`) to runProcess for consistent output decoding + ## 0.2.4 - new: add `parallelJobs` and `parallelUseAllProcessors` to support parallel build or set njobs explicitly. diff --git a/pubspec.yaml b/pubspec.yaml index 748b3c2..6c4db05 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: native_toolchain_cmake description: >- A library to invoke and build CMake projects for Dart Native Assets. -version: 0.2.4 +version: 0.2.5 repository: https://github.com/rainyl/native_toolchain_cmake topics: