fix: support hcpu/lcpu project entry for run triggers#26
fix: support hcpu/lcpu project entry for run triggers#26
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates project path resolution so build/run-related features work when the project’s SConscript lives under project/hcpu or project/lcpu (instead of only project/).
Changes:
- Add
LCPU_SUBFOLDERconstant and extend project detection to locateSConscriptunderproject/hcpu,project/lcpu, orproject/. - Extend
getProjectInfo()to return the resolved project entry path (absolute + workspace-relative). - Update terminal cd behavior, board command generation, and clangd config generation to use the resolved project entry path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/projectUtils.ts | Adds workspace root helper and logic to resolve the effective project entry directory based on where SConscript is found. |
| src/services/terminalService.ts | Uses resolved project entry path when cd-ing the terminal into the project. |
| src/services/boardService.ts | Uses resolved project entry path/relative path for build folder and board search path computations. |
| src/constants/index.ts | Adds LCPU_SUBFOLDER = 'lcpu'. |
| src/commands/configCommands.ts | Builds clangd --compile-commands-dir using the resolved project entry relative path. |
Comments suppressed due to low confidence (2)
src/services/boardService.ts:166
projectPathfalls back to an empty string whengetProjectInfo()returns null. That makes subsequentpath.relative(projectPath, ...)calculations use the process CWD (Node treats "" as "."), which can generate incorrect--board_search_pathvalues forproject_local/customboards. Use a deterministic fallback (e.g.${workspaceRoot}/project) or return/throw whenprojectInfois missing sopath.relativealways has a valid base path.
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath || '';
let boardSearchArg = '';
const availableBoards = await this.discoverBoards();
const currentBoard = availableBoards.find(b => b.name === boardName);
if (currentBoard) {
if (currentBoard.type === 'sdk') {
boardSearchArg = '';
} else if (currentBoard.type === 'project_local') {
const projectLocalBoardsDir = path.dirname(currentBoard.path);
const relativeToProject = path.relative(projectPath, projectLocalBoardsDir);
boardSearchArg = ` --board_search_path="${relativeToProject}"`;
} else if (currentBoard.type === 'custom') {
const relativeToProject = path.relative(projectPath, currentBoard.path);
boardSearchArg = ` --board_search_path="${path.dirname(relativeToProject)}"`;
src/services/boardService.ts:192
- Same issue as
getCompileCommand: falling back toprojectPath = ''makespath.relative(projectPath, ...)compute relative paths from the process CWD, producing incorrect--board_search_pathvalues whenprojectInfois null. Prefer a deterministic fallback base path (workspaceRoot/project) or fail early if no project can be resolved.
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath || '';
let boardSearchArg = '';
const availableBoards = await this.discoverBoards();
const currentBoard = availableBoards.find(b => b.name === boardName);
if (currentBoard && currentBoard.type !== 'sdk') {
if (currentBoard.type === 'project_local') {
const projectLocalBoardsDir = path.dirname(currentBoard.path);
const relativeToProject = path.relative(projectPath, projectLocalBoardsDir);
boardSearchArg = ` --board_search_path="${relativeToProject}"`;
} else if (currentBoard.type === 'custom') {
const relativeToProject = path.relative(projectPath, currentBoard.path);
boardSearchArg = ` --board_search_path="${path.dirname(relativeToProject)}"`;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| path.join(projectPath, SCONSCRIPT_FILE), | ||
| path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE), | ||
| path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE) |
There was a problem hiding this comment.
resolveProjectEntry() checks candidates in the order [project/hcpu, project/lcpu, project], but the failure log message is built from getSconscriptCandidatePaths() which returns [project, project/hcpu, project/lcpu]. This makes the "Checked:" list inaccurate and can mislead debugging. Align the candidate order (either change projectCandidates or getSconscriptCandidatePaths).
| path.join(projectPath, SCONSCRIPT_FILE), | |
| path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE), | |
| path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE) | |
| path.join(projectPath, HCPU_SUBFOLDER, SCONSCRIPT_FILE), | |
| path.join(projectPath, LCPU_SUBFOLDER, SCONSCRIPT_FILE), | |
| path.join(projectPath, SCONSCRIPT_FILE) |
| : ''; | ||
| const projectPath = path.join(workspaceRoot, 'project'); | ||
| const projectInfo = getProjectInfo(); | ||
| const projectPath = projectInfo?.projectEntryPath || ''; |
There was a problem hiding this comment.
const projectPath = this.getProjectFolderPath();
| : ''; | ||
| const projectPath = path.join(workspaceRoot, 'project'); | ||
| const projectInfo = getProjectInfo(); | ||
| const projectPath = projectInfo?.projectEntryPath || ''; |
There was a problem hiding this comment.
统一调用
const projectPath = this.getProjectFolderPath();
| const workspaceRoot = workspaceFolders[0].uri.fsPath; | ||
| const projectPath = path.join(workspaceRoot, PROJECT_SUBFOLDER); | ||
| const projectInfo = getProjectInfo(); | ||
| const projectPath = projectInfo?.projectEntryPath || path.join(workspaceRoot, PROJECT_SUBFOLDER); |
There was a problem hiding this comment.
// 切换到项目目录
const projectInfo = getProjectInfo();
const projectPath = projectInfo?.projectEntryPath;
if (!projectPath) {
// 提示一下错误
this.logService.error('[terminalService] Project entry path not found');
return terminal;
}
terminal.sendText(`cd "${projectPath}"`);
this.logService.debug(`Changed terminal directory to: ${projectPath}`);
No description provided.