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

Filter packages to install by framework before attempting install #5041

Merged
merged 1 commit into from
Feb 10, 2022
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
19 changes: 14 additions & 5 deletions src/InstallRuntimeDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import { EventStream } from './EventStream';
import { getRuntimeDependenciesPackages } from './tools/RuntimeDependencyPackageUtils';
import { getAbsolutePathPackagesToInstall } from './packageManager/getAbsolutePathPackagesToInstall';
import IInstallDependencies from './packageManager/IInstallDependencies';
import { AbsolutePathPackage } from './packageManager/AbsolutePathPackage';

export async function installRuntimeDependencies(packageJSON: any, extensionPath: string, installDependencies: IInstallDependencies, eventStream: EventStream, platformInfo: PlatformInformation): Promise<boolean> {
let runTimeDependencies = getRuntimeDependenciesPackages(packageJSON);
let packagesToInstall = await getAbsolutePathPackagesToInstall(runTimeDependencies, platformInfo, extensionPath);
if (packagesToInstall && packagesToInstall.length > 0) {
export async function installRuntimeDependencies(packageJSON: any, extensionPath: string, installDependencies: IInstallDependencies, eventStream: EventStream, platformInfo: PlatformInformation, useFramework: boolean): Promise<boolean> {
const runTimeDependencies = getRuntimeDependenciesPackages(packageJSON);
const packagesToInstall = await getAbsolutePathPackagesToInstall(runTimeDependencies, platformInfo, extensionPath);
const filteredPackages = filterOmniSharpPackage(packagesToInstall, useFramework);

if (filteredPackages && filteredPackages.length > 0) {
eventStream.post(new PackageInstallation("C# dependencies"));
// Display platform information and RID
eventStream.post(new LogPlatformInfo(platformInfo));
if (await installDependencies(packagesToInstall)) {

if (await installDependencies(filteredPackages)) {
eventStream.post(new InstallationSuccess());
}
else {
Expand All @@ -29,3 +33,8 @@ export async function installRuntimeDependencies(packageJSON: any, extensionPath
return true;
}

function filterOmniSharpPackage(packages: AbsolutePathPackage[], useFramework: boolean) {
// Since we will have more than one OmniSharp package defined for some platforms, we need
// to filter out the one that doesn't match which dotnet runtime is being used.
return packages.filter(pkg => pkg.id != "OmniSharp" || pkg.isFramework === useFramework);
}
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
let networkSettingsProvider = vscodeNetworkSettingsProvider(vscode);
const useFramework = optionProvider.GetLatestOptions().useModernNet !== true;
let installDependencies: IInstallDependencies = async (dependencies: AbsolutePathPackage[]) => downloadAndInstallPackages(dependencies, networkSettingsProvider, eventStream, isValidDownload, useFramework);
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, installDependencies);
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, installDependencies, useFramework);

// activate language services
let langServicePromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider, extension.extensionPath);
Expand Down Expand Up @@ -228,8 +228,8 @@ function isSupportedPlatform(platform: PlatformInformation): boolean {
return false;
}

async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExtensionExports>, eventStream: EventStream, platformInfo: PlatformInformation, installDependencies: IInstallDependencies): Promise<boolean> {
return installRuntimeDependencies(extension.packageJSON, extension.extensionPath, installDependencies, eventStream, platformInfo);
async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExtensionExports>, eventStream: EventStream, platformInfo: PlatformInformation, installDependencies: IInstallDependencies, useFramework: boolean): Promise<boolean> {
return installRuntimeDependencies(extension.packageJSON, extension.extensionPath, installDependencies, eventStream, platformInfo, useFramework);
}

async function initializeDotnetPath() {
Expand Down
9 changes: 5 additions & 4 deletions test/unitTests/InstallRuntimeDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
let eventStream: EventStream;
let eventBus: TestEventBus;
let platformInfo = new PlatformInformation("platform1", "architecture1");
const useFramework = true;

setup(() => {
eventStream = new EventStream();
Expand All @@ -40,7 +41,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
});

test("True is returned", async () => {
let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo);
let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo, useFramework);
expect(installed).to.be.true;
});

Expand All @@ -49,7 +50,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
runtimeDependencies: {}
};

await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo);
await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo, useFramework);
expect(eventBus.getEvents()).to.be.empty;
});
});
Expand Down Expand Up @@ -78,15 +79,15 @@ suite(`${installRuntimeDependencies.name}`, () => {
return Promise.resolve(true);
};

let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo);
let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo, useFramework);
expect(installed).to.be.true;
expect(inputPackage).to.have.length(1);
expect(inputPackage[0]).to.be.deep.equal(AbsolutePathPackage.getAbsolutePathPackage(packageToInstall, extensionPath));
});

test("Returns false when installDependencies returns false", async () => {
installDependencies = async () => Promise.resolve(false);
let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo);
let installed = await installRuntimeDependencies(packageJSON, extensionPath, installDependencies, eventStream, platformInfo, useFramework);
expect(installed).to.be.false;
});
});
Expand Down