From 109c537d86bba3b57bc3e15a1e09613f27af3be6 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 6 Jul 2023 11:40:30 +0300 Subject: [PATCH] Fixed handling of ``-include`` flag // Resolve #4683 --- HISTORY.rst | 2 ++ platformio/builder/tools/piobuild.py | 6 ++---- tests/commands/test_run.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c60293e4..63f54eec 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,8 @@ PlatformIO Core 6 6.1.9 (2023-??-??) ~~~~~~~~~~~~~~~~~~ +* Rectified a regression bug that occurred when the ``-include`` flag was passed via the `build_flags `__ option as a relative path and subsequently expanded (`issue #4683 `_) + 6.1.8 (2023-07-05) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piobuild.py b/platformio/builder/tools/piobuild.py index 1646dc95..23d0c6ff 100644 --- a/platformio/builder/tools/piobuild.py +++ b/platformio/builder/tools/piobuild.py @@ -201,15 +201,13 @@ def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches for k in ("CPPPATH", "LIBPATH"): for i, p in enumerate(result.get(k, [])): p = env.subst(p) - if os.path.isdir(p): - result[k][i] = os.path.abspath(p) + result[k][i] = p if os.path.isabs(p) else env.Dir(f"#{p}") # fix relative path for "-include" for i, f in enumerate(result.get("CCFLAGS", [])): if isinstance(f, tuple) and f[0] == "-include": p = env.subst(f[1].get_path()) - if os.path.exists(p): - result["CCFLAGS"][i] = (f[0], os.path.abspath(p)) + result["CCFLAGS"][i] = (f[0], p if os.path.isabs(p) else env.File(f"#{p}")) return result diff --git a/tests/commands/test_run.py b/tests/commands/test_run.py index de13a5a8..573ac9ef 100644 --- a/tests/commands/test_run.py +++ b/tests/commands/test_run.py @@ -22,7 +22,10 @@ def test_generic_build(clirunner, validate_cliresult, tmpdir): ("-D TEST_INT=13", "-DTEST_INT=13"), ("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"), ('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'), + ("-Iinclude", "-Iinclude"), + ("-include cpppath-include.h", "cpppath-include.h"), ("-Iextra_inc", "-Iextra_inc"), + ("-Inon-existing-dir", "-Inon-existing-dir"), ( "-include $PROJECT_DIR/lib/component/component-forced-include.h", "component-forced-include.h", @@ -103,12 +106,22 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO") #error "I_AM_FORCED_COMPONENT_INCLUDE" #endif +#ifndef I_AM_FORCED_CPPPATH_INCLUDE +#error "I_AM_FORCED_CPPPATH_INCLUDE" +#endif + #ifdef COMMENTED_MACRO #error "COMMENTED_MACRO" #endif int main() { } +""" + ) + + tmpdir.mkdir("include").join("cpppath-include.h").write( + """ +#define I_AM_FORCED_CPPPATH_INCLUDE """ ) component_dir = tmpdir.mkdir("lib").mkdir("component")