feat: 实现 Vivado 创建工程功能
- 添加 createVivadoProject 工具 - 实现 Vivado 自动检测(支持所有盘符和版本) - 添加 TCL 脚本生成器 - 添加配置管理模块 - 添加测试命令
This commit is contained in:
105
src/utils/vivadoConfig.ts
Normal file
105
src/utils/vivadoConfig.ts
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Vivado 配置管理
|
||||
* 功能:读取和验证 Vivado 配置
|
||||
* 依赖:vscode
|
||||
*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export interface VivadoConfig {
|
||||
enabled: boolean;
|
||||
executablePath: string;
|
||||
workingDir: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Vivado 配置
|
||||
*/
|
||||
export function getVivadoConfig(): VivadoConfig | null {
|
||||
// 优先读取项目配置
|
||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||
if (workspaceFolder) {
|
||||
const projectConfigPath = path.join(
|
||||
workspaceFolder.uri.fsPath,
|
||||
'.vscode',
|
||||
'ic-coder-vivado.json'
|
||||
);
|
||||
if (fs.existsSync(projectConfigPath)) {
|
||||
const content = fs.readFileSync(projectConfigPath, 'utf-8');
|
||||
return JSON.parse(content).vivado;
|
||||
}
|
||||
}
|
||||
|
||||
// 读取全局配置
|
||||
const config = vscode.workspace.getConfiguration('ic-coder');
|
||||
const vivadoConfig = config.get<VivadoConfig>('vivado');
|
||||
|
||||
if (vivadoConfig) {
|
||||
return vivadoConfig;
|
||||
}
|
||||
|
||||
// 自动检测 Vivado
|
||||
return autoDetectVivado();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证配置
|
||||
*/
|
||||
export function validateConfig(config: VivadoConfig): string | null {
|
||||
if (!config.enabled) {
|
||||
return 'Vivado 未启用';
|
||||
}
|
||||
if (!fs.existsSync(config.executablePath)) {
|
||||
return `Vivado 可执行文件不存在: ${config.executablePath}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析工作目录
|
||||
*/
|
||||
export function resolveWorkingDir(workingDir: string): string {
|
||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||
if (workspaceFolder) {
|
||||
return workingDir.replace('${workspaceFolder}', workspaceFolder.uri.fsPath);
|
||||
}
|
||||
return workingDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动检测 Vivado
|
||||
*/
|
||||
function autoDetectVivado(): VivadoConfig | null {
|
||||
const drives = ['C', 'D', 'E', 'F', 'G'];
|
||||
|
||||
for (const drive of drives) {
|
||||
const vivadoDir = `${drive}:\\Xilinx\\Vivado`;
|
||||
if (!fs.existsSync(vivadoDir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 读取所有版本目录
|
||||
const versions = fs.readdirSync(vivadoDir)
|
||||
.filter(v => fs.statSync(path.join(vivadoDir, v)).isDirectory())
|
||||
.sort()
|
||||
.reverse(); // 最新版本在前
|
||||
|
||||
for (const version of versions) {
|
||||
const p = path.join(vivadoDir, version, 'bin', 'vivado.bat');
|
||||
if (fs.existsSync(p)) {
|
||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||
return {
|
||||
enabled: true,
|
||||
executablePath: p,
|
||||
workingDir: workspaceFolder
|
||||
? path.join(workspaceFolder.uri.fsPath, 'vivado_projects')
|
||||
: `${drive}:\\vivado_projects`
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user