fbt/ufbt: Ensure POSIX paths are passed to GDB on all platforms

https://github.com/flipperdevices/flipperzero-firmware/pull/3360/files
This commit is contained in:
MX 2024-03-22 11:27:02 +03:00
parent 760deb66c5
commit 6d9a2cc699
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
6 changed files with 56 additions and 33 deletions

View file

@ -229,7 +229,6 @@ firmware_debug = distenv.PhonyTarget(
source=firmware_env["FW_ELF"],
GDBOPTS="${GDBOPTS_BASE}",
GDBREMOTE="${OPENOCD_GDB_PIPE}",
FBT_FAP_DEBUG_ELF_ROOT=path_as_posix(firmware_env.subst("$FBT_FAP_DEBUG_ELF_ROOT")),
)
distenv.Depends(firmware_debug, firmware_flash)
@ -239,7 +238,6 @@ distenv.PhonyTarget(
source=firmware_env["FW_ELF"],
GDBOPTS="${GDBOPTS_BASE} ${GDBOPTS_BLACKMAGIC}",
GDBREMOTE="${BLACKMAGIC_ADDR}",
FBT_FAP_DEBUG_ELF_ROOT=path_as_posix(firmware_env.subst("$FBT_FAP_DEBUG_ELF_ROOT")),
)
# Debug alien elf

View file

@ -1,5 +1,9 @@
import os
import re
import subprocess
import sys
import webbrowser
from pathlib import Path, PurePosixPath
import SCons
from SCons.Errors import StopError
@ -80,6 +84,27 @@ def resolve_real_dir_node(node):
raise StopError(f"Can't find absolute path for {node.name} ({node})")
class PosixPathWrapper:
def __init__(self, pathobj):
self.pathobj = pathobj
@staticmethod
def fixup_separators(path):
if SCons.Platform.platform_default() == "win32":
return path.replace(os.path.sep, os.path.altsep)
return path
@staticmethod
def fix_path(path):
return str(PurePosixPath(Path(path).as_posix()))
def __call__(self, target, source, env, for_signature):
if for_signature:
return self.pathobj
return self.fix_path(env.subst(self.pathobj))
def path_as_posix(path):
if SCons.Platform.platform_default() == "win32":
return path.replace(os.path.sep, os.path.altsep)

View file

