Skip to content

Commit c73bbc1

Browse files
committed
Better handling of complex macros from CMake model
1 parent e9dbab3 commit c73bbc1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

builder/frameworks/espidf.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ def _normalize_define(define_string):
330330
define_string = define_string.strip()
331331
if "=" in define_string:
332332
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 ('"', '\'')):
335336
value = value.replace('"', '\\"')
336337
return (define, value)
337338
return define_string
@@ -342,8 +343,11 @@ def _normalize_define(define_string):
342343
]
343344

344345
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:]))
347351

348352
return result
349353

@@ -429,8 +433,8 @@ def _extract_flags(config):
429433
for cg in config["compileGroups"]:
430434
flags[cg["language"]] = []
431435
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"):
434438
continue
435439
flags[cg["language"]].extend(
436440
click.parser.split_arg_string(fragment.strip())
@@ -715,7 +719,7 @@ def prepare_build_envs(config, default_env, debug_allowed=True):
715719
build_env = default_env.Clone()
716720
build_env.SetOption("implicit_cache", 1)
717721
for cc in compile_commands:
718-
build_flags = cc.get("fragment")
722+
build_flags = cc.get("fragment", "").strip("\" ")
719723
if not build_flags.startswith("-D"):
720724
if build_flags.startswith("-include") and ".." in build_flags:
721725
source_index = cg.get("sourceIndexes")[0]

0 commit comments

Comments
 (0)