Skip to content

Commit 9b2c568

Browse files
authored
Add cleanUnusedBinaries stage (#5153)
Our offline installer will include two versions of lldb. ./debugAdapters/lldb is lldb-mi 3.8 and is used for High-Sierra and older ./debugAdapters/lldb-mi is lldb-mi 10.x and is used for Mojave and higher.
1 parent 5986aee commit 9b2c568

File tree

2 files changed

+64
-36
lines changed

2 files changed

+64
-36
lines changed

Extension/src/main.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as nls from 'vscode-nls';
1616
import { CppToolsApi, CppToolsExtension } from 'vscode-cpptools';
1717
import { getTemporaryCommandRegistrarInstance, initializeTemporaryCommandRegistrar } from './commands';
1818
import { PlatformInformation } from './platform';
19-
import { PackageManager, PackageManagerError, IPackage } from './packageManager';
19+
import { PackageManager, PackageManagerError, IPackage, VersionsMatch, ArchitecturesMatch, PlatformsMatch } from './packageManager';
2020
import { getInstallationInformation, InstallationInformation, setInstallationStage, setInstallationType, InstallationType } from './installationInformation';
2121
import { Logger, getOutputChannelLogger, showOutputChannel } from './logger';
2222
import { CppTools1, NullCppTools } from './cppTools1';
@@ -103,6 +103,9 @@ async function offlineInstallation(): Promise<void> {
103103
setInstallationType(InstallationType.Offline);
104104
const info: PlatformInformation = await PlatformInformation.GetPlatformInformation();
105105

106+
setInstallationStage('cleanUpUnusedBinaries');
107+
await cleanUpUnusedBinaries(info);
108+
106109
setInstallationStage('makeBinariesExecutable');
107110
await makeBinariesExecutable();
108111

@@ -168,19 +171,44 @@ function makeBinariesExecutable(): Promise<void> {
168171
return util.allowExecution(util.getDebugAdaptersPath("OpenDebugAD7"));
169172
}
170173

174+
function packageMatchesPlatform(pkg: IPackage, info: PlatformInformation): boolean {
175+
return PlatformsMatch(pkg, info) &&
176+
(pkg.architectures === undefined || ArchitecturesMatch(pkg, info)) &&
177+
VersionsMatch(pkg, info);
178+
}
179+
171180
function makeOfflineBinariesExecutable(info: PlatformInformation): Promise<void> {
172181
let promises: Thenable<void>[] = [];
173182
let packages: IPackage[] = util.packageJson["runtimeDependencies"];
174183
packages.forEach(p => {
175184
if (p.binaries && p.binaries.length > 0 &&
176-
p.platforms.findIndex(plat => plat === info.platform) !== -1 &&
177-
(p.architectures === undefined || p.architectures.findIndex(arch => arch === info.architecture) !== - 1)) {
185+
packageMatchesPlatform(p, info)) {
178186
p.binaries.forEach(binary => promises.push(util.allowExecution(util.getExtensionFilePath(binary))));
179187
}
180188
});
181189
return Promise.all(promises).then(() => { });
182190
}
183191

192+
function cleanUpUnusedBinaries(info: PlatformInformation): Promise<void> {
193+
let promises: Thenable<void>[] = [];
194+
let packages: IPackage[] = util.packageJson["runtimeDependencies"];
195+
const logger: Logger = getOutputChannelLogger();
196+
197+
packages.forEach(p => {
198+
if (p.binaries && p.binaries.length > 0 &&
199+
!packageMatchesPlatform(p, info)) {
200+
p.binaries.forEach(binary => {
201+
const path: string = util.getExtensionFilePath(binary);
202+
if (fs.existsSync(path)) {
203+
logger.appendLine(`deleting: ${path}`);
204+
promises.push(util.deleteFile(path));
205+
}
206+
});
207+
}
208+
});
209+
return Promise.all(promises).then(() => { });
210+
}
211+
184212
function removeUnnecessaryFile(): Promise<void> {
185213
if (os.platform() !== 'win32') {
186214
let sourcePath: string = util.getDebugAdaptersPath("bin/OpenDebugAD7.exe.config");

Extension/src/packageManager.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -153,43 +153,13 @@ export class PackageManager {
153153
return this.GetPackageList()
154154
.then((list) =>
155155
list.filter((value, index, array) =>
156-
this.ArchitecturesMatch(value) &&
157-
this.PlatformsMatch(value) &&
158-
this.VersionsMatch(value)
156+
ArchitecturesMatch(value, this.platformInfo) &&
157+
PlatformsMatch(value, this.platformInfo) &&
158+
VersionsMatch(value, this.platformInfo)
159159
)
160160
);
161161
}
162162

163-
private ArchitecturesMatch(value: IPackage): boolean {
164-
return !value.architectures || (this.platformInfo.architecture !== undefined && value.architectures.indexOf(this.platformInfo.architecture) !== -1);
165-
}
166-
167-
private PlatformsMatch(value: IPackage): boolean {
168-
return !value.platforms || value.platforms.indexOf(this.platformInfo.platform) !== -1;
169-
}
170-
171-
private VersionsMatch(value: IPackage): boolean {
172-
if (value.versionRegex) {
173-
// If we have a versionRegex but did not get a platformVersion
174-
if (!this.platformInfo.version) {
175-
// If we are expecting to match the versionRegex, return false since there was no version found.
176-
//
177-
// If we are expecting to not match the versionRegex, return true since we are expecting to
178-
// not match the version string, the only match would be if versionRegex was not set.
179-
return !value.matchVersion;
180-
}
181-
const regex: RegExp = new RegExp(value.versionRegex);
182-
183-
return (value.matchVersion ?
184-
regex.test(this.platformInfo.version) :
185-
!regex.test(this.platformInfo.version)
186-
);
187-
}
188-
189-
// No versionRegex provided.
190-
return true;
191-
}
192-
193163
private async DownloadPackage(pkg: IPackage, progressCount: string, progress: vscode.Progress<{message?: string; increment?: number}>): Promise<void> {
194164
this.AppendChannel(localize("downloading.package", "Downloading package '{0}' ", pkg.description));
195165

@@ -467,3 +437,33 @@ export class PackageManager {
467437
}
468438
}
469439
}
440+
441+
export function VersionsMatch(pkg: IPackage, info: PlatformInformation): boolean {
442+
if (pkg.versionRegex) {
443+
// If we have a versionRegex but did not get a platformVersion
444+
if (!info.version) {
445+
// If we are expecting to match the versionRegex, return false since there was no version found.
446+
//
447+
// If we are expecting to not match the versionRegex, return true since we are expecting to
448+
// not match the version string, the only match would be if versionRegex was not set.
449+
return !pkg.matchVersion;
450+
}
451+
const regex: RegExp = new RegExp(pkg.versionRegex);
452+
453+
return (pkg.matchVersion ?
454+
regex.test(info.version) :
455+
!regex.test(info.version)
456+
);
457+
}
458+
459+
// No versionRegex provided.
460+
return true;
461+
}
462+
463+
export function ArchitecturesMatch(value: IPackage, info: PlatformInformation): boolean {
464+
return !value.architectures || (info.architecture !== undefined && value.architectures.indexOf(info.architecture) !== -1);
465+
}
466+
467+
export function PlatformsMatch(value: IPackage, info: PlatformInformation): boolean {
468+
return !value.platforms || value.platforms.indexOf(info.platform) !== -1;
469+
}

0 commit comments

Comments
 (0)