build(Vivid2DRenderer): enhance post-build script with directory exclusion logic
- Add DesignTime build protection by checking $(TargetName) macro - Implement exclusion list for directories to skip during copy operations - Recursively copy header files from subdirectories while excluding specified dirs - Introduce cleanup step to remove excluded directories from target path - Improve robustness of file copy and directory management in build process - Add logging for directory copy and cleanup actions for better traceability
This commit is contained in:
@@ -143,22 +143,47 @@
|
||||
<PostBuildEvent>
|
||||
<Command>setlocal enabledelayedexpansion
|
||||
|
||||
REM --- DesignTime 保护 ---
|
||||
REM 检查 $(TargetName) 宏,如果在 DesignTime 环境中可能为空,则退出。
|
||||
if "$(TargetName)"=="" (
|
||||
echo 警告:检测到可能为 DesignTime 构建,跳过后期生成事件。
|
||||
goto :EOF
|
||||
)
|
||||
|
||||
REM 定义目标路径变量,使用 VS 宏 $(TargetDir)
|
||||
REM $(TargetDir) 通常解析为 C:\...\Vivid2DRenderer\x64\Release\
|
||||
set TARGET_INCLUDE_DIR=$(TargetDir)include
|
||||
set PROJECT_DIR=$(ProjectDir)
|
||||
REM 定义需要排除的目录名列表
|
||||
set EXCLUDE_DIRS_LIST=.idea !DEST_DIR! x64
|
||||
|
||||
REM 确保目标目录存在
|
||||
mkdir %TARGET_INCLUDE_DIR%
|
||||
mkdir "%TARGET_INCLUDE_DIR%"
|
||||
|
||||
REM --- 复制操作 ---
|
||||
|
||||
REM 1. 复制项目根目录下的 .h 文件
|
||||
REM $(ProjectDir) 解析为 C:\...\Vivid2DRenderer\Vivid2DRenderer\
|
||||
xcopy "$(ProjectDir)*.h" "%TARGET_INCLUDE_DIR%" /Y /I
|
||||
xcopy "%PROJECT_DIR%*.h" "%TARGET_INCLUDE_DIR%" /Y /I
|
||||
|
||||
REM 2. 递归复制 'systems\' 文件夹下的所有 .h 文件
|
||||
REM /E 确保复制子目录结构
|
||||
xcopy "$(ProjectDir)systems\*.h" "%TARGET_INCLUDE_DIR%\systems" /E /Y /I
|
||||
REM 2. 遍历并复制子目录中的 .h 文件,跳过 EXCLUDE_DIRS_LIST 中的目录
|
||||
REM /D 仅遍历目录
|
||||
for /D %%d in ("%PROJECT_DIR%*") do (
|
||||
set DIR_NAME=%%~nxd
|
||||
|
||||
REM 检查当前目录名是否在排除列表中
|
||||
set IS_EXCLUDED=0
|
||||
for %%e in (%EXCLUDE_DIRS_LIST%) do (
|
||||
if /I "%%e"=="!DIR_NAME!" (
|
||||
set IS_EXCLUDED=1
|
||||
)
|
||||
)
|
||||
|
||||
REM 如果不在排除列表中,则递归复制该目录下的所有 .h 文件
|
||||
if !IS_EXCLUDED!==0 (
|
||||
echo 正在复制目录: %%~nxd
|
||||
REM /E 确保复制子目录结构,/I 确保目标是目录,避免复制文件失败
|
||||
xcopy "%%d\*.h" "%TARGET_INCLUDE_DIR%\%%~nxd" /E /Y /I
|
||||
)
|
||||
)
|
||||
|
||||
REM --- 排除操作 ---
|
||||
|
||||
@@ -167,7 +192,17 @@ for /R "%TARGET_INCLUDE_DIR%" %%f in (framework.h pch.h) do (
|
||||
del /Q "%%f"
|
||||
)
|
||||
|
||||
endlocal</Command>
|
||||
REM 4. 清理排除目录
|
||||
REM 强制删除目标路径中不应存在的文件夹
|
||||
for %%e in (%EXCLUDE_DIRS_LIST%) do (
|
||||
echo 正在清理排除目录: %TARGET_INCLUDE_DIR%\%%e
|
||||
REM /S 删除所有子目录和文件, /Q 安静模式, /F 强制删除只读文件
|
||||
rd /S /Q "%TARGET_INCLUDE_DIR%\%%e" 2>nul
|
||||
)
|
||||
|
||||
endlocal
|
||||
|
||||
:EOF</Command>
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Message>==== Package include ====</Message>
|
||||
|
||||
Reference in New Issue
Block a user