Skip to content

Commit

Permalink
Merge pull request #5041 from JoeRobich/fix-package-check
Browse files Browse the repository at this point in the history
Filter packages to install by framework before attempting install
  • Loading branch information
JoeRobich authored Feb 10, 2022
2 parents 752a56a + 1be0a7f commit 8689c41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
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

0 comments on commit 8689c41

Please sign in to comment.