@@ -16,7 +16,7 @@ import * as nls from 'vscode-nls';
1616import { CppToolsApi , CppToolsExtension } from 'vscode-cpptools' ;
1717import { getTemporaryCommandRegistrarInstance , initializeTemporaryCommandRegistrar } from './commands' ;
1818import { PlatformInformation } from './platform' ;
19- import { PackageManager , PackageManagerError , IPackage } from './packageManager' ;
19+ import { PackageManager , PackageManagerError , IPackage , VersionsMatch , ArchitecturesMatch , PlatformsMatch } from './packageManager' ;
2020import { getInstallationInformation , InstallationInformation , setInstallationStage , setInstallationType , InstallationType } from './installationInformation' ;
2121import { Logger , getOutputChannelLogger , showOutputChannel } from './logger' ;
2222import { 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+
171180function 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+
184212function removeUnnecessaryFile ( ) : Promise < void > {
185213 if ( os . platform ( ) !== 'win32' ) {
186214 let sourcePath : string = util . getDebugAdaptersPath ( "bin/OpenDebugAD7.exe.config" ) ;
0 commit comments