Skip to content

Commit af56c49

Browse files
EvlersRbb666
authored andcommitted
[build] 解决构建文件污染lib以及bsp目录的问题
1 parent 4d743d6 commit af56c49

File tree

1 file changed

+88
-44
lines changed

1 file changed

+88
-44
lines changed

projects/Edgi_Talk_M33_S_Template/Sconstruct

Lines changed: 88 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import uuid
1111
# Project paths
1212
PROJECT_ROOT = Dir('.').abspath
1313
SDK_ROOT = os.path.normpath(os.path.join(PROJECT_ROOT, '..', '..'))
14+
BUILD_DIR = 'build'
1415

1516
# =============================================================================
1617
# Toolchain configuration
@@ -145,55 +146,76 @@ CPPDEFINES = [
145146
# =============================================================================
146147
# Library path detection (support both local and external libraries)
147148
# =============================================================================
149+
def _posix(path):
150+
return path.replace('\\', '/')
151+
148152
# Check if libraries exist locally or need to use external path
149-
if os.path.exists(os.path.join(PROJECT_ROOT, 'libraries')):
150-
LIBRARIES_PATH = PROJECT_ROOT + '/libraries'
151-
LIBRARIES_PREFIX = ''
153+
local_libraries_dir = os.path.join(PROJECT_ROOT, 'libraries')
154+
if os.path.exists(local_libraries_dir):
155+
libraries_src = PROJECT_ROOT + '/libraries'
156+
libraries_variant = os.path.join(BUILD_DIR, 'libraries_local')
152157
else:
153-
LIBRARIES_PATH = SDK_ROOT + '/libraries'
154-
LIBRARIES_PREFIX = '../../libraries/'
158+
libraries_src = os.path.relpath(os.path.join(SDK_ROOT, 'libraries'), PROJECT_ROOT)
159+
libraries_variant = os.path.join(BUILD_DIR, 'libraries_ext')
160+
libraries_src_abs = os.path.normpath(os.path.join(PROJECT_ROOT, libraries_src))
161+
libraries_variant_abs = os.path.normpath(os.path.join(PROJECT_ROOT, libraries_variant))
162+
libraries_real_path = libraries_src_abs
163+
libraries_variant_rel = libraries_variant
164+
VariantDir(libraries_variant, libraries_src, duplicate=0)
165+
libraries_real_path = _posix(libraries_real_path)
166+
libraries_variant = _posix(libraries_variant_rel)
167+
LIBRARIES_PREFIX = libraries_variant + '/'
155168

156169
# Check if libs exist locally or need to use external path
157-
if os.path.exists(os.path.join(PROJECT_ROOT, 'libs')):
158-
LIBS_PATH = PROJECT_ROOT + '/libs'
159-
LIBS_PREFIX = ''
170+
local_libs_dir = os.path.join(PROJECT_ROOT, 'libs')
171+
if os.path.exists(local_libs_dir):
172+
libs_src = 'libs'
173+
libs_variant = os.path.join(BUILD_DIR, 'libs_local')
160174
else:
161-
LIBS_PATH = os.path.normpath(os.path.join(PROJECT_ROOT, '..', 'libs'))
162-
LIBS_PREFIX = '../libs/'
175+
libs_src = os.path.relpath(os.path.join(PROJECT_ROOT, '..', 'libs'), PROJECT_ROOT)
176+
libs_variant = os.path.join(BUILD_DIR, 'libs_ext')
177+
libs_src_abs = os.path.normpath(os.path.join(PROJECT_ROOT, libs_src))
178+
libs_variant_abs = os.path.normpath(os.path.join(PROJECT_ROOT, libs_variant))
179+
libs_real_path = libs_src_abs
180+
libs_variant_rel = libs_variant
181+
VariantDir(libs_variant, libs_src, duplicate=0)
182+
libs_real_path = _posix(libs_real_path)
183+
libs_variant = _posix(libs_variant_rel)
184+
LIBS_PREFIX = libs_variant + '/'
163185

164186
# =============================================================================
165187
# Include paths
166188
# =============================================================================
167189
CPPPATH = [
168190
PROJECT_ROOT + '/applications',
169191
PROJECT_ROOT + '/config',
170-
LIBRARIES_PATH + '/components/retarget-io/include',
171-
LIBRARIES_PATH + '/components/mtb-ipc/include',
172-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS/vsi/gcnano',
173-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS/vsi/dcnano8000',
174-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS',
175-
LIBRARIES_PATH + '/components/mtb-srf/include/COMPONENT_NON_SECURE_DEVICE/COMPONENT_MW_MTB_IPC',
176-
LIBRARIES_PATH + '/components/mtb-srf/include/COMPONENT_NON_SECURE_DEVICE',
177-
LIBRARIES_PATH + '/components/mtb-srf/include',
178-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/nnkernel/COMPONENT_CM33/include',
179-
LIBRARIES_PATH + '/components/async-transfer/include',
180-
LIBRARIES_PATH + '/components/Infineon_cmsis-latest/Core/Include',
181-
LIBRARIES_PATH + '/components/Infineon_cmsis-latest/Core/Include/m-profile',
182-
LIBRARIES_PATH + '/components/Infineon_core-lib-latest/include',
183-
LIBRARIES_PATH + '/components/Infineon_retarget-io-latest',
184-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/device-utils/syspm/include',
185-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/hal/include',
186-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/devices/include',
187-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/devices/include/ip',
188-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/drivers/include',
189-
LIBRARIES_PATH + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/ethernet/include',
190-
LIBRARIES_PATH + '/components/serial-memory/include',
191-
LIBRARIES_PATH + '/components/se-rt-services-utils',
192-
LIBS_PATH + '/TARGET_APP_KIT_PSE84_EVAL_EPC2',
193-
LIBS_PATH + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/bluetooth',
194-
LIBS_PATH + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/config',
195-
LIBS_PATH + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource',
196-
LIBS_PATH + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/COMPONENT_CM33/COMPONENT_SECURE_DEVICE',
192+
libraries_real_path + '/components/retarget-io/include',
193+
libraries_real_path + '/components/mtb-ipc/include',
194+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS/vsi/gcnano',
195+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS/vsi/dcnano8000',
196+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/COMPONENT_GFXSS',
197+
libraries_real_path + '/components/mtb-srf/include/COMPONENT_NON_SECURE_DEVICE/COMPONENT_MW_MTB_IPC',
198+
libraries_real_path + '/components/mtb-srf/include/COMPONENT_NON_SECURE_DEVICE',
199+
libraries_real_path + '/components/mtb-srf/include',
200+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/nnkernel/COMPONENT_CM33/include',
201+
libraries_real_path + '/components/async-transfer/include',
202+
libraries_real_path + '/components/Infineon_cmsis-latest/Core/Include',
203+
libraries_real_path + '/components/Infineon_cmsis-latest/Core/Include/m-profile',
204+
libraries_real_path + '/components/Infineon_core-lib-latest/include',
205+
libraries_real_path + '/components/Infineon_retarget-io-latest',
206+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/device-utils/syspm/include',
207+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/hal/include',
208+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/devices/include',
209+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/devices/include/ip',
210+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/drivers/include',
211+
libraries_real_path + '/components/mtb-device-support-pse8xxgp/pdl/drivers/third_party/ethernet/include',
212+
libraries_real_path + '/components/serial-memory/include',
213+
libraries_real_path + '/components/se-rt-services-utils',
214+
libs_real_path + '/TARGET_APP_KIT_PSE84_EVAL_EPC2',
215+
libs_real_path + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/bluetooth',
216+
libs_real_path + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/config',
217+
libs_real_path + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource',
218+
libs_real_path + '/TARGET_APP_KIT_PSE84_EVAL_EPC2/COMPONENT_CM33/COMPONENT_SECURE_DEVICE',
197219
]
198220

199221
# =============================================================================
@@ -351,7 +373,6 @@ static_obj.add_action('.S', as_builder.action)
351373
# Build target
352374
# =============================================================================
353375
# Create build directory
354-
BUILD_DIR = 'build'
355376
VariantDir(BUILD_DIR, '.', duplicate=0)
356377

357378
# Separate local sources and external sources
@@ -361,15 +382,38 @@ external_src = []
361382

362383
for s in SRC:
363384
src_str = str(s)
364-
# Check if it's an external path (either relative ../ or absolute path outside project)
365-
if src_str.startswith('../') or src_str.startswith('..\\'):
385+
src_abs = os.path.abspath(src_str)
386+
try:
387+
rel_to_proj = os.path.relpath(src_abs, PROJECT_ROOT).replace('\\', '/')
388+
except ValueError:
366389
external_src.append(src_str)
367-
elif os.path.isabs(src_str) and not src_str.startswith(os.path.abspath('.')):
368-
# Absolute path outside project - use as-is
390+
continue
391+
392+
src_abs_norm = os.path.normcase(src_abs)
393+
libs_src_norm = os.path.normcase(libs_src_abs)
394+
libraries_src_norm = os.path.normcase(libraries_src_abs)
395+
396+
if src_abs_norm.startswith(libs_src_norm):
397+
rel_in_libs = os.path.relpath(src_abs, libs_src_abs).replace('\\', '/')
398+
local_src.append(LIBS_PREFIX + rel_in_libs)
399+
continue
400+
401+
if src_abs_norm.startswith(libraries_src_norm):
402+
rel_in_libraries = os.path.relpath(src_abs, libraries_src_abs).replace('\\', '/')
403+
local_src.append(LIBRARIES_PREFIX + rel_in_libraries)
404+
continue
405+
406+
build_prefix = BUILD_DIR + '/'
407+
408+
# Path escapes project root → treat as external
409+
if rel_to_proj.startswith('../'):
369410
external_src.append(src_str)
411+
elif rel_to_proj.startswith(build_prefix):
412+
# Already under build directory
413+
local_src.append(rel_to_proj)
370414
else:
371-
# Local source - add build dir prefix
372-
local_src.append(BUILD_DIR + '/' + src_str)
415+
# Located inside project tree: mirror into build directory
416+
local_src.append(build_prefix + rel_to_proj)
373417

374418
# Combine: local sources (with build dir prefix) + external sources (as-is)
375419
build_src = local_src + external_src

0 commit comments

Comments
 (0)