diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 6c0c06142..20c732d12 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -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 @@ -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 @@ -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()) @@ -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]