修复编译问题
This commit is contained in:
@@ -181,7 +181,7 @@ VS Code C/C++ IntelliSense 可能无法识别这些寄存器。插件会自动
|
|||||||
工程目录\build\
|
工程目录\build\
|
||||||
```
|
```
|
||||||
|
|
||||||
为了兼容官方工具链,插件会先让 `c.exe` 按官方风格输出到工程根目录的小写文件名前缀,例如 `ft61e132a.hex`,编译成功后再复制为配置输出目录中的工程名文件,例如 `build\FT61E132A.hex`。
|
为了兼容官方工具链,插件会先让 `c.exe` 按官方风格输出到工程根目录的小写文件名前缀,例如 `ft61e132a.hex`,编译成功后再把所有编译生成/更新的产物移动到配置输出目录,例如 `build\FT61E132A.hex`、`build\FT61E132A.map`、`build\FT61E132A.lst`、`build\button.p1` 等。
|
||||||
|
|
||||||
也可以设置为绝对路径,例如:
|
也可以设置为绝对路径,例如:
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "fmd-c-compiler",
|
"name": "fmd-c-compiler",
|
||||||
"version": "0.2.13",
|
"version": "0.2.15",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "fmd-c-compiler",
|
"name": "fmd-c-compiler",
|
||||||
"version": "0.2.13",
|
"version": "0.2.15",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.0.0",
|
"@types/node": "^20.0.0",
|
||||||
"@types/vscode": "^1.85.0",
|
"@types/vscode": "^1.85.0",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"publisher": "kevinngmanfong",
|
"publisher": "kevinngmanfong",
|
||||||
"displayName": "FMD C Compiler",
|
"displayName": "FMD C Compiler",
|
||||||
"description": "FMD/FT61FC6X 系列 MCU 编译器支持(C.exe 工具链)",
|
"description": "FMD/FT61FC6X 系列 MCU 编译器支持(C.exe 工具链)",
|
||||||
"version": "0.2.13",
|
"version": "0.2.15",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "resources/icon.png",
|
"icon": "resources/icon.png",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+59
-22
@@ -136,9 +136,8 @@ export class FmdCompiler {
|
|||||||
this.outputChannel.appendLine('');
|
this.outputChannel.appendLine('');
|
||||||
this.outputChannel.appendLine('========== 编译成功 ==========');
|
this.outputChannel.appendLine('========== 编译成功 ==========');
|
||||||
|
|
||||||
this.copyCompilerArtifacts(compilerArtifacts, artifacts);
|
this.moveCompilerArtifacts(projectDir, compilerArtifacts, artifacts);
|
||||||
this.logArtifact(artifacts.hexFile);
|
this.logBuildArtifacts(artifacts.outputDir);
|
||||||
this.logArtifact(artifacts.binFile);
|
|
||||||
|
|
||||||
vscode.window.showInformationMessage('FMD: 编译成功 ✓');
|
vscode.window.showInformationMessage('FMD: 编译成功 ✓');
|
||||||
return { success: true, exitCode, artifacts };
|
return { success: true, exitCode, artifacts };
|
||||||
@@ -222,20 +221,27 @@ export class FmdCompiler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanExts = ['.obj', '.p1', '.pre', '.d', '.lpp', '.cmf', '.sym', '.map', '.rlf', '.sdb', '.asm'];
|
const cleanExts = ['.as', '.asm', '.bin', '.cmf', '.cof', '.d', '.hex', '.hxl', '.lpp', '.lst', '.map', '.obj', '.p1', '.pre', '.rlf', '.sdb', '.sym'];
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const files = fs.readdirSync(projectDir);
|
const cfg = getConfig();
|
||||||
for (const f of files) {
|
const outputDir = this.resolveOutputDir(projectDir, cfg.outputDir);
|
||||||
const ext = path.extname(f).toLowerCase();
|
for (const dir of Array.from(new Set([projectDir, outputDir]))) {
|
||||||
if (cleanExts.includes(ext)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.unlinkSync(path.join(projectDir, f));
|
continue;
|
||||||
count++;
|
}
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
for (const f of files) {
|
||||||
|
const ext = path.extname(f).toLowerCase();
|
||||||
|
if (cleanExts.includes(ext)) {
|
||||||
|
fs.unlinkSync(path.join(dir, f));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.outputChannel.appendLine(`[FMD] 清理完成,删除 ${count} 个中间文件`);
|
this.outputChannel.appendLine(`[FMD] 清理完成,删除 ${count} 个编译产物`);
|
||||||
vscode.window.showInformationMessage(`FMD: 清理完成,删除 ${count} 个中间文件`);
|
vscode.window.showInformationMessage(`FMD: 清理完成,删除 ${count} 个编译产物`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
vscode.window.showErrorMessage(`FMD 清理失败: ${err}`);
|
vscode.window.showErrorMessage(`FMD 清理失败: ${err}`);
|
||||||
}
|
}
|
||||||
@@ -271,22 +277,44 @@ export class FmdCompiler {
|
|||||||
return path.isAbsolute(outputDir) ? outputDir : path.join(projectDir, outputDir);
|
return path.isAbsolute(outputDir) ? outputDir : path.join(projectDir, outputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private copyCompilerArtifacts(from: FmdOutputArtifacts, to: FmdOutputArtifacts): void {
|
private moveCompilerArtifacts(projectDir: string, from: FmdOutputArtifacts, to: FmdOutputArtifacts): void {
|
||||||
fs.mkdirSync(to.outputDir, { recursive: true });
|
fs.mkdirSync(to.outputDir, { recursive: true });
|
||||||
const pairs = [
|
const artifactExts = new Set([
|
||||||
[from.hexFile, to.hexFile],
|
'.as', '.asm', '.bin', '.cmf', '.cof', '.d', '.hex', '.hxl', '.lpp',
|
||||||
[from.binFile, to.binFile],
|
'.lst', '.map', '.obj', '.p1', '.pre', '.rlf', '.sdb', '.sym',
|
||||||
];
|
]);
|
||||||
|
|
||||||
for (const [source, target] of pairs) {
|
for (const file of fs.readdirSync(projectDir)) {
|
||||||
if (source === target || !fs.existsSync(source)) {
|
const source = path.join(projectDir, file);
|
||||||
|
if (!fs.statSync(source).isFile()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ext = path.extname(file).toLowerCase();
|
||||||
|
if (!artifactExts.has(ext)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetName = this.getOutputArtifactName(file, from.projectName, to.projectName);
|
||||||
|
const target = path.join(to.outputDir, targetName);
|
||||||
|
if (source === target) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
fs.copyFileSync(source, target);
|
fs.copyFileSync(source, target);
|
||||||
this.outputChannel.appendLine(`复制输出: ${source} -> ${target}`);
|
fs.unlinkSync(source);
|
||||||
|
this.outputChannel.appendLine(`移动输出: ${source} -> ${target}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getOutputArtifactName(fileName: string, compilerProjectName: string, outputProjectName: string): string {
|
||||||
|
const base = path.basename(fileName, path.extname(fileName));
|
||||||
|
const ext = path.extname(fileName);
|
||||||
|
return base.toLowerCase() === compilerProjectName.toLowerCase()
|
||||||
|
? outputProjectName + ext.toLowerCase()
|
||||||
|
: fileName;
|
||||||
|
}
|
||||||
|
|
||||||
private resolveCompilerChip(projectDir: string, projectName: string, projectChip: string, compilerPath: string): string {
|
private resolveCompilerChip(projectDir: string, projectName: string, projectChip: string, compilerPath: string): string {
|
||||||
const historicalChip = this.readMachineTypeFromMap(projectDir, projectName);
|
const historicalChip = this.readMachineTypeFromMap(projectDir, projectName);
|
||||||
if (historicalChip && this.checkCompilerChipSupport(compilerPath, historicalChip).supported) {
|
if (historicalChip && this.checkCompilerChipSupport(compilerPath, historicalChip).supported) {
|
||||||
@@ -515,8 +543,17 @@ export class FmdCompiler {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private logArtifact(filePath: string): void {
|
private logBuildArtifacts(outputDir: string): void {
|
||||||
if (fs.existsSync(filePath)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outputChannel.appendLine(`输出目录: ${outputDir}`);
|
||||||
|
for (const file of fs.readdirSync(outputDir)) {
|
||||||
|
const filePath = path.join(outputDir, file);
|
||||||
|
if (!fs.statSync(filePath).isFile()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const stat = fs.statSync(filePath);
|
const stat = fs.statSync(filePath);
|
||||||
this.outputChannel.appendLine(`输出: ${filePath} (${stat.size} 字节)`);
|
this.outputChannel.appendLine(`输出: ${filePath} (${stat.size} 字节)`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user