Skip to content

Commit

Permalink
Better handling of complex macros from CMake model
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Sep 5, 2024
1 parent e9dbab3 commit c73bbc1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ def _normalize_define(define_string):
define_string = define_string.strip()
if "=" in define_string:
define, value = define_string.split("=", maxsplit=1)
if '"' in value and not value.startswith("\\"):
# Escape only raw values
if any(char in value for char in (' ', '<', '>')):
value = f'"{value}"'
elif any(char in value for char in ('"', '\'')):
value = value.replace('"', '\\"')
return (define, value)
return define_string
Expand All @@ -342,8 +343,11 @@ def _normalize_define(define_string):
]

for f in compile_group.get("compileCommandFragments", []):
if f.get("fragment", "").startswith("-D"):
result.append(_normalize_define(f["fragment"][2:]))
fragment = f.get("fragment", "").strip()
if fragment.startswith('"'):
fragment = fragment.strip('"')
if fragment.startswith("-D"):
result.append(_normalize_define(fragment[2:]))

return result

Expand Down Expand Up @@ -429,8 +433,8 @@ def _extract_flags(config):
for cg in config["compileGroups"]:
flags[cg["language"]] = []
for ccfragment in cg["compileCommandFragments"]:
fragment = ccfragment.get("fragment", "")
if not fragment.strip() or fragment.startswith("-D"):
fragment = ccfragment.get("fragment", "").strip("\" ")
if not fragment or fragment.startswith("-D"):
continue
flags[cg["language"]].extend(
click.parser.split_arg_string(fragment.strip())
Expand Down Expand Up @@ -715,7 +719,7 @@ def prepare_build_envs(config, default_env, debug_allowed=True):
build_env = default_env.Clone()
build_env.SetOption("implicit_cache", 1)
for cc in compile_commands:
build_flags = cc.get("fragment")
build_flags = cc.get("fragment", "").strip("\" ")
if not build_flags.startswith("-D"):
if build_flags.startswith("-include") and ".." in build_flags:
source_index = cg.get("sourceIndexes")[0]
Expand Down

0 comments on commit c73bbc1

Please sign in to comment.