@@ -88,7 +88,8 @@ import {
8888 txt_no ,
8989 remove_this_item ,
9090 view_str$prompt$filesOptionsComment ,
91- view_str$virual_doc_provider_banner
91+ view_str$virual_doc_provider_banner ,
92+ view_str$missed_stubs_added
9293} from './StringTable' ;
9394import { CodeBuilder , BuildOptions } from './CodeBuilder' ;
9495import { ExceptionToMessage , newMessage } from './Message' ;
@@ -128,7 +129,7 @@ import {
128129} from 'vscode-cpptools' ;
129130import * as eclipseParser from './EclipseProjectParser' ;
130131import { isArray } from 'util' ;
131- import { parseIarCompilerLog , CompilerDiagnostics , parseGccCompilerLog , parseArmccCompilerLog , parseKeilc51CompilerLog , parseSdccCompilerLog , parseCosmicStm8CompilerLog } from './ProblemMatcher' ;
132+ import { parseIarCompilerLog , CompilerDiagnostics , parseGccCompilerLog , parseArmccCompilerLog , parseKeilc51CompilerLog , parseSdccCompilerLog , parseCosmicStm8CompilerLog , EideDiagnosticCode } from './ProblemMatcher' ;
132133import * as iarParser from './IarProjectParser' ;
133134import * as ArmCpuUtils from './ArmCpuUtils' ;
134135import { ShellFlasherIndexItem } from './WebInterface/WebInterface' ;
@@ -3488,6 +3489,16 @@ export class ProjectExplorer implements CustomConfigurationProvider {
34883489 this . _event . emit ( event , arg ) ;
34893490 }
34903491
3492+ /**
3493+ *
3494+ * @param callbk return true to break foreach
3495+ */
3496+ foreachProjects ( callbk : ( val : AbstractProject , index : number ) => boolean | undefined ) {
3497+ this . dataProvider . traverseProjects ( ( prj , idx ) => {
3498+ return callbk ( prj , idx ) ;
3499+ } ) ;
3500+ }
3501+
34913502 getProjectByTreeItem ( prjItem ?: ProjTreeItem ) : AbstractProject | undefined {
34923503 return prjItem instanceof ProjTreeItem ?
34933504 this . dataProvider . GetProjectByIndex ( prjItem . val . projectIndex ) :
@@ -3518,6 +3529,36 @@ export class ProjectExplorer implements CustomConfigurationProvider {
35183529
35193530 // -------
35203531
3532+ createSysStubs ( prjuid : string | undefined ) {
3533+
3534+ const prj = prjuid
3535+ ? this . dataProvider . getProjectByUid ( prjuid )
3536+ : this . dataProvider . getActiveProject ( ) ;
3537+ if ( ! prj )
3538+ return ; // no project
3539+
3540+ const tarFile = File . from ( prj . getRootDir ( ) . path , 'sys_stubs.c' ) ;
3541+ for ( const grp of prj . getFileGroups ( ) ) {
3542+ for ( const e of grp . files ) {
3543+ if ( tarFile . path === e . file . path )
3544+ return ; // it's existed, abort.
3545+ }
3546+ }
3547+
3548+ try {
3549+ const srcFile = File . from ( ResManager . instance ( ) . getAppDataDir ( ) . path , 'gcc_posix_stubs.c' ) ;
3550+ tarFile . Write ( srcFile . Read ( ) ) ;
3551+ const vSrcManger = prj . getVirtualSourceManager ( ) ;
3552+ vSrcManger . addFile ( VirtualSource . rootName , tarFile . path ) ;
3553+ // clear diags
3554+ const uri = vscode . Uri . file ( File . from ( prj . getOutputFolder ( ) . path , 'compiler.log' ) . path ) ;
3555+ this . compiler_diags . get ( prj . getUid ( ) ) ?. delete ( uri ) ;
3556+ GlobalEvent . show_msgbox ( 'Info' , view_str$missed_stubs_added . replace ( '{}' , tarFile . name ) ) ;
3557+ } catch ( error ) {
3558+ GlobalEvent . show_msgbox ( 'Error' , error ) ;
3559+ }
3560+ }
3561+
35213562 openLibsGeneratorConfig ( prjItem ?: ProjTreeItem ) {
35223563
35233564 const proj = this . getProjectByTreeItem ( prjItem ) ;
@@ -3871,13 +3912,52 @@ export class ProjectExplorer implements CustomConfigurationProvider {
38713912 }
38723913 }
38733914
3915+ private parseLdLogs ( file : File ) : { content : string , idx : number } [ ] {
3916+
3917+ const logLines : { content : string , idx : number } [ ] = [ ] ;
3918+
3919+ try {
3920+
3921+ const fileLines = file . Read ( ) . split ( / \r \n | \n / ) ;
3922+
3923+ let logStarted = false ;
3924+ let logEnd = false ;
3925+
3926+ fileLines . forEach ( ( line , idx ) => {
3927+
3928+ if ( logEnd )
3929+ return ;
3930+
3931+ if ( ! logStarted ) {
3932+ if ( line . startsWith ( '>>> ld' ) ) {
3933+ logStarted = true ;
3934+ }
3935+ } else {
3936+ if ( line . startsWith ( '>>>' ) ) {
3937+ logEnd = true ;
3938+ } else {
3939+ logLines . push ( {
3940+ content : line ,
3941+ idx
3942+ } ) ;
3943+ }
3944+ }
3945+ } ) ;
3946+
3947+ } catch ( error ) {
3948+ // nothing todo
3949+ }
3950+
3951+ return logLines ;
3952+ }
3953+
38743954 private updateCompilerDiagsAfterBuild ( prj : AbstractProject ) {
38753955
38763956 let diag_res : CompilerDiagnostics | undefined ;
38773957
3878- try {
3958+ const logFile = File . from ( prj . getOutputFolder ( ) . path , 'compiler.log' ) ;
38793959
3880- const logFile = File . fromArray ( [ prj . getOutputFolder ( ) . path , 'compiler.log' ] ) ;
3960+ try {
38813961
38823962 switch ( prj . getToolchain ( ) . name ) {
38833963 case 'IAR_ARM' :
@@ -3906,6 +3986,46 @@ export class ProjectExplorer implements CustomConfigurationProvider {
39063986 GlobalEvent . log_warn ( error ) ;
39073987 }
39083988
3989+ if ( isGccFamilyToolchain ( prj . toolchainName ( ) ) ) {
3990+ // examples:
3991+ // >>> ld
3992+ // ....
3993+ // warning: _getpid is not implemented and will always fail
3994+ const allStubs = [
3995+ '_chown' , '_execve' , '_fork' , '_fstat' , '_getpid' ,
3996+ '_gettimeofday' , '_isatty' , '_kill' , '_link' , '_lseek' ,
3997+ '_open' , '_close' , '_read' , '_readlink' , '_stat' , '_symlink' , '_times' , '_unlink' , '_wait' , '_write' ,
3998+ ] ;
3999+ const missedStubs : { name : string , lineIdx : number } [ ] = [ ] ;
4000+
4001+ this . parseLdLogs ( logFile ) . forEach ( line => {
4002+ const m = / w a r n i n g : ( \w + ) i s n o t i m p l e m e n t e d a n d w i l l a l w a y s f a i l / . exec ( line . content ) ;
4003+ if ( m && m . length > 1 ) {
4004+ const name = m [ 1 ] ;
4005+ if ( allStubs . includes ( name ) )
4006+ missedStubs . push ( { name, lineIdx : line . idx } ) ;
4007+ }
4008+ } ) ;
4009+
4010+ if ( missedStubs . length > 0 ) {
4011+ if ( diag_res == undefined )
4012+ diag_res = { } ;
4013+ const diags : vscode . Diagnostic [ ] = [ ] ;
4014+ for ( const ele of missedStubs ) {
4015+ const range = new vscode . Range (
4016+ new vscode . Position ( ele . lineIdx , 0 ) ,
4017+ new vscode . Position ( ele . lineIdx , 54 ) ) ;
4018+ const diag = new vscode . Diagnostic ( range ,
4019+ `warning: ${ ele . name } is not implemented and will always fail` ,
4020+ vscode . DiagnosticSeverity . Warning ) ;
4021+ diag . source = "eide" ;
4022+ diag . code = EideDiagnosticCode . GCC_SYS_STUB_MISSED ;
4023+ diags . push ( diag ) ;
4024+ }
4025+ diag_res [ logFile . path ] = diags ;
4026+ }
4027+ }
4028+
39094029 if ( diag_res ) {
39104030
39114031 const uid = prj . getUid ( ) ;
0 commit comments