From 01ab1fa4c08d0f5f854b84d6098a111760ebbe1b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 3 Jul 2023 18:37:57 +0300 Subject: [PATCH] Resolved a critical issue related to the usage of the ``-include`` flag // Resolve #4682 --- HISTORY.rst | 1 + docs | 2 +- platformio/builder/tools/piobuild.py | 5 ++++- tests/commands/test_run.py | 13 +++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8c180293..b36ed218 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -25,6 +25,7 @@ PlatformIO Core 6 * Refactored |UNITTESTING| engine to resolve compiler warnings with "-Wpedantic" option (`pull #4671 `_) * Eliminated erroneous warning regarding the use of obsolete PlatformIO Core when downgrading to the stable version (`issue #4664 `_) * Updated the `pio project metadata `__ command to return C/C++ flags as parsed Unix shell arguments when dumping project build metadata +* Resolved a critical issue related to the usage of the ``-include`` flag within the `build_flags `__ option, specifically when employing dynamic variables (`issue #4682 `_) * Removed PlatformIO IDE for Atom from the documentation as `Atom has been deprecated `__ 6.1.7 (2023-05-08) diff --git a/docs b/docs index 50bbe8ac..daa389f6 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 50bbe8ac61de55ba31d153d2000fc04ee5dd09a4 +Subproject commit daa389f68b9e3505f8e6aceda5d9362ba0cb5e54 diff --git a/platformio/builder/tools/piobuild.py b/platformio/builder/tools/piobuild.py index ba194eb0..1646dc95 100644 --- a/platformio/builder/tools/piobuild.py +++ b/platformio/builder/tools/piobuild.py @@ -200,13 +200,16 @@ def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches # fix relative CPPPATH & LIBPATH 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) # fix relative path for "-include" for i, f in enumerate(result.get("CCFLAGS", [])): if isinstance(f, tuple) and f[0] == "-include": - result["CCFLAGS"][i] = (f[0], env.File(os.path.abspath(f[1].get_path()))) + p = env.subst(f[1].get_path()) + if os.path.exists(p): + result["CCFLAGS"][i] = (f[0], os.path.abspath(p)) return result diff --git a/tests/commands/test_run.py b/tests/commands/test_run.py index cb9e3d85..de13a5a8 100644 --- a/tests/commands/test_run.py +++ b/tests/commands/test_run.py @@ -23,6 +23,10 @@ def test_generic_build(clirunner, validate_cliresult, tmpdir): ("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"), ('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'), ("-Iextra_inc", "-Iextra_inc"), + ( + "-include $PROJECT_DIR/lib/component/component-forced-include.h", + "component-forced-include.h", + ), ] tmpdir.join("platformio.ini").write( @@ -95,6 +99,10 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO") #error "POST_SCRIPT_MACRO" #endif +#ifndef I_AM_FORCED_COMPONENT_INCLUDE +#error "I_AM_FORCED_COMPONENT_INCLUDE" +#endif + #ifdef COMMENTED_MACRO #error "COMMENTED_MACRO" #endif @@ -124,6 +132,11 @@ void dummy(void); void dummy(void ) {}; """ ) + component_dir.join("component-forced-include.h").write( + """ +#define I_AM_FORCED_COMPONENT_INCLUDE + """ + ) result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"]) validate_cliresult(result)