Skip to content

Commit

Permalink
shorten include path length
Browse files Browse the repository at this point in the history
by using prefix option
  • Loading branch information
Jason2866 authored Jan 16, 2025
1 parent 44cb91b commit 6151a70
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion builder/frameworks/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from os.path import join

from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript
from platformio import fs
from platformio.package.version import pepver_to_semver
from platformio.project.config import ProjectConfig
from platformio.package.manager.tool import ToolPackageManager
Expand Down Expand Up @@ -195,11 +196,67 @@ def call_compile_libs():
if flag_custom_sdkconfig == True:
call_compile_libs()
flag_custom_sdkconfig = False



FRAMEWORK_SDK_DIR = fs.to_unix_path(
os.path.join(
FRAMEWORK_DIR,
"tools",
"esp32-arduino-libs",
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,
)

if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
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"):
env.AddBuildMiddleware(shorthen_includes)
if os.path.exists(join(FRAMEWORK_DIR, "tools", "platformio-build.py")):
PIO_BUILD = "platformio-build.py"
else:
Expand Down

3 comments on commit 6151a70

@uzi18
Copy link

@uzi18 uzi18 commented on 6151a70 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jason2866 nice!

@Jason2866
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uzi18 Not my work. Snipplet is from Valeros

@uzi18
Copy link

@uzi18 uzi18 commented on 6151a70 Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But idea is ok :)

Please sign in to comment.