@@ -146,7 +146,7 @@ export class SettingManager {
146146 this . getConfiguration ( ) . update ( key , val , vscode . ConfigurationTarget . Global ) ;
147147 }
148148
149- private toFullPathForSettings ( path_ : string ) : string {
149+ private _formatPathForPluginSettings ( path_ : string ) : string {
150150
151151 const wsRoot = WorkspaceManager . getInstance ( ) . getWorkspaceRoot ( ) ;
152152
@@ -189,59 +189,61 @@ export class SettingManager {
189189
190190 //------------------------- env and path --------------------------
191191
192- private getExePathFromConfig ( confName : string , execName : string ) : string | undefined {
193-
194- let defPath : string | undefined ;
195-
196- const path = this . getConfiguration ( ) . get < string > ( confName ) ;
192+ private getFullPathByPluginConfig ( configName : string ) : string | undefined {
193+ const path = this . getConfiguration ( ) . get < string > ( configName ) ;
197194 if ( path ) {
198- defPath = Utility . formatPath ( this . toFullPathForSettings ( path ) ) ;
199- if ( File . IsExist ( defPath ) ) {
200- return defPath ;
195+ const p = Utility . formatPath ( this . _formatPathForPluginSettings ( path ) ) ;
196+ if ( File . IsExist ( p ) ) {
197+ return p ;
201198 }
202199 }
200+ }
203201
204- if ( this . envPathCache . has ( execName ) ) {
205- return < string > this . envPathCache . get ( execName ) ;
202+ private findExePathInSystemEnv ( exeName : string ) : string | undefined {
203+
204+ if ( this . envPathCache . has ( exeName ) ) {
205+ return < string > this . envPathCache . get ( exeName ) ;
206206 }
207207
208208 else {
209- const absPath = find ( execName ) ;
209+ const absPath = find ( exeName ) ;
210210 if ( absPath ) {
211- this . envPathCache . set ( execName , absPath ) ;
211+ this . envPathCache . set ( exeName , absPath ) ;
212212 return absPath ;
213213 }
214214 }
215-
216- return defPath ;
217215 }
218216
219- private getGccFolderFromConfig ( confName : string , execName : string ) : string | undefined {
217+ private findExeDirInSystemEnv ( exeName : string ) : string | undefined {
220218
221- let defPath : string | undefined ;
219+ if ( this . envPathCache . has ( exeName ) ) {
220+ return < string > this . envPathCache . get ( exeName ) ;
221+ }
222222
223- const path = this . getConfiguration ( ) . get < string > ( confName ) ;
224- if ( path ) {
225- defPath = Utility . formatPath ( this . toFullPathForSettings ( path ) ) ;
226- if ( File . IsExist ( defPath ) ) {
227- return defPath ;
223+ else {
224+ const absPath = find ( exeName ) ;
225+ if ( absPath ) {
226+ const dirpath = NodePath . dirname ( absPath ) ;
227+ this . envPathCache . set ( exeName , dirpath ) ;
228+ return dirpath ;
228229 }
229230 }
231+ }
230232
231- if ( this . envPathCache . has ( execName ) ) {
232- return < string > this . envPathCache . get ( execName ) ;
233+ private findGccCompilerRootInSystemEnv ( gccName : string ) : string | undefined {
234+
235+ if ( this . envPathCache . has ( gccName ) ) {
236+ return < string > this . envPathCache . get ( gccName ) ;
233237 }
234238
235239 else {
236- const absPath = find ( execName ) ;
240+ const absPath = find ( gccName ) ;
237241 if ( absPath ) {
238242 const dirName = NodePath . dirname ( NodePath . dirname ( absPath ) ) ;
239- this . envPathCache . set ( execName , dirName ) ;
243+ this . envPathCache . set ( gccName , dirName ) ;
240244 return dirName ;
241245 }
242246 }
243-
244- return defPath ;
245247 }
246248
247249 //-------------------------- Serialport --------------------------------
@@ -350,74 +352,44 @@ export class SettingManager {
350352 }
351353
352354 getCppcheckerExe ( ) : string | undefined {
353- return this . getExePathFromConfig ( 'Cppcheck.ExecutablePath' , 'cppcheck' ) ;
355+ return this . getFullPathByPluginConfig ( 'Cppcheck.ExecutablePath' )
356+ || this . findExePathInSystemEnv ( 'cppcheck' ) ;
354357 }
355358
356359 //----------------------------- Flasher --------------------------------
357360
358361 getJlinkDir ( ) : string {
359-
360- let defPath : string | undefined ;
361-
362- const path = this . getConfiguration ( ) . get < string > ( 'JLink.InstallDirectory' ) ;
363- if ( path ) {
364- defPath = Utility . formatPath ( this . toFullPathForSettings ( path ) ) ;
365- if ( File . IsExist ( defPath ) ) {
366- return defPath ;
367- }
368- }
369-
370- const execName = 'JLink' ;
371-
372- if ( this . envPathCache . has ( execName ) ) {
373- return < string > this . envPathCache . get ( execName )
374- }
375-
376- else {
377- const absPath = find ( execName ) ;
378- if ( absPath ) {
379- const dirName = NodePath . dirname ( absPath ) ;
380- this . envPathCache . set ( execName , dirName ) ;
381- return dirName ;
382- }
383- }
384-
385- return defPath || 'null' ;
362+ return this . getFullPathByPluginConfig ( 'JLink.InstallDirectory' )
363+ || this . findExeDirInSystemEnv ( 'JLink' )
364+ || 'null' ;
386365 }
387366
388367 getStvpExePath ( ) : string {
389- return this . toFullPathForSettings (
390- this . getExePathFromConfig ( 'STM8.STVP.CliExePath' , ' STVP_CmdLine') || 'null'
391- ) ;
368+ return this . getFullPathByPluginConfig ( 'STM8.STVP.CliExePath' )
369+ || this . findExePathInSystemEnv ( ' STVP_CmdLine')
370+ || 'null' ;
392371 }
393372
394373 getSTLinkExePath ( ) : string {
395-
396- const flasher =
397- this . getExePathFromConfig ( 'STLink.ExePath' , 'STM32_Programmer_CLI' ) ||
398- this . getExePathFromConfig ( 'STLink.ExePath' , 'ST-LINK_CLI' ) ;
399-
400- return this . toFullPathForSettings ( flasher || 'null' ) ;
374+ return this . getFullPathByPluginConfig ( 'STLink.ExePath' )
375+ || this . findExePathInSystemEnv ( 'STM32_Programmer_CLI' )
376+ || this . findExePathInSystemEnv ( 'ST-LINK_CLI' )
377+ || 'null' ;
401378 }
402379
403380 getOpenOCDExePath ( ) : string {
404- return this . toFullPathForSettings (
405- this . getExePathFromConfig ( 'OpenOCD.ExePath' , ' openocd') || 'null'
406- ) ;
381+ return this . getFullPathByPluginConfig ( 'OpenOCD.ExePath' )
382+ || this . findExePathInSystemEnv ( ' openocd')
383+ || 'null' ;
407384 }
408385
409386 //-----------------------------IAR-------------------------------
410387
411388 getIARForStm8Dir ( ) : File {
412389
413- let defPath : string | undefined ;
414-
415- const path = this . getConfiguration ( ) . get < string > ( 'IAR.STM8.InstallDirectory' ) ;
416- if ( path ) {
417- defPath = Utility . formatPath ( this . toFullPathForSettings ( path ) ) ;
418- if ( File . IsExist ( defPath ) ) {
419- return new File ( defPath ) ;
420- }
390+ const p = this . getFullPathByPluginConfig ( 'IAR.STM8.InstallDirectory' ) ;
391+ if ( p ) {
392+ return new File ( p ) ;
421393 }
422394
423395 const execName = 'iccstm8' ;
@@ -435,11 +407,15 @@ export class SettingManager {
435407 }
436408 }
437409
438- return new File ( defPath || 'null' ) ;
410+ return new File ( 'null' ) ;
439411 }
440412
441413 getIarForArmDir ( ) : File {
442- return new File ( this . getGccFolderFromConfig ( 'IAR.ARM.Toolchain.InstallDirectory' , 'iccarm' ) || 'null' ) ;
414+ return new File (
415+ this . getFullPathByPluginConfig ( 'IAR.ARM.Toolchain.InstallDirectory' ) ||
416+ this . findGccCompilerRootInSystemEnv ( 'iccarm' ) ||
417+ 'null'
418+ ) ;
443419 }
444420
445421 //---------------------------- ARM ----------------------------
@@ -467,24 +443,29 @@ export class SettingManager {
467443 }
468444
469445 getGCCDir ( ) : File {
470- const execName = `${ this . getGCCPrefix ( ) } gcc` ;
471- return new File ( this . getGccFolderFromConfig ( 'ARM.GCC.InstallDirectory' , execName ) || 'null' ) ;
446+ return new File (
447+ this . getFullPathByPluginConfig ( 'ARM.GCC.InstallDirectory' ) ||
448+ this . findGccCompilerRootInSystemEnv ( `${ this . getGCCPrefix ( ) } gcc` ) ||
449+ 'null'
450+ ) ;
472451 }
473452
474453 // ---
475454
476455 getArmcc5Dir ( ) : File {
477456 return new File (
478- this . getGccFolderFromConfig ( 'ARM.ARMCC5.InstallDirectory' , 'armcc ') ||
457+ this . getFullPathByPluginConfig ( 'ARM.ARMCC5.InstallDirectory' ) ||
479458 this . pathCache . get ( 'ARMCC5' ) ||
459+ this . findGccCompilerRootInSystemEnv ( 'armcc' ) ||
480460 'null'
481461 ) ;
482462 }
483463
484464 getArmcc6Dir ( ) : File {
485465 return new File (
486- this . getGccFolderFromConfig ( 'ARM.ARMCC6.InstallDirectory' , 'armclang ') ||
466+ this . getFullPathByPluginConfig ( 'ARM.ARMCC6.InstallDirectory' ) ||
487467 this . pathCache . get ( 'ARMCC6' ) ||
468+ this . findGccCompilerRootInSystemEnv ( 'armclang' ) ||
488469 'null'
489470 ) ;
490471 }
@@ -584,18 +565,25 @@ export class SettingManager {
584565 //------------------------------- SDCC --------------------------------
585566
586567 getSdccDir ( ) : File {
587- return new File ( this . getGccFolderFromConfig ( 'SDCC.InstallDirectory' , 'sdcc' ) || 'null' ) ;
568+ return new File (
569+ this . getFullPathByPluginConfig ( 'SDCC.InstallDirectory' ) ||
570+ this . findGccCompilerRootInSystemEnv ( 'sdcc' ) ||
571+ 'null'
572+ ) ;
588573 }
589574
590575 getGnuSdccStm8Dir ( ) : File {
591- return new File ( this . getGccFolderFromConfig ( 'STM8.GNU-SDCC.InstallDirectory' , 'stm8-as' ) || ' null') ;
576+ return new File ( ' null') ; // disabled
592577 }
593578
594579 //------------------------------- RISC-V ----------------------------------
595580
596581 getRiscvToolFolder ( ) : File {
597- const execName = `${ this . getRiscvToolPrefix ( ) } gcc` ;
598- return new File ( this . getGccFolderFromConfig ( 'RISCV.InstallDirectory' , execName ) || 'null' ) ;
582+ return new File (
583+ this . getFullPathByPluginConfig ( 'RISCV.InstallDirectory' ) ||
584+ this . findGccCompilerRootInSystemEnv ( `${ this . getRiscvToolPrefix ( ) } gcc` ) ||
585+ 'null'
586+ ) ;
599587 }
600588
601589 getRiscvToolPrefix ( ) : string {
@@ -605,8 +593,11 @@ export class SettingManager {
605593 //------------------------------- Any GCC ----------------------------------
606594
607595 getAnyGccToolFolder ( ) : File {
608- const execName = `${ this . getAnyGccToolPrefix ( ) } gcc` ;
609- return new File ( this . getGccFolderFromConfig ( 'Toolchain.AnyGcc.InstallDirectory' , execName ) || 'null' ) ;
596+ return new File (
597+ this . getFullPathByPluginConfig ( 'Toolchain.AnyGcc.InstallDirectory' ) ||
598+ this . findGccCompilerRootInSystemEnv ( `${ this . getAnyGccToolPrefix ( ) } gcc` ) ||
599+ 'null'
600+ ) ;
610601 }
611602
612603 getAnyGccToolPrefix ( ) : string {
0 commit comments