@ -18,7 +18,7 @@ def GetDevices(env):
def generate(env, **kw):
env.AddMethod(GetDevices)
env.SetDefault(
FBT_DEBUG_DIR="${FBT_SCRIPT_DIR}/debug",
FBT_DEBUG_DIR="${POSIXPATH('$FBT_SCRIPT_DIR')}/debug",
)
if (adapter_serial := env.subst("$SWD_TRANSPORT_SERIAL")) != "auto":
@ -36,11 +36,11 @@ def generate(env, **kw):
env.SetDefault(
OPENOCD_GDB_PIPE=[
"|openocd -c 'gdb_port pipe; log_output ${FBT_DEBUG_DIR}/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}"
"|openocd -c 'gdb_port pipe; log_output ${POSIXPATH('$FBT_DEBUG_DIR')}/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}"
],
GDBOPTS_BASE=[
"-ex",
"source ${FBT_DEBUG_DIR}/gdbinit",
"source ${POSIXPATH('$FBT_DEBUG_DIR')}/gdbinit",
"-ex",
"target extended-remote ${GDBREMOTE}",
],
@ -57,17 +57,17 @@ def generate(env, **kw):
],
GDBPYOPTS=[
"-ex",
"source ${FBT_DEBUG_DIR}/FreeRTOS/FreeRTOS.py",
"source ${POSIXPATH('$FBT_DEBUG_DIR')}/FreeRTOS/FreeRTOS.py",
"-ex",
"source ${FBT_DEBUG_DIR}/flipperapps.py",
"source ${POSIXPATH('$FBT_DEBUG_DIR')}/flipperapps.py",
"-ex",
"source ${FBT_DEBUG_DIR}/flipperversion.py",
"source ${POSIXPATH('$FBT_DEBUG_DIR')}/flipperversion.py",
"-ex",
"fap-set-debug-elf-root ${FBT_FAP_DEBUG_ELF_ROOT}",
"fap-set-debug-elf-root ${POSIXPATH('$FBT_FAP_DEBUG_ELF_ROOT')}",
"-ex",
"source ${FBT_DEBUG_DIR}/PyCortexMDebug/PyCortexMDebug.py",
"source ${POSIXPATH('$FBT_DEBUG_DIR')}/PyCortexMDebug/PyCortexMDebug.py",
"-ex",
"svd_load ${SVD_FILE}",
"svd_load ${POSIXPATH('$SVD_FILE')}",
"-ex",
"compare-sections",
"-ex",

View file

@ -6,7 +6,7 @@ import shutil
from fbt.sdk.cache import SdkCache
from fbt.sdk.collector import SdkCollector
from fbt.util import path_as_posix
from fbt.util import PosixPathWrapper
from SCons.Action import Action
from SCons.Builder import Builder
from SCons.Errors import UserError
@ -80,7 +80,7 @@ class SdkMeta:
vars,
target=Entry(self.MAP_FILE_SUBST),
)
return path_as_posix(expanded_vars)
return PosixPathWrapper.fixup_separators(expanded_vars)
class SdkTreeBuilder:
@ -149,7 +149,7 @@ class SdkTreeBuilder:
meta.save_to(self.target[0].path)
def build_sdk_file_path(self, orig_path: str) -> str:
return path_as_posix(
return PosixPathWrapper.fix_path(
posixpath.normpath(
posixpath.join(
self.SDK_DIR_SUBST,

View file

@ -47,7 +47,7 @@ from fbt.appmanifest import FlipperApplication, FlipperAppType
from fbt.sdk.cache import SdkCache
from fbt.util import (
FORWARDED_ENV_VARIABLES,
path_as_posix,
PosixPathWrapper,
resolve_real_dir_node,
single_quote,
tempfile_arg_esc_func,
@ -89,6 +89,7 @@ env = core_env.Clone(
("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}),
],
FBT_FAP_DEBUG_ELF_ROOT=ufbt_build_dir,
POSIXPATH=PosixPathWrapper,
TEMPFILE=TempFileMunge,
MAXLINELENGTH=2048,
PROGSUFFIX=".elf",
@ -128,7 +129,7 @@ dist_env = env.Clone(
"-c",
"transport select hla_swd",
"-f",
"${FBT_DEBUG_DIR}/stm32wbx.cfg",
"${POSIXPATH('$FBT_DEBUG_DIR')}/stm32wbx.cfg",
"-c",
"stm32wbx.cpu configure -rtos auto",
],
@ -161,7 +162,6 @@ firmware_debug = dist_env.PhonyTarget(
source=dist_env["FW_ELF"],
GDBOPTS="${GDBOPTS_BASE}",
GDBREMOTE="${OPENOCD_GDB_PIPE}",
FBT_FAP_DEBUG_ELF_ROOT=path_as_posix(dist_env.subst("$FBT_FAP_DEBUG_ELF_ROOT")),
)
dist_env.PhonyTarget(
@ -170,15 +170,14 @@ dist_env.PhonyTarget(
source=dist_env["FW_ELF"],
GDBOPTS="${GDBOPTS_BASE} ${GDBOPTS_BLACKMAGIC}",
GDBREMOTE="${BLACKMAGIC_ADDR}",
FBT_FAP_DEBUG_ELF_ROOT=path_as_posix(dist_env.subst("$FBT_FAP_DEBUG_ELF_ROOT")),
)
# Debug alien elf
debug_other_opts = [
"-ex",
"source ${FBT_DEBUG_DIR}/PyCortexMDebug/PyCortexMDebug.py",
"source ${POSIXPATH('FBT_DEBUG_DIR')}/PyCortexMDebug/PyCortexMDebug.py",
"-ex",
"source ${FBT_DEBUG_DIR}/flipperversion.py",
"source ${POSIXPATH('FBT_DEBUG_DIR')}/flipperversion.py",
"-ex",
"fw-version",
]
@ -371,10 +370,6 @@ dist_env.PhonyTarget(
# Prepare vscode environment
def _path_as_posix(path):
return pathlib.Path(path).as_posix()
vscode_dist = []
project_template_dir = dist_env["UFBT_SCRIPT_ROOT"].Dir("project_template")
for template_file in project_template_dir.Dir(".vscode").glob("*"):
@ -387,20 +382,24 @@ for template_file in project_template_dir.Dir(".vscode").glob("*"):
"@UFBT_TOOLCHAIN_ARM_TOOLCHAIN_DIR@": pathlib.Path(
dist_env.WhereIs("arm-none-eabi-gcc")
).parent.as_posix(),
"@UFBT_TOOLCHAIN_GCC@": _path_as_posix(
"@UFBT_TOOLCHAIN_GCC@": PosixPathWrapper.fix_path(
dist_env.WhereIs("arm-none-eabi-gcc")
),
"@UFBT_TOOLCHAIN_GDB_PY@": _path_as_posix(
"@UFBT_TOOLCHAIN_GDB_PY@": PosixPathWrapper.fix_path(
dist_env.WhereIs("arm-none-eabi-gdb-py3")
),
"@UFBT_TOOLCHAIN_OPENOCD@": _path_as_posix(dist_env.WhereIs("openocd")),
"@UFBT_APP_DIR@": _path_as_posix(original_app_dir.abspath),
"@UFBT_ROOT_DIR@": _path_as_posix(Dir("#").abspath),
"@UFBT_DEBUG_DIR@": _path_as_posix(dist_env["FBT_DEBUG_DIR"].abspath),
"@UFBT_DEBUG_ELF_DIR@": _path_as_posix(
"@UFBT_TOOLCHAIN_OPENOCD@": PosixPathWrapper.fix_path(
dist_env.WhereIs("openocd")
),
"@UFBT_APP_DIR@": PosixPathWrapper.fix_path(original_app_dir.abspath),
"@UFBT_ROOT_DIR@": PosixPathWrapper.fix_path(Dir("#").abspath),
"@UFBT_DEBUG_DIR@": dist_env.subst("FBT_DEBUG_DIR"),
"@UFBT_DEBUG_ELF_DIR@": PosixPathWrapper.fix_path(
dist_env["FBT_FAP_DEBUG_ELF_ROOT"].abspath
),
"@UFBT_FIRMWARE_ELF@": _path_as_posix(dist_env["FW_ELF"].abspath),
"@UFBT_FIRMWARE_ELF@": PosixPathWrapper.fix_path(
dist_env["FW_ELF"].abspath
),
},
)
)

View file

@ -3,6 +3,7 @@ import os
from fbt.util import (
FORWARDED_ENV_VARIABLES,
PosixPathWrapper,
resolve_real_dir_node,
single_quote,
tempfile_arg_esc_func,
@ -26,7 +27,6 @@ for env_value_name in variables_to_forward:
if environ_value := os.environ.get(env_value_name, None):
forward_os_env[env_value_name] = environ_value
coreenv = VAR_ENV.Clone(
tools=[
"fbt_tweaks",
@ -43,6 +43,7 @@ coreenv = VAR_ENV.Clone(
"ccache",
],
TEMPFILE=TempFileMunge,
POSIXPATH=PosixPathWrapper,
MAXLINELENGTH=2048,
PROGSUFFIX=".elf",
ENV=forward_os_env,