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

Add PATH for Arm emulation x64 on Mac #1932

Merged
merged 8 commits into from
Sep 11, 2024
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.
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 @@ -476,7 +476,7 @@ To keep your .NET version up to date, please reconnect to the internet at your s
}

let dotnetPath : string = await installer.getExpectedGlobalSDKPath(installingVersion,
context.acquisitionContext.architecture ?? this.getDefaultInternalArchitecture(context.acquisitionContext.architecture));
context.acquisitionContext.architecture ?? this.getDefaultInternalArchitecture(context.acquisitionContext.architecture), false);
const existingInstall = await this.getExistingInstall(context, installedVersions, install, dotnetPath);
if(existingInstall)
{
Expand All @@ -501,6 +501,10 @@ ${WinMacGlobalInstaller.InterpretExitCode(installerResult)}`), install);

TelemetryUtilities.setDotnetSDKTelemetryToMatch(context.isExtensionTelemetryInitiallyEnabled, this.extensionContext, context, this.utilityContext).catch(() => {});

// in case the path does not exist, try resetting the path using an automatic path search setting
dotnetPath = await installer.getExpectedGlobalSDKPath(installingVersion,
context.acquisitionContext.architecture ?? this.getDefaultInternalArchitecture(context.acquisitionContext.architecture));

try
{
context.installationValidator.validateDotnetInstall(install, dotnetPath, os.platform() !== 'win32');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class IGlobalInstaller {

public abstract uninstallSDK(install : DotnetInstall) : Promise<string>

public abstract getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string) : Promise<string>
public abstract getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string, macPathShouldExist? : boolean) : Promise<string>

public abstract getGlobalSdkVersionsInstalledOnMachine() : Promise<Array<string>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class LinuxGlobalInstaller extends IGlobalInstaller {
return this.linuxSDKResolver.UninstallSDK(this.version);
}

public async getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string) : Promise<string>
public async getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string, macPathShouldExist = true) : Promise<string>
{
await this.linuxSDKResolver.Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Permissions: ${JSON.stringify(await this.commandRunner.execute(CommandExecutor.m

// async is needed to match the interface even if we don't use await.
// eslint-disable-next-line @typescript-eslint/require-await
public async getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string) : Promise<string>
public async getExpectedGlobalSDKPath(specificSDKVersionInstalled : string, installedArch : string, macPathShouldExist = true) : Promise<string>
{
if(os.platform() === 'win32')
{
Expand All @@ -330,7 +330,7 @@ Permissions: ${JSON.stringify(await this.commandRunner.execute(CommandExecutor.m
}
else if(os.platform() === 'darwin')
{
return this.getMacPath();
return this.getMacPath(macPathShouldExist);
}

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

private getMacPath() : string
private getMacPath(macPathShouldExist = true) : string
{
// On an arm machine we would install to /usr/local/share/dotnet/x64/dotnet/sdk` for a 64 bit sdk
// but we don't currently allow customizing the install architecture so that would never happen.
return path.resolve(`/usr/local/share/dotnet/dotnet`);
const standardHostPath = path.resolve(`/usr/local/share/dotnet/dotnet`);
const arm64EmulationHostPath = path.resolve(`/usr/local/share/dotnet/x64/dotnet`);
if(!macPathShouldExist || fs.existsSync(standardHostPath) || !fs.existsSync(arm64EmulationHostPath))
{
return standardHostPath;
}
return arm64EmulationHostPath;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,34 @@ ${fs.readdirSync(installerDownloadFolder).join(', ')}`);
await installer.installSDK(install);
mockExecutor.resetReturnValues();
}).timeout(150000);

test('It will use arm64 emulation path IFF path does not exist and option to use it is set', async () =>
{
if(os.platform() === 'darwin')
{
const sdkVersionThatShouldNotExist = '3.0.500';
const standardHostPath = path.resolve(`/usr/local/share/dotnet/dotnet`);
const arm64EmulationHostPath = path.resolve(`/usr/local/share/dotnet/x64/dotnet`);

let cleanUpPath = false;
const defaultPath = await installer.getExpectedGlobalSDKPath(sdkVersionThatShouldNotExist, os.arch(), false);
if(!fs.existsSync(arm64EmulationHostPath))
{
fs.mkdirSync(arm64EmulationHostPath, {recursive: true});
cleanUpPath = true;
}
let shouldNotExistOptionPath = await installer.getExpectedGlobalSDKPath(sdkVersionThatShouldNotExist, os.arch());

assert.equal(defaultPath, standardHostPath, 'It uses the standard path if false is set and path dne');
assert.equal(shouldNotExistOptionPath, arm64EmulationHostPath, 'It uses the emu path if the std path does not exist and option is set');

if(cleanUpPath)
{
fs.rmdirSync(arm64EmulationHostPath, {recursive: true});

shouldNotExistOptionPath = await installer.getExpectedGlobalSDKPath(sdkVersionThatShouldNotExist, os.arch());
assert.equal(shouldNotExistOptionPath, standardHostPath, 'It wont use the emu path if it does not exist');
}
}
}).timeout(standardTimeoutTime);
});