Skip to content

Commit

Permalink
Fix #98, CMake configure not awaited
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Oct 15, 2024
1 parent 05dc290 commit c48b2ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/commands/configureCmake.mts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class ConfigureCmakeCommand extends Command {
if (await configureCmakeNinja(workspaceFolder.uri)) {
void window.showInformationMessage("CMake has configured your build.");
} else {
void window.showWarningMessage("CMake has not configured your build.");
void window.showWarningMessage("CMake failed to configure your build.");
}
}
}
Expand Down
77 changes: 33 additions & 44 deletions src/utils/cmakeUtil.mts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
folder.with({ path: join(folder.fsPath, "CMakeLists.txt") })
);

void window.withProgress(
await window.withProgress(
{
location: ProgressLocation.Notification,
cancellable: true,
Expand All @@ -178,8 +178,6 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
?.replace(HOME_VAR, homedir().replaceAll("\\", "/")) || "cmake";

// TODO: analyze command result
// TODO: option for the user to choose the generator
// TODO: maybe delete the build folder before running cmake so
// all configuration files in build get updates
const customEnv = process.env;
/*customEnv["PYTHONHOME"] = pythonPath.includes("/")
Expand All @@ -201,49 +199,40 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
: ""
}` + `-G Ninja -B ./build "${folder.fsPath}"`;

const child = exec(
command,
{
env: customEnv,
cwd: folder.fsPath,
},
(error, stdout, stderr) => {
if (error) {
Logger.error(LoggerSource.cmake, error);
Logger.warn(
LoggerSource.cmake,
`Stdout of failed cmake: ${stdout}`
);
Logger.warn(
LoggerSource.cmake,
`Stderr of failed cmake: ${stderr}`
);
await new Promise<void>((resolve, reject) => {
// use exec to be able to cancel the process
const child = exec(
command,
{
env: customEnv,
cwd: folder.fsPath,
},
error => {
progress.report({ increment: 100 });
if (error) {
if (error.signal === "SIGTERM") {
Logger.warn(
LoggerSource.cmake,
"CMake configuration process was canceled."
);
} else {
Logger.error(
LoggerSource.cmake,
`Failed to configure CMake:`,
error
);
}

reject(error);
}

resolve();
}
);

return;
}
);

child.on("error", err => {
Logger.error(LoggerSource.cmake, err);
});

//child.stdout?.on("data", data => {});
child.on("close", () => {
progress.report({ increment: 100 });
});
child.on("exit", code => {
if (code !== 0) {
Logger.error(
LoggerSource.cmake,
`CMake exited with code ${code ?? "N/A"}`
);
}
progress.report({ increment: 100 });
});

token.onCancellationRequested(() => {
child.kill();
token.onCancellationRequested(() => {
child.kill();
});
});
}
);
Expand Down

0 comments on commit c48b2ec

Please sign in to comment.