This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 83b1a728c3c cmake(tasking): strip absolute paths from __FILE__ macro
83b1a728c3c is described below

commit 83b1a728c3c488bb6596a291cff0e24e54350a02
Author: zhaoyiming5 <[email protected]>
AuthorDate: Mon Apr 27 19:41:58 2026 +0800

    cmake(tasking): strip absolute paths from __FILE__ macro
    
    TASKING cctc has no -fmacro-prefix-map equivalent. Override
    CMAKE_C_COMPILE_OBJECT to cd into the code root and sed-strip
    the absolute prefix before invoking the compiler, so __FILE__
    embeds short relative paths instead of full absolute paths.
    
    Guard the path-stripping logic behind CONFIG_OUTPUT_STRIP_PATHS
    so it can be toggled via Kconfig, consistent with the GCC
    toolchain in cmake/nuttx_toolchain.cmake.
    
    This reduces .rodata size and enables reproducible builds
    across different working directories.
    
    Signed-off-by: zhaoyiming5 <[email protected]>
---
 Kconfig                              |  2 +-
 arch/tricore/src/cmake/tasking.cmake | 39 ++++++++++++++++++++++++++++++------
 cmake/nuttx_toolchain.cmake          |  4 +++-
 3 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/Kconfig b/Kconfig
index 521b7d88faa..678313acf5e 100644
--- a/Kconfig
+++ b/Kconfig
@@ -484,7 +484,7 @@ endif # DFU_BINARY
 config OUTPUT_STRIP_PATHS
        bool "Strip absolute paths from binaries"
        default y
-       depends on ARCH_TOOLCHAIN_GNU
+       depends on ARCH_TOOLCHAIN_GNU || ARCH_TOOLCHAIN_TASKING
        ---help---
                Cmake build provide absolute paths to compile files. If __FILE__
                macros are used in the source code(ASSERT), the binary will 
contain
diff --git a/arch/tricore/src/cmake/tasking.cmake 
b/arch/tricore/src/cmake/tasking.cmake
index 094440122cc..9f19b8c5c12 100644
--- a/arch/tricore/src/cmake/tasking.cmake
+++ b/arch/tricore/src/cmake/tasking.cmake
@@ -44,12 +44,39 @@ set(ASMEXT
     asm
     CACHE INTERNAL "")
 
-set(CMAKE_C_COMPILE_OBJECT
-    "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> --create <SOURCE> -o 
<OBJECT>"
-)
-set(CMAKE_CXX_COMPILE_OBJECT
-    "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> --create <SOURCE> -o 
<OBJECT>"
-)
+if(CONFIG_OUTPUT_STRIP_PATHS)
+  # TASKING cctc has no -fmacro-prefix-map. Convert absolute source paths to
+  # relative paths by cd-ing to code root before compilation, so __FILE__ 
embeds
+  # short relative paths instead of full absolute paths.
+  #
+  # CMake prepends CMAKE_C_COMPILER_LAUNCHER before the entire compile object
+  # template, which breaks shell commands that must run before the compiler.
+  # Save the launcher and place it manually after the cd.
+  #
+  # CMake's built-in Tasking support injects "--dep-file=<DEP_FILE>" with a
+  # build-dir-relative path; prefix it with the binary dir so it stays valid
+  # after the cd (absolute dep-file paths are left untouched).
+  get_filename_component(_TASKING_CODE_ROOT "${CMAKE_SOURCE_DIR}" DIRECTORY)
+
+  set(_TASKING_C_LAUNCHER "${CMAKE_C_COMPILER_LAUNCHER}")
+  set(_TASKING_CXX_LAUNCHER "${CMAKE_CXX_COMPILER_LAUNCHER}")
+  set(CMAKE_C_COMPILER_LAUNCHER "")
+  set(CMAKE_CXX_COMPILER_LAUNCHER "")
+
+  set(CMAKE_C_COMPILE_OBJECT
+      "_CMD='${_TASKING_C_LAUNCHER} <CMAKE_C_COMPILER> <DEFINES> <INCLUDES> 
<FLAGS> --create <SOURCE>' && cd ${_TASKING_CODE_ROOT} && _CMD=$$(echo 
\"$$_CMD\" | sed -e 's|${_TASKING_CODE_ROOT}/||g' -e 
's|--dep-file=\\([^/]\\)|--dep-file=${CMAKE_BINARY_DIR}/\\1|') && eval \"$$_CMD 
-o ${CMAKE_BINARY_DIR}/<OBJECT>\""
+  )
+  set(CMAKE_CXX_COMPILE_OBJECT
+      "_CMD='${_TASKING_CXX_LAUNCHER} <CMAKE_CXX_COMPILER> <DEFINES> 
<INCLUDES> <FLAGS> --create <SOURCE>' && cd ${_TASKING_CODE_ROOT} && 
_CMD=$$(echo \"$$_CMD\" | sed -e 's|${_TASKING_CODE_ROOT}/||g' -e 
's|--dep-file=\\([^/]\\)|--dep-file=${CMAKE_BINARY_DIR}/\\1|') && eval \"$$_CMD 
-o ${CMAKE_BINARY_DIR}/<OBJECT>\""
+  )
+else()
+  set(CMAKE_C_COMPILE_OBJECT
+      "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> --create <SOURCE> -o 
<OBJECT>"
+  )
+  set(CMAKE_CXX_COMPILE_OBJECT
+      "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> --create <SOURCE> -o 
<OBJECT>"
+  )
+endif()
 
 if(CMAKE_GENERATOR MATCHES "Ninja")
   set(CMAKE_C_RESPONSE_FILE_FLAG "-f ${CMAKE_BINARY_DIR}/")
diff --git a/cmake/nuttx_toolchain.cmake b/cmake/nuttx_toolchain.cmake
index 3974846cc04..2a83ae677d3 100644
--- a/cmake/nuttx_toolchain.cmake
+++ b/cmake/nuttx_toolchain.cmake
@@ -37,7 +37,9 @@ endif()
 # failure logs more deterministic and most importantly makes builds more
 # deterministic. Debuggers usually have a path mapping feature to ensure the
 # files are still found.
-if((NOT MSVC) AND (NOT CONFIG_ARCH_TOOLCHAIN_GHS))
+if((NOT MSVC)
+   AND (NOT CONFIG_ARCH_TOOLCHAIN_GHS)
+   AND (NOT CONFIG_ARCH_TOOLCHAIN_TASKING))
   if(CONFIG_OUTPUT_STRIP_PATHS)
     add_compile_options(-fmacro-prefix-map=${NUTTX_DIR}=)
     add_compile_options(-fmacro-prefix-map=${NUTTX_APPS_DIR}=)

Reply via email to