@@ -165,7 +165,7 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
165165 folder . with ( { path : join ( folder . fsPath , "CMakeLists.txt" ) } )
166166 ) ;
167167
168- void window . withProgress (
168+ await window . withProgress (
169169 {
170170 location : ProgressLocation . Notification ,
171171 cancellable : true ,
@@ -178,8 +178,6 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
178178 ?. replace ( HOME_VAR , homedir ( ) . replaceAll ( "\\" , "/" ) ) || "cmake" ;
179179
180180 // TODO: analyze command result
181- // TODO: option for the user to choose the generator
182- // TODO: maybe delete the build folder before running cmake so
183181 // all configuration files in build get updates
184182 const customEnv = process . env ;
185183 /*customEnv["PYTHONHOME"] = pythonPath.includes("/")
@@ -201,49 +199,40 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
201199 : ""
202200 } ` + `-G Ninja -B ./build "${ folder . fsPath } "` ;
203201
204- const child = exec (
205- command ,
206- {
207- env : customEnv ,
208- cwd : folder . fsPath ,
209- } ,
210- ( error , stdout , stderr ) => {
211- if ( error ) {
212- Logger . error ( LoggerSource . cmake , error ) ;
213- Logger . warn (
214- LoggerSource . cmake ,
215- `Stdout of failed cmake: ${ stdout } `
216- ) ;
217- Logger . warn (
218- LoggerSource . cmake ,
219- `Stderr of failed cmake: ${ stderr } `
220- ) ;
202+ await new Promise < void > ( ( resolve , reject ) => {
203+ // use exec to be able to cancel the process
204+ const child = exec (
205+ command ,
206+ {
207+ env : customEnv ,
208+ cwd : folder . fsPath ,
209+ } ,
210+ error => {
211+ progress . report ( { increment : 100 } ) ;
212+ if ( error ) {
213+ if ( error . signal === "SIGTERM" ) {
214+ Logger . warn (
215+ LoggerSource . cmake ,
216+ "CMake configuration process was canceled."
217+ ) ;
218+ } else {
219+ Logger . error (
220+ LoggerSource . cmake ,
221+ `Failed to configure CMake:` ,
222+ error
223+ ) ;
224+ }
225+
226+ reject ( error ) ;
227+ }
228+
229+ resolve ( ) ;
221230 }
231+ ) ;
222232
223- return ;
224- }
225- ) ;
226-
227- child . on ( "error" , err => {
228- Logger . error ( LoggerSource . cmake , err ) ;
229- } ) ;
230-
231- //child.stdout?.on("data", data => {});
232- child . on ( "close" , ( ) => {
233- progress . report ( { increment : 100 } ) ;
234- } ) ;
235- child . on ( "exit" , code => {
236- if ( code !== 0 ) {
237- Logger . error (
238- LoggerSource . cmake ,
239- `CMake exited with code ${ code ?? "N/A" } `
240- ) ;
241- }
242- progress . report ( { increment : 100 } ) ;
243- } ) ;
244-
245- token . onCancellationRequested ( ( ) => {
246- child . kill ( ) ;
233+ token . onCancellationRequested ( ( ) => {
234+ child . kill ( ) ;
235+ } ) ;
247236 } ) ;
248237 }
249238 ) ;
0 commit comments