refactor: 优化 Vivado 配置检测逻辑
- 使用环境变量中的 vivado 命令替代磁盘路径搜索 - 修改验证逻辑,支持环境变量命令 - 简化自动检测函数实现
This commit is contained in:
@ -51,9 +51,11 @@ export function validateConfig(config: VivadoConfig): string | null {
|
|||||||
if (!config.enabled) {
|
if (!config.enabled) {
|
||||||
return 'Vivado 未启用';
|
return 'Vivado 未启用';
|
||||||
}
|
}
|
||||||
if (!fs.existsSync(config.executablePath)) {
|
// 如果是完整路径,检查文件是否存在
|
||||||
|
if (path.isAbsolute(config.executablePath) && !fs.existsSync(config.executablePath)) {
|
||||||
return `Vivado 可执行文件不存在: ${config.executablePath}`;
|
return `Vivado 可执行文件不存在: ${config.executablePath}`;
|
||||||
}
|
}
|
||||||
|
// 环境变量命令不检查,运行时会自动报错
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,34 +74,14 @@ export function resolveWorkingDir(workingDir: string): string {
|
|||||||
* 自动检测 Vivado
|
* 自动检测 Vivado
|
||||||
*/
|
*/
|
||||||
function autoDetectVivado(): VivadoConfig | null {
|
function autoDetectVivado(): VivadoConfig | null {
|
||||||
const drives = ['C', 'D', 'E', 'F', 'G'];
|
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||||
|
|
||||||
for (const drive of drives) {
|
// 默认使用环境变量中的 vivado 命令
|
||||||
const vivadoDir = `${drive}:\\Xilinx\\Vivado`;
|
return {
|
||||||
if (!fs.existsSync(vivadoDir)) {
|
enabled: true,
|
||||||
continue;
|
executablePath: 'vivado',
|
||||||
}
|
workingDir: workspaceFolder
|
||||||
|
? path.join(workspaceFolder.uri.fsPath, 'vivado_projects')
|
||||||
// 读取所有版本目录
|
: path.join(process.env.USERPROFILE || 'C:\\Users\\Default', 'vivado_projects')
|
||||||
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