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

Improve ARM Mac Path Check #1947

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ This report should be made at https://github.com/dotnet/vscode-dotnet-runtime/is
}
else
{
const command = CommandExecutor.makeCommand(`rm`, [`-rf`, `${path.join(path.dirname(this.getMacPath()), 'sdk', install.version)}`, `&&`,
`rm`, `-rf`, `${path.join(path.dirname(this.getMacPath()), 'sdk-manifests', install.version)}`], true);
const macPath = await this.getMacPath();
const command = CommandExecutor.makeCommand(`rm`, [`-rf`, `${path.join(path.dirname(macPath), 'sdk', install.version)}`, `&&`,
`rm`, `-rf`, `${path.join(path.dirname(macPath), 'sdk-manifests', install.version)}`], true);

const commandResult = await this.commandRunner.execute(command, {timeout : this.acquisitionContext.timeoutSeconds * 1000});
this.handleTimeout(commandResult);
Expand Down Expand Up @@ -330,7 +331,8 @@ Permissions: ${JSON.stringify(await this.commandRunner.execute(CommandExecutor.m
}
else if(os.platform() === 'darwin')
{
return this.getMacPath(macPathShouldExist);
const sdkPath = await this.getMacPath(macPathShouldExist);
return sdkPath;
}

const err = new DotnetUnexpectedInstallerOSError(new EventBasedError('DotnetUnexpectedInstallerOSError',
Expand All @@ -352,10 +354,19 @@ If you were waiting for the install to succeed, please extend the timeout settin
}
}

private getMacPath(macPathShouldExist = true) : string
private async getMacPath(macPathShouldExist = true) : Promise<string>
{
const standardHostPath = path.resolve(`/usr/local/share/dotnet/dotnet`);
const arm64EmulationHostPath = path.resolve(`/usr/local/share/dotnet/x64/dotnet`);

const findTrueArchCommand = CommandExecutor.makeCommand(`uname`, [`-p`]);
if((os.arch() === 'x64' || os.arch() === 'ia32') && (await this.commandRunner.execute(findTrueArchCommand, null, false)).stdout.toLowerCase().includes('arm') && (fs.existsSync(arm64EmulationHostPath) || !macPathShouldExist))
{
// VS Code runs on an emulated version of node which will return x64 or use x86 emulation for ARM devices.
// os.arch() returns the architecture of the node binary, not the system architecture, so it will not report arm on an arm device.
return arm64EmulationHostPath;
}

if(!macPathShouldExist || fs.existsSync(standardHostPath) || !fs.existsSync(arm64EmulationHostPath))
{
return standardHostPath;
Expand Down