Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arch check for PowerShell enumeration #114292

Merged
merged 2 commits into from Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/base/node/powershell.ts
Expand Up @@ -19,7 +19,7 @@ const PwshPreviewMsixRegex: RegExp = /^Microsoft.PowerShellPreview_.*/;

// The platform details descriptor for the platform we're on
const isProcess64Bit: boolean = process.arch === 'x64';
const isOS64Bit: boolean = isProcess64Bit || env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
const isOS64Bit: boolean = isProcess64Bit || os.arch() === 'x64';

export interface IPowerShellExeDetails {
readonly displayName: string;
Expand Down
21 changes: 10 additions & 11 deletions src/vs/base/test/node/powershell.test.ts
Expand Up @@ -39,16 +39,15 @@ if (platform.isWindows) {
checkPath(exePath!);
});

test.skip('Can enumerate PowerShells', async () => { // https://github.com/microsoft/vscode/issues/114248
test('Can enumerate PowerShells', async () => {
const isOS64Bit = os.arch() === 'x64';
const pwshs = new Array<IPowerShellExeDetails>();
for await (const p of enumeratePowerShellInstallations()) {
pwshs.push(p);
}

// In Azure DevOps and GitHub Actions there should be an extra PowerShell since PowerShell 7 comes pre-installed
const minNumberOfPowerShells = process.env.TF_BUILD || process.env.CI ? 3 : 2;

assert.strictEqual(pwshs.length >= minNumberOfPowerShells, true, 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n'));
const powershellLog = 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n');
assert.strictEqual(pwshs.length >= (isOS64Bit ? 2 : 1), true, powershellLog);

for (const pwsh of pwshs) {
checkPath(pwsh.exePath);
Expand All @@ -61,23 +60,23 @@ if (platform.isWindows) {
// 64bit process on 64bit OS
if (process.arch === 'x64') {
checkPath(pwshs[secondToLastIndex].exePath);
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell');
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell', powershellLog);

checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)');
} else if (os.arch() === 'x64') {
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);
} else if (isOS64Bit) {
// 32bit process on 64bit OS

// Windows PowerShell x86 comes first if vscode is 32bit
checkPath(pwshs[secondToLastIndex].exePath);
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell (x86)');
assert.strictEqual(pwshs[secondToLastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);

checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell');
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell', powershellLog);
} else {
// 32bit or ARM process
checkPath(pwshs[lastIndex].exePath);
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)');
assert.strictEqual(pwshs[lastIndex].displayName, 'Windows PowerShell (x86)', powershellLog);
}
});
});
Expand Down