shorten include path by using prefix
This commit is contained in:
@@ -30,6 +30,7 @@ import shutil
|
|||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript
|
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript
|
||||||
|
from platformio import fs
|
||||||
from platformio.package.version import pepver_to_semver
|
from platformio.package.version import pepver_to_semver
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
from platformio.package.manager.tool import ToolPackageManager
|
from platformio.package.manager.tool import ToolPackageManager
|
||||||
@@ -55,6 +56,8 @@ extra_flags = (''.join([element for element in board.get("build.extra_flags", ""
|
|||||||
framework_reinstall = False
|
framework_reinstall = False
|
||||||
flag_any_custom_sdkconfig = False
|
flag_any_custom_sdkconfig = False
|
||||||
|
|
||||||
|
FRAMEWORK_LIB_DIR = platform.get_package_dir("framework-arduinoespressif32-lib")
|
||||||
|
|
||||||
SConscript("_embed_files.py", exports="env")
|
SConscript("_embed_files.py", exports="env")
|
||||||
|
|
||||||
flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32-libs"),"sdkconfig"))
|
flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32-libs"),"sdkconfig"))
|
||||||
@@ -171,6 +174,59 @@ def check_reinstall_frwrk():
|
|||||||
framework_reinstall = True
|
framework_reinstall = True
|
||||||
return framework_reinstall
|
return framework_reinstall
|
||||||
|
|
||||||
|
|
||||||
|
FRAMEWORK_SDK_DIR = fs.to_unix_path(
|
||||||
|
os.path.join(
|
||||||
|
FRAMEWORK_LIB_DIR,
|
||||||
|
mcu,
|
||||||
|
"include",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
IS_INTEGRATION_DUMP = env.IsIntegrationDump()
|
||||||
|
|
||||||
|
|
||||||
|
def is_framework_subfolder(potential_subfolder):
|
||||||
|
if not os.path.isabs(potential_subfolder):
|
||||||
|
return False
|
||||||
|
if (
|
||||||
|
os.path.splitdrive(FRAMEWORK_SDK_DIR)[0]
|
||||||
|
!= os.path.splitdrive(potential_subfolder)[0]
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
return os.path.commonpath([FRAMEWORK_SDK_DIR]) == os.path.commonpath(
|
||||||
|
[FRAMEWORK_SDK_DIR, potential_subfolder]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def shorthen_includes(env, node):
|
||||||
|
if IS_INTEGRATION_DUMP:
|
||||||
|
# Don't shorten include paths for IDE integrations
|
||||||
|
return node
|
||||||
|
|
||||||
|
includes = [fs.to_unix_path(inc) for inc in env.get("CPPPATH", [])]
|
||||||
|
shortened_includes = []
|
||||||
|
generic_includes = []
|
||||||
|
for inc in includes:
|
||||||
|
if is_framework_subfolder(inc):
|
||||||
|
shortened_includes.append(
|
||||||
|
"-iwithprefix/"
|
||||||
|
+ fs.to_unix_path(os.path.relpath(inc, FRAMEWORK_SDK_DIR))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
generic_includes.append(inc)
|
||||||
|
|
||||||
|
return env.Object(
|
||||||
|
node,
|
||||||
|
CPPPATH=generic_includes,
|
||||||
|
CCFLAGS=env["CCFLAGS"]
|
||||||
|
+ ["-iprefix", FRAMEWORK_SDK_DIR]
|
||||||
|
+ shortened_includes,
|
||||||
|
ASFLAGS=env["ASFLAGS"]
|
||||||
|
+ ["-iprefix", FRAMEWORK_SDK_DIR]
|
||||||
|
+ shortened_includes,
|
||||||
|
)
|
||||||
|
|
||||||
def call_compile_libs():
|
def call_compile_libs():
|
||||||
if mcu == "esp32c2":
|
if mcu == "esp32c2":
|
||||||
ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu)
|
ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu)
|
||||||
@@ -192,6 +248,7 @@ if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
|
|||||||
call_compile_libs()
|
call_compile_libs()
|
||||||
|
|
||||||
if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"):
|
if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"):
|
||||||
|
env.AddBuildMiddleware(shorthen_includes)
|
||||||
if os.path.exists(join(platform.get_package_dir(
|
if os.path.exists(join(platform.get_package_dir(
|
||||||
"framework-arduinoespressif32"), "tools", "platformio-build.py")):
|
"framework-arduinoespressif32"), "tools", "platformio-build.py")):
|
||||||
PIO_BUILD = "platformio-build.py"
|
PIO_BUILD = "platformio-build.py"
|
||||||
|
|||||||
Reference in New Issue
Block a user