@@ -492,22 +492,9 @@ export async function listCompilers(): Promise<DetectedCompiler[]> {
492492}
493493
494494export async function listCompilersImpl ( ) : Promise < DetectedCompiler [ ] > {
495- const compilers = [ "dmd" , "ldc2" , "ldc" , "gdc" , "gcc" ] ;
496495 let ret : DetectedCompiler [ ] = [ ] ;
497496 let fallbackPath : string | undefined = undefined ;
498-
499- // test compilers in $PATH
500- for ( let i = 0 ; i < compilers . length ; i ++ ) {
501- const check = compilers [ i ] ;
502- let result = await checkCompiler ( < any > check ) ;
503- fallbackPath = fallbackPath || result . path ;
504- if ( result && result . has ) {
505- result . has = check == "ldc2" ? "ldc" : < any > check ;
506- ret . push ( result ) ;
507- if ( check == "ldc2" || check == "gdc" )
508- i ++ ; // skip ldc / gcc
509- }
510- }
497+ let defaultDir : string | undefined ;
511498
512499 async function testInstallShPath ( dir : string , type : "dmd" | "ldc" | "gdc" ) {
513500 let activateFile = process . platform == "win32" ? "activate.bat" : "activate" ;
@@ -552,8 +539,40 @@ export async function listCompilersImpl(): Promise<DetectedCompiler[]> {
552539 }
553540 }
554541
542+ // test code-d install.sh based D compilers
543+ await new Promise ( ( resolve ) => {
544+ fs . readdir ( defaultDir = getLocalCompilersDir ( ) , async ( err , files ) => {
545+ try {
546+ if ( err )
547+ return ;
548+ for ( let i = 0 ; i < files . length ; i ++ ) {
549+ const file = files [ i ] ;
550+ const type = getCompilerTypeFromPrefix ( file ) ;
551+ if ( type )
552+ await testInstallShPath ( path . join ( defaultDir ! , file ) , type ) ;
553+ }
554+ } finally {
555+ resolve ( undefined ) ;
556+ }
557+ } ) ;
558+ } ) ;
559+
560+ // test compilers in $PATH
561+ const compilers = [ "dmd" , "ldc2" , "ldc" , "gdc" , "gcc" ] ;
562+ for ( let i = 0 ; i < compilers . length ; i ++ ) {
563+ const check = compilers [ i ] ;
564+ let result = await checkCompiler ( < any > check ) ;
565+ fallbackPath = fallbackPath || result . path ;
566+ if ( result && result . has ) {
567+ result . has = check == "ldc2" ? "ldc" : < any > check ;
568+ ret . push ( result ) ;
569+ if ( check == "ldc2" || check == "gdc" )
570+ i ++ ; // skip ldc / gcc
571+ }
572+ }
573+
555574 // test global install.sh based D compilers
556- let defaultDir = getDefaultInstallShDir ( ) ;
575+ defaultDir = getDefaultInstallShDir ( ) ;
557576 if ( defaultDir ) {
558577 await new Promise ( ( resolve ) => {
559578 fs . readdir ( defaultDir ! , async ( err , files ) => {
@@ -573,24 +592,6 @@ export async function listCompilersImpl(): Promise<DetectedCompiler[]> {
573592 } ) ;
574593 }
575594
576- // test code-d install.sh based D compilers
577- await new Promise ( ( resolve ) => {
578- fs . readdir ( defaultDir = getLocalCompilersDir ( ) , async ( err , files ) => {
579- try {
580- if ( err )
581- return ;
582- for ( let i = 0 ; i < files . length ; i ++ ) {
583- const file = files [ i ] ;
584- const type = getCompilerTypeFromPrefix ( file ) ;
585- if ( type )
586- await testInstallShPath ( path . join ( defaultDir ! , file ) , type ) ;
587- }
588- } finally {
589- resolve ( undefined ) ;
590- }
591- } ) ;
592- } ) ;
593-
594595 if ( ret . length == 0 && fallbackPath )
595596 ret . push ( { has : false , path : fallbackPath } ) ;
596597 return ret ;
0 commit comments