forked from firka/flutter
[ Tool ] Support Powershell v6+ to determine Windows version in flutter doctor (#156476)
Powershell v6+ use the executable name `pwsh.exe` instead of `powershell.exe`. This change adds support for determining the Windows version on systems that solely use `pwsh.exe` and don't have `powershell.exe` on the `PATH`. Fixes #156189. --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
This commit is contained in:
@@ -37,9 +37,22 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
final ProcessLister _processLister;
|
||||
|
||||
Future<ValidationResult> _topazScan() async {
|
||||
if (!_processLister.canRunPowershell()) {
|
||||
return const ValidationResult(
|
||||
ValidationType.missing,
|
||||
<ValidationMessage>[
|
||||
ValidationMessage.hint('Failed to find ${ProcessLister.powershell} or ${ProcessLister.pwsh} on PATH'),
|
||||
],
|
||||
);
|
||||
}
|
||||
final ProcessResult getProcessesResult = await _processLister.getProcessesWithPath();
|
||||
if (getProcessesResult.exitCode != 0) {
|
||||
return const ValidationResult(ValidationType.missing, <ValidationMessage>[ValidationMessage.hint('Get-Process failed to complete')]);
|
||||
return const ValidationResult(
|
||||
ValidationType.missing,
|
||||
<ValidationMessage>[
|
||||
ValidationMessage.hint('Get-Process failed to complete'),
|
||||
],
|
||||
);
|
||||
}
|
||||
final RegExp topazRegex = RegExp(kCoreProcessPattern, caseSensitive: false, multiLine: true);
|
||||
final String processes = getProcessesResult.stdout as String;
|
||||
@@ -106,8 +119,22 @@ class ProcessLister {
|
||||
|
||||
final ProcessManager processManager;
|
||||
|
||||
static const String powershell = 'powershell';
|
||||
static const String pwsh = 'pwsh';
|
||||
|
||||
bool canRunPowershell() {
|
||||
return processManager.canRun(powershell) || processManager.canRun(pwsh);
|
||||
}
|
||||
|
||||
Future<ProcessResult> getProcessesWithPath() async {
|
||||
const String argument = 'Get-Process | Format-List Path';
|
||||
return processManager.run(<String>['powershell', '-command', argument]);
|
||||
const List<String> psArgs = <String>['-command', argument];
|
||||
if (processManager.canRun(powershell)) {
|
||||
return processManager.run(<String>[powershell, ...psArgs]);
|
||||
}
|
||||
if (processManager.canRun(pwsh)) {
|
||||
return processManager.run(<String>[pwsh, ...psArgs]);
|
||||
}
|
||||
throw StateError('Failed to find $powershell or $pwsh on PATH');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user