fix(bt): Normalize source paths for log compression pattern matching

This commit is contained in:
luoxu
2026-04-23 22:11:16 +08:00
committed by BOT
parent 09fac633a3
commit b02139becb
2 changed files with 15 additions and 3 deletions

View File

@@ -118,6 +118,12 @@ if(LOG_COMPRESSED_MODULE)
string(REPLACE ";" "|" MODULE_CODE_PATH "${LOG_COMPRESSED_MODULE_CODE_PATH}")
set(MATCH_PATTERN "(${MODULE_CODE_PATH}).+\\.c")
foreach(src ${srcs})
# Normalize absolute paths to relative paths (relative to CODE_BASE_PATH)
# so that pattern matching works and .compressed_srcs/ has a clean layout
if(IS_ABSOLUTE "${src}")
get_filename_component(src "${src}" ABSOLUTE)
file(RELATIVE_PATH src "${CODE_BASE_PATH}" "${src}")
endif()
if(src MATCHES ${MATCH_PATTERN})
set(dest "${LOG_COMPRESSED_SRCS_DIR}/${src}")
file(WRITE "${dest}" "")

View File

@@ -663,9 +663,15 @@ class LogCompressor:
compressed_file_cnt = 0
total_cnt = 0
for src in srcs:
if pattern.match(src):
src_path = self.code_base_path / src
dest_path = self.bt_compressed_srcs_path / src
# Convert absolute paths to relative (to code_base_path) for pattern matching
src_for_match = src
try:
src_for_match = str(Path(src).relative_to(self.code_base_path))
except ValueError:
pass # Not under code_base_path, keep as-is
if pattern.match(src_for_match):
src_path = self.code_base_path / src_for_match
dest_path = self.bt_compressed_srcs_path / src_for_match
temp_path = f'{dest_path}.tmp'
total_cnt += 1
# Skip if already processed