Skip to content

Commit 109c537

Browse files
committed
Fixed handling of -include flag // Resolve platformio#4683
1 parent 25c7c60 commit 109c537

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PlatformIO Core 6
1818
6.1.9 (2023-??-??)
1919
~~~~~~~~~~~~~~~~~~
2020

21+
* 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>`_)
22+
2123
6.1.8 (2023-07-05)
2224
~~~~~~~~~~~~~~~~~~
2325

platformio/builder/tools/piobuild.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,13 @@ def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches
201201
for k in ("CPPPATH", "LIBPATH"):
202202
for i, p in enumerate(result.get(k, [])):
203203
p = env.subst(p)
204-
if os.path.isdir(p):
205-
result[k][i] = os.path.abspath(p)
204+
result[k][i] = p if os.path.isabs(p) else env.Dir(f"#{p}")
206205

207206
# fix relative path for "-include"
208207
for i, f in enumerate(result.get("CCFLAGS", [])):
209208
if isinstance(f, tuple) and f[0] == "-include":
210209
p = env.subst(f[1].get_path())
211-
if os.path.exists(p):
212-
result["CCFLAGS"][i] = (f[0], os.path.abspath(p))
210+
result["CCFLAGS"][i] = (f[0], p if os.path.isabs(p) else env.File(f"#{p}"))
213211

214212
return result
215213

tests/commands/test_run.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def test_generic_build(clirunner, validate_cliresult, tmpdir):
2222
("-D TEST_INT=13", "-DTEST_INT=13"),
2323
("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"),
2424
('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'),
25+
("-Iinclude", "-Iinclude"),
26+
("-include cpppath-include.h", "cpppath-include.h"),
2527
("-Iextra_inc", "-Iextra_inc"),
28+
("-Inon-existing-dir", "-Inon-existing-dir"),
2629
(
2730
"-include $PROJECT_DIR/lib/component/component-forced-include.h",
2831
"component-forced-include.h",
@@ -103,12 +106,22 @@ def post_prog_action(source, target, env):
103106
#error "I_AM_FORCED_COMPONENT_INCLUDE"
104107
#endif
105108
109+
#ifndef I_AM_FORCED_CPPPATH_INCLUDE
110+
#error "I_AM_FORCED_CPPPATH_INCLUDE"
111+
#endif
112+
106113
#ifdef COMMENTED_MACRO
107114
#error "COMMENTED_MACRO"
108115
#endif
109116
110117
int main() {
111118
}
119+
"""
120+
)
121+
122+
tmpdir.mkdir("include").join("cpppath-include.h").write(
123+
"""
124+
#define I_AM_FORCED_CPPPATH_INCLUDE
112125
"""
113126
)
114127
component_dir = tmpdir.mkdir("lib").mkdir("component")

0 commit comments

Comments
 (0)