Fixed handling of `-include` flag // Resolve #4683

This commit is contained in:
Ivan Kravets
2023-07-06 11:40:30 +03:00
parent 25c7c60f0d
commit 109c537d86
3 changed files with 17 additions and 4 deletions

View File

@ -18,6 +18,8 @@ PlatformIO Core 6
6.1.9 (2023-??-??) 6.1.9 (2023-??-??)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
* Rectified a regression bug that occurred when the ``-include`` flag was passed via the `build_flags <https://docs.platformio.org/en/latest/projectconf/sections/env/options/build/build_flags.html>`__ option as a relative path and subsequently expanded (`issue #4683 <https://github.com/platformio/platformio-core/issues/4683>`_)
6.1.8 (2023-07-05) 6.1.8 (2023-07-05)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

View File

@ -201,15 +201,13 @@ def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches
for k in ("CPPPATH", "LIBPATH"): for k in ("CPPPATH", "LIBPATH"):
for i, p in enumerate(result.get(k, [])): for i, p in enumerate(result.get(k, [])):
p = env.subst(p) p = env.subst(p)
if os.path.isdir(p): result[k][i] = p if os.path.isabs(p) else env.Dir(f"#{p}")
result[k][i] = os.path.abspath(p)
# fix relative path for "-include" # fix relative path for "-include"
for i, f in enumerate(result.get("CCFLAGS", [])): for i, f in enumerate(result.get("CCFLAGS", [])):
if isinstance(f, tuple) and f[0] == "-include": if isinstance(f, tuple) and f[0] == "-include":
p = env.subst(f[1].get_path()) p = env.subst(f[1].get_path())
if os.path.exists(p): result["CCFLAGS"][i] = (f[0], p if os.path.isabs(p) else env.File(f"#{p}"))
result["CCFLAGS"][i] = (f[0], os.path.abspath(p))
return result return result

View File

@ -22,7 +22,10 @@ def test_generic_build(clirunner, validate_cliresult, tmpdir):
("-D TEST_INT=13", "-DTEST_INT=13"), ("-D TEST_INT=13", "-DTEST_INT=13"),
("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"), ("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"),
('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'), ('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'),
("-Iinclude", "-Iinclude"),
("-include cpppath-include.h", "cpppath-include.h"),
("-Iextra_inc", "-Iextra_inc"), ("-Iextra_inc", "-Iextra_inc"),
("-Inon-existing-dir", "-Inon-existing-dir"),
( (
"-include $PROJECT_DIR/lib/component/component-forced-include.h", "-include $PROJECT_DIR/lib/component/component-forced-include.h",
"component-forced-include.h", "component-forced-include.h",
@ -103,12 +106,22 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
#error "I_AM_FORCED_COMPONENT_INCLUDE" #error "I_AM_FORCED_COMPONENT_INCLUDE"
#endif #endif
#ifndef I_AM_FORCED_CPPPATH_INCLUDE
#error "I_AM_FORCED_CPPPATH_INCLUDE"
#endif
#ifdef COMMENTED_MACRO #ifdef COMMENTED_MACRO
#error "COMMENTED_MACRO" #error "COMMENTED_MACRO"
#endif #endif
int main() { int main() {
} }
"""
)
tmpdir.mkdir("include").join("cpppath-include.h").write(
"""
#define I_AM_FORCED_CPPPATH_INCLUDE
""" """
) )
component_dir = tmpdir.mkdir("lib").mkdir("component") component_dir = tmpdir.mkdir("lib").mkdir("component")