Skip to content

Commit 96ea5d3

Browse files
committed
manual generate .d files for COSMIC_STM8
1 parent 47b1f63 commit 96ea5d3

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/CodeBuilder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export interface BuilderParams {
9393
env?: { [name: string]: any };
9494
}
9595

96+
export interface CompilerCommandsDatabaseItem {
97+
directory: string;
98+
file: string;
99+
command: string;
100+
}
101+
96102
export abstract class CodeBuilder {
97103

98104
protected readonly paramsFileName = 'builder.params';

src/EIDEProject.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import * as events from 'events';
2929
import * as ini from 'ini';
3030
import * as os from 'os';
3131
import * as yaml from 'yaml';
32+
import * as child_process from 'child_process';
33+
3234
import {
3335
CppToolsApi, Version, CustomConfigurationProvider, getCppToolsApi,
3436
SourceFileConfigurationItem, WorkspaceBrowseConfiguration
@@ -69,6 +71,7 @@ import * as iconv from 'iconv-lite';
6971
import * as globmatch from 'micromatch'
7072
import { ICompileOptions, EventData, CurrentDevice, ArmBaseCompileConfigModel } from './EIDEProjectModules';
7173
import * as FileLock from '../lib/node-utility/FileLock';
74+
import { CompilerCommandsDatabaseItem } from './CodeBuilder';
7275

7376
export 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)));

src/EIDEProjectExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3921,7 +3921,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
39213921
if (this.compiler_diags.has(prj.getUid())) {
39223922
this.compiler_diags.get(prj.getUid())?.clear();
39233923
}
3924-
})
3924+
});
39253925

39263926
// build finish event
39273927
codeBuilder.on('finished', (done) => {

0 commit comments

Comments
 (0)