@@ -330,8 +330,9 @@ def _normalize_define(define_string):
330
330
define_string = define_string .strip ()
331
331
if "=" in define_string :
332
332
define , value = define_string .split ("=" , maxsplit = 1 )
333
- if '"' in value and not value .startswith ("\\ " ):
334
- # Escape only raw values
333
+ if any (char in value for char in (' ' , '<' , '>' )):
334
+ value = f'"{ value } "'
335
+ elif any (char in value for char in ('"' , '\' ' )):
335
336
value = value .replace ('"' , '\\ "' )
336
337
return (define , value )
337
338
return define_string
@@ -342,8 +343,11 @@ def _normalize_define(define_string):
342
343
]
343
344
344
345
for f in compile_group .get ("compileCommandFragments" , []):
345
- if f .get ("fragment" , "" ).startswith ("-D" ):
346
- result .append (_normalize_define (f ["fragment" ][2 :]))
346
+ fragment = f .get ("fragment" , "" ).strip ()
347
+ if fragment .startswith ('"' ):
348
+ fragment = fragment .strip ('"' )
349
+ if fragment .startswith ("-D" ):
350
+ result .append (_normalize_define (fragment [2 :]))
347
351
348
352
return result
349
353
@@ -429,8 +433,8 @@ def _extract_flags(config):
429
433
for cg in config ["compileGroups" ]:
430
434
flags [cg ["language" ]] = []
431
435
for ccfragment in cg ["compileCommandFragments" ]:
432
- fragment = ccfragment .get ("fragment" , "" )
433
- if not fragment . strip () or fragment .startswith ("-D" ):
436
+ fragment = ccfragment .get ("fragment" , "" ). strip ( " \" " )
437
+ if not fragment or fragment .startswith ("-D" ):
434
438
continue
435
439
flags [cg ["language" ]].extend (
436
440
click .parser .split_arg_string (fragment .strip ())
@@ -715,7 +719,7 @@ def prepare_build_envs(config, default_env, debug_allowed=True):
715
719
build_env = default_env .Clone ()
716
720
build_env .SetOption ("implicit_cache" , 1 )
717
721
for cc in compile_commands :
718
- build_flags = cc .get ("fragment" )
722
+ build_flags = cc .get ("fragment" , "" ). strip ( " \" " )
719
723
if not build_flags .startswith ("-D" ):
720
724
if build_flags .startswith ("-include" ) and ".." in build_flags :
721
725
source_index = cg .get ("sourceIndexes" )[0 ]
0 commit comments