@@ -321,23 +321,72 @@ static const char*my_tempfile(const char*str, FILE**fout)
321
321
return pathbuf ;
322
322
}
323
323
324
+ #ifdef __MINGW32__
325
+ /* system() on Windows is a bit special. It removes quotes at the begining and
326
+ * the end. Even if the quoted part is just part of the command.
327
+ * E.g. `"cmd" "arg"` would be executed as `cmd" "arg`. This prevents us from
328
+ * properly handling paths with spaces in it.
329
+ */
330
+ static int run_cmd (const char * cmd )
331
+ {
332
+ char * cmd2 ;
333
+ size_t len ;
334
+ int rc ;
335
+
336
+ len = strlen (cmd ) + 13 ;
337
+ cmd2 = malloc (len );
338
+ rc = snprintf (cmd2 , len , "cmd /S /C \"%s\"" , cmd );
339
+ if (rc < 0 )
340
+ return rc ;
341
+
342
+ if (verbose_flag )
343
+ fprintf (stderr , "Executing: %s" , cmd2 );
344
+
345
+ STARTUPINFO si ;
346
+ PROCESS_INFORMATION pi ;
347
+
348
+ memset (& si , 0x00 , sizeof (si ));
349
+ si .cb = sizeof (si );
350
+ memset (& pi , 0x00 , sizeof (pi ));
351
+
352
+ if (!CreateProcess (NULL , cmd2 , NULL , NULL , FALSE, 0 , NULL , NULL , & si , & pi )) {
353
+ fprintf (stderr , "CreateProcess failed (%lu).\n" , GetLastError ());
354
+ return -1 ;
355
+ }
356
+
357
+ WaitForSingleObject (pi .hProcess , INFINITE );
358
+
359
+ CloseHandle (pi .hProcess );
360
+ CloseHandle (pi .hThread );
361
+
362
+ free (cmd2 );
363
+
364
+ return 0 ;
365
+ }
366
+ #else
367
+ static int run_cmd (const char * cmd )
368
+ {
369
+ return system (cmd );
370
+ }
371
+ #endif
372
+
324
373
static int t_version_only (void )
325
374
{
326
375
int rc ;
327
376
remove (source_path );
328
377
free (source_path );
329
378
330
379
fflush (0 );
331
- snprintf (tmp , sizeof tmp , "%s%civlpp -V" , ivlpp_dir , sep );
332
- rc = system (tmp );
380
+ snprintf (tmp , sizeof tmp , "\" %s%civlpp\" -V" , ivlpp_dir , sep );
381
+ rc = run_cmd (tmp );
333
382
if (rc != 0 ) {
334
383
fprintf (stderr , "Unable to get version from \"%s\"\n" , tmp );
335
384
}
336
385
337
386
fflush (0 );
338
- snprintf (tmp , sizeof tmp , "%s%civl -V -C\"%s\" -C\"%s\"" , base , sep ,
387
+ snprintf (tmp , sizeof tmp , "\" %s%civl\" -V -C\"%s\" -C\"%s\"" , base , sep ,
339
388
iconfig_path , iconfig_common_path );
340
- rc = system (tmp );
389
+ rc = run_cmd (tmp );
341
390
if (rc != 0 ) {
342
391
fprintf (stderr , "Unable to get version from \"%s\"\n" , tmp );
343
392
}
@@ -356,7 +405,7 @@ static int t_version_only(void)
356
405
357
406
static void build_preprocess_command (int e_flag )
358
407
{
359
- snprintf (tmp , sizeof tmp , "%s%civlpp%s%s%s -F\"%s\" -f\"%s\" -p\"%s\"%s" ,
408
+ snprintf (tmp , sizeof tmp , "\" %s%civlpp\" %s%s%s -F\"%s\" -f\"%s\" -p\"%s\"%s" ,
360
409
ivlpp_dir , sep ,
361
410
verbose_flag ? " -v" : "" ,
362
411
e_flag ? "" : " -L" ,
@@ -388,7 +437,7 @@ static int t_preprocess_only(void)
388
437
if (verbose_flag )
389
438
printf ("preprocess: %s\n" , cmd );
390
439
391
- rc = system (cmd );
440
+ rc = run_cmd (cmd );
392
441
remove (source_path );
393
442
free (source_path );
394
443
@@ -442,7 +491,7 @@ static int t_compile(void)
442
491
#endif
443
492
444
493
/* Build the ivl command. */
445
- snprintf (tmp , sizeof tmp , "%s%civl" , base , sep );
494
+ snprintf (tmp , sizeof tmp , "\" %s%civl\" " , base , sep );
446
495
rc = strlen (tmp );
447
496
cmd = realloc (cmd , ncmd + rc + 1 );
448
497
strcpy (cmd + ncmd , tmp );
@@ -489,7 +538,7 @@ static int t_compile(void)
489
538
printf ("translate: %s\n" , cmd );
490
539
491
540
492
- rc = system (cmd );
541
+ rc = run_cmd (cmd );
493
542
if ( ! getenv ("IVERILOG_ICONFIG" )) {
494
543
remove (source_path );
495
544
free (source_path );
@@ -1420,7 +1469,7 @@ int main(int argc, char **argv)
1420
1469
1421
1470
if (vhdlpp_work == 0 )
1422
1471
vhdlpp_work = "ivl_vhdl_work" ;
1423
- fprintf (defines_file , "vhdlpp:%s%cvhdlpp\n" , vhdlpp_dir , sep );
1472
+ fprintf (defines_file , "vhdlpp:\" %s%cvhdlpp\" \n" , vhdlpp_dir , sep );
1424
1473
fprintf (defines_file , "vhdlpp-work:%s\n" , vhdlpp_work );
1425
1474
for (unsigned idx = 0 ; idx < vhdlpp_libdir_cnt ; idx += 1 )
1426
1475
fprintf (defines_file , "vhdlpp-libdir:%s\n" , vhdlpp_libdir [idx ]);
@@ -1483,7 +1532,7 @@ int main(int argc, char **argv)
1483
1532
/* Write the preprocessor command needed to preprocess a
1484
1533
single file. This may be used to preprocess library
1485
1534
files. */
1486
- fprintf (iconfig_file , "ivlpp:%s%civlpp %s -L -F\"%s\" -P\"%s\"\n" ,
1535
+ fprintf (iconfig_file , "ivlpp:\" %s%civlpp\" %s -L -F\"%s\" -P\"%s\"\n" ,
1487
1536
ivlpp_dir , sep ,
1488
1537
strchr (warning_flags , 'r' ) ? "-Wredef-all" :
1489
1538
strchr (warning_flags , 'R' ) ? "-Wredef-chg" : "" ,
0 commit comments