From a8ecbc390b2bfb866466f4cbf62a7691f63fa31c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 14 Dec 2018 09:08:02 -0800 Subject: [PATCH 1/5] Handle failures when determining version of OS --- news/2 Fixes/3693.md | 1 + src/client/common/platform/platformService.ts | 21 +++++++++++++++---- src/client/telemetry/constants.ts | 4 +++- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 news/2 Fixes/3693.md diff --git a/news/2 Fixes/3693.md b/news/2 Fixes/3693.md new file mode 100644 index 000000000000..26085091b8e4 --- /dev/null +++ b/news/2 Fixes/3693.md @@ -0,0 +1 @@ +Handle failures when determining version of OS. diff --git a/src/client/common/platform/platformService.ts b/src/client/common/platform/platformService.ts index 5f80320ecd05..086afe3d7d16 100644 --- a/src/client/common/platform/platformService.ts +++ b/src/client/common/platform/platformService.ts @@ -108,14 +108,27 @@ async function getLinuxDistro(): Promise<[OSDistro, SemVer]> { // tslint:disable-next-line:no-require-imports const getos = require('getos') as typeof import('getos'); // tslint:disable-next-line:no-any - getos((exc: Error, info: any) => { + getos((exc: Error, info: { dist?: string; release?: string }) => { if (exc) { + traceError('getos failed', exc); sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToGetLinuxInfo }); return reject(exc); } - distro = getLinuxDistroFromName(info.dist); - version = parseVersion(info.release); - resolve([distro, version]); + try { + distro = getLinuxDistroFromName(info.dist!); + } catch (ex) { + traceError('getLinuxDistroFromName failed in getLinuxDistro', exc); + sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineDistro }); + return reject(ex); + } + try { + version = parseVersion(info.release!); + resolve([distro, version]); + } catch (ex) { + traceError('parseVersion failed in getLinuxDistro', exc); + sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineVersion }); + return reject(ex); + } }); }); } diff --git a/src/client/telemetry/constants.ts b/src/client/telemetry/constants.ts index 5fe05301f6a3..c119c99fdfcd 100644 --- a/src/client/telemetry/constants.ts +++ b/src/client/telemetry/constants.ts @@ -52,5 +52,7 @@ export const PLATFORM_INFO = 'PLATFORM.INFO'; export enum PlatformErrors { FailedToParseVersion = 'FailedToParseVersion', FailedToGetLinuxInfo = 'FailedToGetLinuxInfo', - FailedToDetermineOS = 'FailedToDetermineOS' + FailedToDetermineOS = 'FailedToDetermineOS', + FailedToDetermineDistro = 'FailedToDetermineDistro', + FailedToDetermineVersion = 'FailedToDetermineVersion' } From 17ec7a0a5025488f1f7335e14b6c7bcda1429252 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 14 Dec 2018 09:12:20 -0800 Subject: [PATCH 2/5] Log result from getos --- src/client/common/platform/platformService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/common/platform/platformService.ts b/src/client/common/platform/platformService.ts index 086afe3d7d16..427586c8c61e 100644 --- a/src/client/common/platform/platformService.ts +++ b/src/client/common/platform/platformService.ts @@ -7,7 +7,7 @@ import * as os from 'os'; import { coerce, SemVer } from 'semver'; import { sendTelemetryEvent } from '../../telemetry'; import { PLATFORM_INFO, PlatformErrors } from '../../telemetry/constants'; -import { traceDecorators, traceError } from '../logger'; +import { traceDecorators, traceError, traceVerbose } from '../logger'; import { OSDistro, OSType } from '../utils/platform'; import { parseVersion } from '../utils/version'; import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants'; @@ -109,6 +109,7 @@ async function getLinuxDistro(): Promise<[OSDistro, SemVer]> { const getos = require('getos') as typeof import('getos'); // tslint:disable-next-line:no-any getos((exc: Error, info: { dist?: string; release?: string }) => { + traceVerbose(`getos result ${info ? JSON.stringify(info) : ''}`); if (exc) { traceError('getos failed', exc); sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToGetLinuxInfo }); From 37273cc6096703517b333811034e48194be1399e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 14 Dec 2018 09:14:42 -0800 Subject: [PATCH 3/5] move logging --- src/client/common/platform/platformService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/platform/platformService.ts b/src/client/common/platform/platformService.ts index 427586c8c61e..f82f702e7d9a 100644 --- a/src/client/common/platform/platformService.ts +++ b/src/client/common/platform/platformService.ts @@ -109,12 +109,12 @@ async function getLinuxDistro(): Promise<[OSDistro, SemVer]> { const getos = require('getos') as typeof import('getos'); // tslint:disable-next-line:no-any getos((exc: Error, info: { dist?: string; release?: string }) => { - traceVerbose(`getos result ${info ? JSON.stringify(info) : ''}`); if (exc) { traceError('getos failed', exc); sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToGetLinuxInfo }); return reject(exc); } + traceVerbose(`getos result ${info ? JSON.stringify(info) : ''}`); try { distro = getLinuxDistroFromName(info.dist!); } catch (ex) { From c88130144e9f0b6519d5a1942096f0fc1917359c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 14 Dec 2018 10:19:07 -0800 Subject: [PATCH 4/5] Changed rules for LS support --- build/webpack/loaders/fixGetosRequire.js | 14 --- build/webpack/loaders/fixGetosRequire.ts | 14 --- build/webpack/webpack.debugadapter.config.js | 12 +-- build/webpack/webpack.debugadapter.config.ts | 12 +-- build/webpack/webpack.extension.config.js | 10 --- build/webpack/webpack.extension.config.ts | 10 --- news/2 Fixes/3693.md | 2 +- package-lock.json | 18 ---- package.json | 3 +- .../services/linuxCompatibilityService.ts | 63 +------------ .../services/windowsCompatibilityService.ts | 11 +-- src/client/common/platform/platformService.ts | 88 +------------------ src/client/common/platform/types.ts | 3 +- src/client/common/utils/platform.ts | 15 ---- src/client/telemetry/types.ts | 2 - .../linuxCompatibilityService.unit.test.ts | 74 ++-------------- .../winCompatibilityService.unit.test.ts | 31 ++----- ...e.unit.test.ts => platformService.test.ts} | 66 +------------- 18 files changed, 28 insertions(+), 420 deletions(-) delete mode 100644 build/webpack/loaders/fixGetosRequire.js delete mode 100644 build/webpack/loaders/fixGetosRequire.ts rename src/test/common/platform/{platformService.unit.test.ts => platformService.test.ts} (54%) diff --git a/build/webpack/loaders/fixGetosRequire.js b/build/webpack/loaders/fixGetosRequire.js deleted file mode 100644 index 70f5d4d08121..000000000000 --- a/build/webpack/loaders/fixGetosRequire.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -// tslint:disable:no-default-export no-invalid-this -function default_1(source) { - const code = 'var logic = path.join(__dirname, \'logic/\' + name + \'.js\')'; - if (source.indexOf(code) === -1) { - throw new Error('Code to replace not found in getos'); - } - source = source.replace(code, 'var logic = \'./logic/\' + name + \'.js\''); - return source; -} -exports.default = default_1; diff --git a/build/webpack/loaders/fixGetosRequire.ts b/build/webpack/loaders/fixGetosRequire.ts deleted file mode 100644 index a659ac20f487..000000000000 --- a/build/webpack/loaders/fixGetosRequire.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -// tslint:disable:no-default-export no-invalid-this -export default function (source: string) { - const code = 'var logic = path.join(__dirname, \'logic/\' + name + \'.js\')'; - if (source.indexOf(code) === -1) { - throw new Error('Code to replace not found in getos'); - } - source = source.replace(code, 'var logic = \'./logic/\' + name + \'.js\''); - return source; -} diff --git a/build/webpack/webpack.debugadapter.config.js b/build/webpack/webpack.debugadapter.config.js index c9fbb9065c2c..82e48252ee5e 100644 --- a/build/webpack/webpack.debugadapter.config.js +++ b/build/webpack/webpack.debugadapter.config.js @@ -30,15 +30,6 @@ const config = { } ] }, - { - // Do not use __dirname in getos when using require. - test: /getos[\\\/]index.js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixGetosRequire.js') - } - ] - }, { test: /\.ts$/, exclude: /node_modules/, @@ -55,8 +46,7 @@ const config = { 'commonjs' ], plugins: [ - ...common_1.getDefaultPlugins('extension'), - new webpack_1.ContextReplacementPlugin(/getos/, /logic\/.*.js/) + ...common_1.getDefaultPlugins('extension') ], resolve: { extensions: ['.ts', '.js'], diff --git a/build/webpack/webpack.debugadapter.config.ts b/build/webpack/webpack.debugadapter.config.ts index 9b9d77b425e8..7f5b4f0ee728 100644 --- a/build/webpack/webpack.debugadapter.config.ts +++ b/build/webpack/webpack.debugadapter.config.ts @@ -33,15 +33,6 @@ const config: Configuration = { } ] }, - { - // Do not use __dirname in getos when using require. - test: /getos[\\\/]index.js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixGetosRequire.js') - } - ] - }, { test: /\.ts$/, exclude: /node_modules/, @@ -58,8 +49,7 @@ const config: Configuration = { 'commonjs' ], plugins: [ - ...getDefaultPlugins('extension'), - new ContextReplacementPlugin(/getos/, /logic\/.*.js/) + ...getDefaultPlugins('extension') ], resolve: { extensions: ['.ts', '.js'], diff --git a/build/webpack/webpack.extension.config.js b/build/webpack/webpack.extension.config.js index 2b94dcc229fa..f30cb43bd08e 100644 --- a/build/webpack/webpack.extension.config.js +++ b/build/webpack/webpack.extension.config.js @@ -35,15 +35,6 @@ const config = { } ] }, - { - // Do not use __dirname in getos when using require. - test: /getos[\\\/]index.js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixGetosRequire.js') - } - ] - }, { test: /\.ts$/, use: [ @@ -70,7 +61,6 @@ const config = { ], plugins: [ ...common_1.getDefaultPlugins('extension'), - new webpack_1.ContextReplacementPlugin(/getos/, /logic\/.*.js/), new WrapperPlugin({ test: /\extension.js$/, // Import source map warning file only if source map is enabled. diff --git a/build/webpack/webpack.extension.config.ts b/build/webpack/webpack.extension.config.ts index 9e551eac33f9..7d84edd037a9 100644 --- a/build/webpack/webpack.extension.config.ts +++ b/build/webpack/webpack.extension.config.ts @@ -40,15 +40,6 @@ const config: Configuration = { } ] }, - { - // Do not use __dirname in getos when using require. - test: /getos[\\\/]index.js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixGetosRequire.js') - } - ] - }, { test: /\.ts$/, use: [ @@ -75,7 +66,6 @@ const config: Configuration = { ], plugins: [ ...getDefaultPlugins('extension'), - new ContextReplacementPlugin(/getos/, /logic\/.*.js/), new WrapperPlugin({ test: /\extension.js$/, // Import source map warning file only if source map is enabled. diff --git a/news/2 Fixes/3693.md b/news/2 Fixes/3693.md index 26085091b8e4..37241de43743 100644 --- a/news/2 Fixes/3693.md +++ b/news/2 Fixes/3693.md @@ -1 +1 @@ -Handle failures when determining version of OS. +Lowering threshold for Language Server support on a platform. diff --git a/package-lock.json b/package-lock.json index ea0429dd62ce..bf5bad09c765 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7034,24 +7034,6 @@ "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=" }, - "getos": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/getos/-/getos-3.1.0.tgz", - "integrity": "sha512-i9vrxtDu5DlLVFcrbqUqGWYlZN/zZ4pGMICCAcZoYsX3JA54nYp8r5EThw5K+m2q3wszkx4Th746JstspB0H4Q==", - "requires": { - "async": "2.4.0" - }, - "dependencies": { - "async": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/async/-/async-2.4.0.tgz", - "integrity": "sha1-SZAgDxjqW4N8LMT4wDGmmFw4VhE=", - "requires": { - "lodash": "^4.14.0" - } - } - } - }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", diff --git a/package.json b/package.json index 2e4ada013da7..7a7337dea8ed 100644 --- a/package.json +++ b/package.json @@ -1860,7 +1860,7 @@ "compile-webviews-verbose": "npx webpack --config webpack.datascience-ui.config.js", "postinstall": "node ./node_modules/vscode/bin/install", "test": "node ./out/test/standardTest.js && node ./out/test/multiRootTest.js", - "test:unittests": "mocha --opts ./build/.mocha.unittests.opts", + "test:unittests": "mocha --opts ./build/.mocha.unittests.opts --grep='PlatformService'", "test:unittests:cover": "nyc --nycrc-path ./build/.nycrc npm run test:unittests", "test:functional": "mocha --opts ./build/.mocha.functional.opts", "test:functional:cover": "nyc--nycrc-path ./build/.nycrc npm run test:functional", @@ -1886,7 +1886,6 @@ "fs-extra": "^4.0.3", "fuzzy": "^0.1.3", "get-port": "^3.2.0", - "getos": "^3.1.0", "glob": "^7.1.2", "iconv-lite": "^0.4.21", "inversify": "^4.11.1", diff --git a/src/client/common/dotnet/services/linuxCompatibilityService.ts b/src/client/common/dotnet/services/linuxCompatibilityService.ts index 2d96fe6a7c95..b53ed2bd469b 100644 --- a/src/client/common/dotnet/services/linuxCompatibilityService.ts +++ b/src/client/common/dotnet/services/linuxCompatibilityService.ts @@ -4,76 +4,19 @@ 'use strict'; import { inject, injectable } from 'inversify'; -import { SemVer } from 'semver'; import { traceDecorators, traceError } from '../../logger'; import { IPlatformService } from '../../platform/types'; -import { OSDistro } from '../../utils/platform'; -import { parseVersion } from '../../utils/version'; import { IOSDotNetCompatibilityService } from '../types'; -// Versions on https://github.com/dotnet/core/blob/master/release-notes/2.1/2.1-supported-os.md -// We are not goind to restrict to exact versions. -// Its possible .net core updates will go out before we can update this code. -// So lets assume that .net core will be supported on this minimum versions. -const versionsPerDistro = new Map(); -versionsPerDistro.set(OSDistro.RHEL, ['6.0.0', '7.0.0']); -versionsPerDistro.set(OSDistro.CentOS, ['7.0.0']); -versionsPerDistro.set(OSDistro.Oracle, ['7.0.0']); -versionsPerDistro.set(OSDistro.Fedora, ['27.0.0', '28.0.0']); -versionsPerDistro.set(OSDistro.Debian, ['9.0.0', '8.7.0']); -versionsPerDistro.set(OSDistro.Ubuntu, ['18.04.0', '16.04.0', '14.04.0']); -versionsPerDistro.set(OSDistro.Mint, ['18.0.0', '17.0.0']); -versionsPerDistro.set(OSDistro.Suse, ['42.3.0', '12.0.0']); -versionsPerDistro.set(OSDistro.Alpine, ['3.7.0']); - @injectable() export class LinuxDotNetCompatibilityService implements IOSDotNetCompatibilityService { constructor(@inject(IPlatformService) private readonly platformService: IPlatformService) { } @traceDecorators.verbose('Checking support of .NET') public async isSupported() { - const distro = await this.platformService.getOSDistro(); - if (!versionsPerDistro.has(distro)) { - traceError(`.NET is not supported on Linux Distro '${distro}'`); - return false; - } - - const minimumVersions = versionsPerDistro.get(distro)!; - const version = await this.platformService.getVersion(); - return this.checkIfVersionsAreSupported(version, minimumVersions); - } - - @traceDecorators.verbose('Checking support of Linux Distro Version') - private async checkIfVersionsAreSupported(version: SemVer, minimumSupportedVersions: string[]): Promise { - if (!Array.isArray(minimumSupportedVersions) || minimumSupportedVersions.length === 0) { + if (!this.platformService.is64bit) { + traceError('.NET is not supported on 32 Bit Linux'); return false; } - if (minimumSupportedVersions.length === 1) { - // If we have only one version, then check if OS version is greater or same. - return version.compare(minimumSupportedVersions[0]) >= 0; - } - - // If we have more than one version, then - // Check if OS version is greater than the max of the versions provided, if yes, the allow it. - // E.g. if versions 18.0, 16.0, 14.0 are supported by .NET core - // Then we assume 19, 20 are supported as well. - const sorted = minimumSupportedVersions.slice().map(ver => parseVersion(ver)!); - sorted.sort((a, b) => a.compare(b)); - if (version.compare(sorted[sorted.length - 1]) >= 0) { - return true; - } - - // Else look for exact major versions and compare against the minor. - // E.g. if versions 18.0, 16.0, 14.0 are supported by .NET core - // Then we assume 16.1, 14.1, 14.2 are supported. - const matchingMajorVersions = sorted.filter(item => item.major === version.major); - if (matchingMajorVersions.length > 0 && version.minor >= matchingMajorVersions[0].minor) { - return true; - } - - // Rest are not supported. - // E.g. if versions 18.0, 16.0, 14.0 are supported by .NET core - // 17, 15 are not supported. - // Similarly, 13, 12,10 are not supported. - return false; + return true; } } diff --git a/src/client/common/dotnet/services/windowsCompatibilityService.ts b/src/client/common/dotnet/services/windowsCompatibilityService.ts index b199f04c1b71..6e616909de3c 100644 --- a/src/client/common/dotnet/services/windowsCompatibilityService.ts +++ b/src/client/common/dotnet/services/windowsCompatibilityService.ts @@ -3,19 +3,12 @@ 'use strict'; -import { inject, injectable } from 'inversify'; -import { IPlatformService } from '../../platform/types'; +import { injectable } from 'inversify'; import { IOSDotNetCompatibilityService } from '../types'; -// Min version on https://github.com/dotnet/core/blob/master/release-notes/2.1/2.1-supported-os.md is 10.12. -// Lets just assume that anything after Win 7SP1 are supported. -const minVersion = '6.1.7601'; - @injectable() export class WindowsDotNetCompatibilityService implements IOSDotNetCompatibilityService { - constructor(@inject(IPlatformService) private readonly platformService: IPlatformService) { } public async isSupported() { - const version = await this.platformService.getVersion(); - return version.compare(minVersion) >= 0; + return true; } } diff --git a/src/client/common/platform/platformService.ts b/src/client/common/platform/platformService.ts index f82f702e7d9a..42a42bab8468 100644 --- a/src/client/common/platform/platformService.ts +++ b/src/client/common/platform/platformService.ts @@ -7,8 +7,8 @@ import * as os from 'os'; import { coerce, SemVer } from 'semver'; import { sendTelemetryEvent } from '../../telemetry'; import { PLATFORM_INFO, PlatformErrors } from '../../telemetry/constants'; -import { traceDecorators, traceError, traceVerbose } from '../logger'; -import { OSDistro, OSType } from '../utils/platform'; +import { traceDecorators, traceError } from '../logger'; +import { OSType } from '../utils/platform'; import { parseVersion } from '../utils/version'; import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants'; import { IPlatformService } from './types'; @@ -16,7 +16,6 @@ import { IPlatformService } from './types'; @injectable() export class PlatformService implements IPlatformService { public readonly osType: OSType = getOSType(); - public distro?: OSDistro; public version?: SemVer; public get pathVariableName() { return this.isWindows ? WINDOWS_PATH_VARIABLE_NAME : NON_WINDOWS_PATH_VARIABLE_NAME; @@ -24,22 +23,6 @@ export class PlatformService implements IPlatformService { public get virtualEnvBinName() { return this.isWindows ? 'Scripts' : 'bin'; } - @traceDecorators.verbose('Get OS Distro') - public async getOSDistro(): Promise { - if (this.distro) { - return this.distro; - } - switch (this.osType) { - case OSType.Windows: - case OSType.OSX: - return this.distro = OSDistro.Unknown; - default: - const result = await getLinuxDistro(); - this.distro = result[0]; - this.version = result[1]; - return this.distro; - } - } @traceDecorators.verbose('Get Platform Version') public async getVersion(): Promise { if (this.version) { @@ -64,11 +47,7 @@ export class PlatformService implements IPlatformService { return parseVersion(os.release()); } default: - const result = await getLinuxDistro(); - sendTelemetryEvent(PLATFORM_INFO, undefined, { distro: result[0], osVersion: `${result[1].major}.${result[1].minor}.${result[1].patch}` }); - this.distro = result[0]; - this.version = result[1]; - return this.version; + throw new Error('Not Supported'); } } @@ -100,64 +79,3 @@ function getOSType(platform: string = process.platform): OSType { return OSType.Unknown; } } - -async function getLinuxDistro(): Promise<[OSDistro, SemVer]> { - let distro: OSDistro = OSDistro.Unknown; - let version = new SemVer('0.0.0'); - return new Promise<[OSDistro, SemVer]>((resolve, reject) => { - // tslint:disable-next-line:no-require-imports - const getos = require('getos') as typeof import('getos'); - // tslint:disable-next-line:no-any - getos((exc: Error, info: { dist?: string; release?: string }) => { - if (exc) { - traceError('getos failed', exc); - sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToGetLinuxInfo }); - return reject(exc); - } - traceVerbose(`getos result ${info ? JSON.stringify(info) : ''}`); - try { - distro = getLinuxDistroFromName(info.dist!); - } catch (ex) { - traceError('getLinuxDistroFromName failed in getLinuxDistro', exc); - sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineDistro }); - return reject(ex); - } - try { - version = parseVersion(info.release!); - resolve([distro, version]); - } catch (ex) { - traceError('parseVersion failed in getLinuxDistro', exc); - sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineVersion }); - return reject(ex); - } - }); - }); -} - -function getLinuxDistroFromName(name: string): OSDistro { - name = name.toLowerCase(); - // See https://github.com/zyga/os-release-zoo. - if (/ubuntu/.test(name)) { - return OSDistro.Ubuntu; - } else if (/debian/.test(name)) { - return OSDistro.Debian; - } else if (/rhel/.test(name) || /red hat/.test(name)) { - return OSDistro.RHEL; - } else if (/fedora/.test(name)) { - return OSDistro.Fedora; - } else if (/alpine/.test(name)) { - return OSDistro.Alpine; - } else if (/mint/.test(name)) { - return OSDistro.Mint; - } else if (/centos/.test(name)) { - return OSDistro.CentOS; - } else if (/suse/.test(name)) { - return OSDistro.Suse; - } else if (/gentoo/.test(name)) { - return OSDistro.Suse; - } else if (/arch/.test(name)) { - return OSDistro.Arch; - } else { - return OSDistro.Unknown; - } -} diff --git a/src/client/common/platform/types.ts b/src/client/common/platform/types.ts index 9a8577b55bf3..1214a77e9fa7 100644 --- a/src/client/common/platform/types.ts +++ b/src/client/common/platform/types.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as fsextra from 'fs-extra'; import { SemVer } from 'semver'; import { Disposable } from 'vscode'; -import { Architecture, OSDistro, OSType } from '../utils/platform'; +import { Architecture, OSType } from '../utils/platform'; export enum RegistryHive { HKCU, HKLM @@ -28,7 +28,6 @@ export interface IPlatformService { readonly isMac: boolean; readonly isLinux: boolean; readonly is64bit: boolean; - getOSDistro(): Promise; getVersion(): Promise; } diff --git a/src/client/common/utils/platform.ts b/src/client/common/utils/platform.ts index 6363c9cbb4c8..e293819b364f 100644 --- a/src/client/common/utils/platform.ts +++ b/src/client/common/utils/platform.ts @@ -14,18 +14,3 @@ export enum OSType { OSX = 'OSX', Linux = 'Linux' } -export enum OSDistro { - Unknown = 'Unknown', - // linux: - Ubuntu = 'Ubuntu', - Debian = 'Debian', - RHEL = 'RHEL', - Fedora = 'Fedora', - Alpine = 'Alpine', - CentOS = 'CentOS', - Oracle = 'Oracle', - Suse = 'Suse', - Gentoo = 'Gentoo', - Arch = 'Arch', - Mint = 'Mint' -} diff --git a/src/client/telemetry/types.ts b/src/client/telemetry/types.ts index d76bea76c3b1..2ca12126e513 100644 --- a/src/client/telemetry/types.ts +++ b/src/client/telemetry/types.ts @@ -3,7 +3,6 @@ 'use strict'; import { TerminalShellType } from '../common/terminal/types'; -import { OSDistro } from '../common/utils/platform'; import { InterpreterType } from '../interpreter/contracts'; import { LinterId } from '../linters/types'; import { PlatformErrors } from './constants'; @@ -127,7 +126,6 @@ export type ImportNotebook = { }; export type Platform = { - distro?: OSDistro; failureType?: PlatformErrors; osVersion?: string; }; diff --git a/src/test/common/dotnet/services/linuxCompatibilityService.unit.test.ts b/src/test/common/dotnet/services/linuxCompatibilityService.unit.test.ts index c9609b8eea8f..4e945d865edf 100644 --- a/src/test/common/dotnet/services/linuxCompatibilityService.unit.test.ts +++ b/src/test/common/dotnet/services/linuxCompatibilityService.unit.test.ts @@ -7,85 +7,23 @@ import { expect } from 'chai'; import { instance, mock, when } from 'ts-mockito'; import { LinuxDotNetCompatibilityService } from '../../../../client/common/dotnet/services/linuxCompatibilityService'; import { PlatformService } from '../../../../client/common/platform/platformService'; -import { getNamesAndValues } from '../../../../client/common/utils/enum'; -import { OSDistro } from '../../../../client/common/utils/platform'; -import { parseVersion } from '../../../../client/common/utils/version'; suite('DOT.NET', () => { suite('Linux', () => { - async function testSupport(distro: OSDistro, expectedValueForIsSupported: boolean, version?: string) { + async function testSupport(expectedValueForIsSupported: boolean, is64Bit: boolean) { const platformService = mock(PlatformService); const service = new LinuxDotNetCompatibilityService(instance(platformService)); - if (version) { - when(platformService.getVersion()).thenResolve(parseVersion(version)); - } - when(platformService.getOSDistro()).thenResolve(distro); + when(platformService.is64bit).thenReturn(is64Bit); const result = await service.isSupported(); expect(result).to.be.equal(expectedValueForIsSupported, 'Invalid value'); } - type TestMatrixItem = { distro: OSDistro; version: string; supported: boolean }; - function createMatrixItem(distro: OSDistro, version: string, supported: boolean): TestMatrixItem { - return { distro, version, supported }; - } - const testMatrix: TestMatrixItem[] = [ - createMatrixItem(OSDistro.RHEL, '6.0.0', true), - createMatrixItem(OSDistro.RHEL, '7.0.0', true), - createMatrixItem(OSDistro.RHEL, '5.0.0', false), - createMatrixItem(OSDistro.RHEL, '4.0.0', false), - - createMatrixItem(OSDistro.CentOS, '7.0.0', true), - createMatrixItem(OSDistro.CentOS, '8.0.0', true), - createMatrixItem(OSDistro.CentOS, '6.0.0', false), - - createMatrixItem(OSDistro.Oracle, '8.0.0', true), - createMatrixItem(OSDistro.Oracle, '7.0.0', true), - createMatrixItem(OSDistro.Oracle, '6.0.0', false), - - createMatrixItem(OSDistro.Fedora, '27.0.0', true), - createMatrixItem(OSDistro.Fedora, '28.0.0', true), - createMatrixItem(OSDistro.Fedora, '26.0.0', false), - - createMatrixItem(OSDistro.Debian, '9.0.0', true), - createMatrixItem(OSDistro.Debian, '8.7.0', true), - createMatrixItem(OSDistro.Debian, '8.6.0', false), - - createMatrixItem(OSDistro.Ubuntu, '18.04.0', true), - createMatrixItem(OSDistro.Ubuntu, '17.04.0', false), - createMatrixItem(OSDistro.Ubuntu, '16.04.0', true), - createMatrixItem(OSDistro.Ubuntu, '15.04.0', false), - createMatrixItem(OSDistro.Ubuntu, '14.04.0', true), - createMatrixItem(OSDistro.Ubuntu, '13.04.0', false), - - createMatrixItem(OSDistro.Mint, '18.0.0', true), - createMatrixItem(OSDistro.Mint, '17.7.0', true), - createMatrixItem(OSDistro.Mint, '19.0.0', true), - createMatrixItem(OSDistro.Mint, '16.0.0', false), - - createMatrixItem(OSDistro.Suse, '42.3.0', true), - createMatrixItem(OSDistro.Suse, '42.0.0', false), - createMatrixItem(OSDistro.Suse, '13.0.0', false), - createMatrixItem(OSDistro.Suse, '12.0.0', true), - createMatrixItem(OSDistro.Suse, '11.0.0', false), - - createMatrixItem(OSDistro.Alpine, '3.7.0', true), - createMatrixItem(OSDistro.Alpine, '4.0.0', true), - createMatrixItem(OSDistro.Alpine, '3.6.0', false) - ]; - - const supportedDistros = new Set(); - testMatrix.forEach(testInput => { - testMatrix.forEach(item => supportedDistros.add(item.distro)); - test(`Distro '${testInput.distro}' with version=${testInput.version} has support=${testInput.supported}`, async () => { - await testSupport(testInput.distro, testInput.supported, testInput.version); - }); + test('Linux 64 bit is supported', async () => { + await testSupport(true, true); }); - - getNamesAndValues(OSDistro).filter(item => !supportedDistros.has(item.value)).forEach(testInput => { - test(`Distro '${testInput.name}' has no support`, async () => { - await testSupport(testInput.value, false); - }); + test('Linux 64 bit is not supported', async () => { + await testSupport(false, false); }); }); }); diff --git a/src/test/common/dotnet/services/winCompatibilityService.unit.test.ts b/src/test/common/dotnet/services/winCompatibilityService.unit.test.ts index 6635c6b4f1d3..9f3132eb830e 100644 --- a/src/test/common/dotnet/services/winCompatibilityService.unit.test.ts +++ b/src/test/common/dotnet/services/winCompatibilityService.unit.test.ts @@ -4,35 +4,14 @@ 'use strict'; import { expect } from 'chai'; -import { SemVer } from 'semver'; -import { instance, mock, when } from 'ts-mockito'; import { WindowsDotNetCompatibilityService } from '../../../../client/common/dotnet/services/windowsCompatibilityService'; -import { PlatformService } from '../../../../client/common/platform/platformService'; suite('DOT.NET', () => { suite('Windows', () => { - async function testSupport(version: string, expectedValueForIsSupported: boolean) { - const platformService = mock(PlatformService); - const service = new WindowsDotNetCompatibilityService(instance(platformService)); - - when(platformService.getVersion()).thenResolve(new SemVer(version)); - - const result = await service.isSupported(); - expect(result).to.be.equal(expectedValueForIsSupported, 'Invalid value'); - } - test('Supported on 6.1.7601', () => testSupport('6.1.7601', true)); - test('Supported on 6.1.7602', () => testSupport('6.1.7602', true)); - test('Supported on 6.2.7602', () => testSupport('6.2.7601', true)); - test('Supported on 7.0.0', () => testSupport('7.0.0', true)); - test('Supported on 8.0.0', () => testSupport('8.0.0', true)); - test('Supported on 8.0.1', () => testSupport('8.0.1', true)); - test('Supported on 10.0.0', () => testSupport('10.0.0', true)); - test('Supported on 10.1.0', () => testSupport('10.1.0', true)); - - test('Supported on 6.1.7600', () => testSupport('6.1.7600', false)); - test('Supported on 6.0.7601', () => testSupport('6.0.7601', false)); - test('Supported on 5.0.0', () => testSupport('5.0.0', false)); - test('Supported on 4.0.0', () => testSupport('4.0.0', false)); - test('Supported on 4.0.1', () => testSupport('4.0.1', false)); + test('Windows is Supported', () => { + const service = new WindowsDotNetCompatibilityService(); + const result = service.isSupported(); + expect(result).to.be.equal(true, 'Invalid value'); + }); }); }); diff --git a/src/test/common/platform/platformService.unit.test.ts b/src/test/common/platform/platformService.test.ts similarity index 54% rename from src/test/common/platform/platformService.unit.test.ts rename to src/test/common/platform/platformService.test.ts index 60e545d6b70b..8336199ec8a2 100644 --- a/src/test/common/platform/platformService.unit.test.ts +++ b/src/test/common/platform/platformService.test.ts @@ -5,10 +5,9 @@ import { expect } from 'chai'; import * as os from 'os'; -import { parse, SemVer } from 'semver'; +import { parse } from 'semver'; import { PlatformService } from '../../../client/common/platform/platformService'; -import { OSDistro, OSType } from '../../../client/common/utils/platform'; -import { parseVersion } from '../../../client/common/utils/version'; +import { OSType } from '../../../client/common/utils/platform'; // tslint:disable-next-line:max-func-body-length suite('PlatformService', () => { @@ -75,25 +74,14 @@ suite('PlatformService', () => { expect(result.compare(expectedVersion)).to.be.equal(0, 'invalid value'); }); - test('getVersion on Linux', async function () { + test('getVersion on Linux shoud throw an exception', async function () { if (osType !== OSType.Linux) { // tslint:disable-next-line:no-invalid-this return this.skip(); } - const info = await getLinuxDistro(); - const expectedVersion = info[1]; const svc = new PlatformService(); - const result = await svc.getVersion(); - - expect(result.compare(expectedVersion)).to.be.equal(0, 'invalid value'); - }); - test('getDistro', async () => { - const info = osType === OSType.Linux ? await getLinuxDistro() : [OSDistro.Unknown, undefined]; - const expectedDistro = info[0]; - const svc = new PlatformService(); - const result = await svc.getOSDistro(); - expect(result).to.be.equal(expectedDistro, 'invalid value'); + await expect(svc.getVersion()).to.eventually.be.rejectedWith('Not Supported'); }); }); @@ -108,49 +96,3 @@ function getOSType(platform: string = process.platform): OSType { return OSType.Unknown; } } - -async function getLinuxDistro(): Promise<[OSDistro, SemVer]> { - let distro: OSDistro = OSDistro.Unknown; - let version = new SemVer('0.0.0'); - return new Promise<[OSDistro, SemVer]>((resolve, reject) => { - // tslint:disable-next-line:no-require-imports - const getos = require('getos') as typeof import('getos'); - // tslint:disable-next-line:no-any - getos((exc: Error, info: any) => { - if (exc) { - return reject(exc); - } - distro = getLinuxDistroFromName(info.dist); - version = parseVersion(info.release); - resolve([distro, version]); - }); - }); -} - -function getLinuxDistroFromName(name: string): OSDistro { - name = name.toLowerCase(); - // See https://github.com/zyga/os-release-zoo. - if (/ubuntu/.test(name)) { - return OSDistro.Ubuntu; - } else if (/debian/.test(name)) { - return OSDistro.Debian; - } else if (/rhel/.test(name) || /red hat/.test(name)) { - return OSDistro.RHEL; - } else if (/fedora/.test(name)) { - return OSDistro.Fedora; - } else if (/alpine/.test(name)) { - return OSDistro.Alpine; - } else if (/mint/.test(name)) { - return OSDistro.Mint; - } else if (/centos/.test(name)) { - return OSDistro.CentOS; - } else if (/suse/.test(name)) { - return OSDistro.Suse; - } else if (/gentoo/.test(name)) { - return OSDistro.Suse; - } else if (/arch/.test(name)) { - return OSDistro.Arch; - } else { - return OSDistro.Unknown; - } -} From f128fe8d5296e85014167f1c3f1890e13094cac7 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 14 Dec 2018 10:22:57 -0800 Subject: [PATCH 5/5] Remove redundant items --- src/client/telemetry/constants.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/client/telemetry/constants.ts b/src/client/telemetry/constants.ts index c119c99fdfcd..9d512a989c2c 100644 --- a/src/client/telemetry/constants.ts +++ b/src/client/telemetry/constants.ts @@ -51,8 +51,5 @@ export const PLATFORM_INFO = 'PLATFORM.INFO'; export enum PlatformErrors { FailedToParseVersion = 'FailedToParseVersion', - FailedToGetLinuxInfo = 'FailedToGetLinuxInfo', - FailedToDetermineOS = 'FailedToDetermineOS', - FailedToDetermineDistro = 'FailedToDetermineDistro', - FailedToDetermineVersion = 'FailedToDetermineVersion' + FailedToDetermineOS = 'FailedToDetermineOS' }