@@ -29,6 +29,8 @@ import * as events from 'events';
2929import * as ini from 'ini' ;
3030import * as os from 'os' ;
3131import * as yaml from 'yaml' ;
32+ import * as child_process from 'child_process' ;
33+
3234import {
3335 CppToolsApi , Version , CustomConfigurationProvider , getCppToolsApi ,
3436 SourceFileConfigurationItem , WorkspaceBrowseConfiguration
@@ -69,6 +71,7 @@ import * as iconv from 'iconv-lite';
6971import * as globmatch from 'micromatch'
7072import { ICompileOptions , EventData , CurrentDevice , ArmBaseCompileConfigModel } from './EIDEProjectModules' ;
7173import * as FileLock from '../lib/node-utility/FileLock' ;
74+ import { CompilerCommandsDatabaseItem } from './CodeBuilder' ;
7275
7376export class CheckError extends Error {
7477}
@@ -2674,6 +2677,35 @@ class EIDEProject extends AbstractProject {
26742677 /* check source references is enabled ? */
26752678 if ( ! SettingManager . GetInstance ( ) . isDisplaySourceRefs ( ) ) return ;
26762679
2680+ let compiler_cmd_db : CompilerCommandsDatabaseItem [ ] = [ ] ;
2681+ let generate_dep_file : ( ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => void ) | undefined ;
2682+
2683+ // for COSMIC STM8, we need manual generate .d files
2684+ if ( this . getToolchain ( ) . name == 'COSMIC_STM8' ) {
2685+ const compilerDBFile = File . fromArray ( [ this . getOutputFolder ( ) . path , 'compile_commands.json' ] ) ;
2686+ if ( compilerDBFile . IsFile ( ) ) {
2687+ try {
2688+ compiler_cmd_db = jsonc . parse ( compilerDBFile . Read ( ) ) ;
2689+ generate_dep_file = ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => {
2690+ let idx = cmd_db . findIndex ( ( e ) => e . file == srcpath ) ;
2691+ if ( idx != - 1 ) {
2692+ try {
2693+ let cmd_item = cmd_db [ idx ] ;
2694+ let command = cmd_item . command . replace ( '-co' , '-sm -co' ) ;
2695+ const depcont = child_process . execSync ( command , { cwd : cmd_item . directory } ) . toString ( ) ;
2696+ fs . writeFileSync ( deppath , depcont ) ;
2697+ } catch ( error ) {
2698+ GlobalEvent . emit ( 'globalLog' , newMessage ( 'Warning' , `Failed to make '${ deppath } ', msg: ${ ( < Error > error ) . message } ` ) ) ;
2699+ try { fs . unlinkSync ( deppath ) } catch ( error ) { } // del old .d file
2700+ }
2701+ }
2702+ } ;
2703+ } catch ( error ) {
2704+ GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2705+ }
2706+ }
2707+ }
2708+
26772709 const toolName = toolchain_ || this . getToolchain ( ) . name ;
26782710
26792711 const outFolder = this . getOutputFolder ( ) ;
@@ -2684,6 +2716,7 @@ class EIDEProject extends AbstractProject {
26842716 const refMap = JSON . parse ( refListFile . Read ( ) ) ;
26852717 for ( const srcpath in refMap ) {
26862718 const refFile = new File ( ( < string > refMap [ srcpath ] ) . replace ( / \. [ ^ \\ \/ \. ] + $ / , '.d' ) ) ;
2719+ if ( generate_dep_file ) generate_dep_file ( compiler_cmd_db , srcpath , refFile . path ) ;
26872720 if ( ! refFile . IsFile ( ) ) continue ;
26882721 const refs = this . parseRefFile ( refFile , toolName ) . filter ( p => p != srcpath ) ;
26892722 this . srcRefMap . set ( srcpath , refs . map ( ( path ) => new File ( path ) ) ) ;
0 commit comments