Skip to content

Commit 019ee09

Browse files
committed
Propagate Arduino build flags to global scope for mixed IDF/Arduino projects
Resolve platformio#848
1 parent d92c478 commit 019ee09

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

builder/frameworks/espidf.py

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,6 @@ def _get_installed_pip_packages():
12461246
project_flags = get_app_flags(project_config, default_config)
12471247
link_args = extract_link_args(elf_config)
12481248
app_includes = get_app_includes(elf_config)
1249-
project_lib_includes = get_project_lib_includes(env)
12501249

12511250
#
12521251
# Compile bootloader
@@ -1301,32 +1300,6 @@ def _skip_prj_source_files(node):
13011300

13021301
env.AddBuildMiddleware(_skip_prj_source_files)
13031302

1304-
# Project files should be compiled only when a special
1305-
# option is enabled when running 'test' command
1306-
if "__test" not in COMMAND_LINE_TARGETS or env.GetProjectOption(
1307-
"test_build_project_src"
1308-
):
1309-
project_env = env.Clone()
1310-
if project_target_name != "__idf_main":
1311-
# Manually add dependencies to CPPPATH since ESP-IDF build system doesn't generate
1312-
# this info if the folder with sources is not named 'main'
1313-
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
1314-
project_env.AppendUnique(CPPPATH=app_includes["plain_includes"])
1315-
1316-
# Add include dirs from PlatformIO build system to project CPPPATH so
1317-
# they're visible to PIOBUILDFILES
1318-
project_env.Append(
1319-
CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"] + project_lib_includes
1320-
)
1321-
1322-
env.Append(
1323-
PIOBUILDFILES=compile_source_files(
1324-
target_configs.get(project_target_name),
1325-
project_env,
1326-
project_env.subst("$PROJECT_DIR"),
1327-
)
1328-
)
1329-
13301303
#
13311304
# Generate partition table
13321305
#
@@ -1387,6 +1360,52 @@ def _skip_prj_source_files(node):
13871360
],
13881361
)
13891362

1363+
#
1364+
# Propagate Arduino defines to the main build environment
1365+
#
1366+
1367+
if "arduino" in env.subst("$PIOFRAMEWORK"):
1368+
arduino_config_name = list(
1369+
filter(
1370+
lambda config_name: config_name.startswith(
1371+
"__idf_framework-arduinoespressif32"
1372+
),
1373+
target_configs,
1374+
)
1375+
)[0]
1376+
env.AppendUnique(
1377+
CPPDEFINES=extract_defines(
1378+
target_configs.get(arduino_config_name, {}).get("compileGroups", [])[0]
1379+
)
1380+
)
1381+
1382+
# Project files should be compiled only when a special
1383+
# option is enabled when running 'test' command
1384+
if "__test" not in COMMAND_LINE_TARGETS or env.GetProjectOption(
1385+
"test_build_project_src"
1386+
):
1387+
project_env = env.Clone()
1388+
if project_target_name != "__idf_main":
1389+
# Manually add dependencies to CPPPATH since ESP-IDF build system doesn't generate
1390+
# this info if the folder with sources is not named 'main'
1391+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
1392+
project_env.AppendUnique(CPPPATH=app_includes["plain_includes"])
1393+
1394+
# Add include dirs from PlatformIO build system to project CPPPATH so
1395+
# they're visible to PIOBUILDFILES
1396+
project_env.AppendUnique(
1397+
CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"]
1398+
+ get_project_lib_includes(env)
1399+
)
1400+
1401+
env.Append(
1402+
PIOBUILDFILES=compile_source_files(
1403+
target_configs.get(project_target_name),
1404+
project_env,
1405+
project_env.subst("$PROJECT_DIR"),
1406+
)
1407+
)
1408+
13901409
#
13911410
# Generate mbedtls bundle
13921411
#

0 commit comments

Comments
 (0)