### P3-15f-2 PMI/step_import 解耦 - pmi_types.h 新增轻量 PMI DTO(不 include brep 头);assembly_feature.h 结构迁出、旧符号源兼容; - step_import.h 不再 include assembly_feature.h(移除 kernel 公开头→业务头反向依赖);test_pmi_decouple 4 用例 + 760 tests 绿; ### P3-15f-3a assembly 核心迁移前置 - mesh_to_brep_model 抽到 include/vde/brep/mesh_to_brep.h + src/brep/mesh_to_brep.cpp(行为不变),9 调用点更新; step_import.cpp 不再依赖 assembly.h; - assembly_services.h 桥:SECTION_ASSEMBLY codec(未注册显式 runtime_error、字节布局不变)+ C API vde_assembly_* 委托(未注册空返回); - 26 测试可执行文件/564 用例绿;kernel-only OFF 构建 0 error + 13/327 用例绿;§9.3.3 迁移边界表; ### P3-15g sheet metal 模块拆分 - vde_sheetmetal(3 TU/~3.7k 行迁出)、VDE_BUILD_SHEETMETAL/DEPS/聚合、规范头+兼容转发头(kernel SDK EXCLUDE); - 包 vde-sheetmetal + consumer SHEETMETAL_CONSUMER_PASS faces=6 k=0.3800 ba=2.1677 table=8 flange_ok=1 unfold_ok=1; - 默认全量 ctest 7550/7550;OFF 构建 0 undefined;sheetmetal+守卫 59/59;docs §10/architecture/roadmap; ### 工程 - 版本 1.0.76(CMake/version.h/test_version/README/docs index/module-manual);模块目标 28; - 全量构建 0 error(498 targets);全量 ctest 7463/7463 PASS(0 failed,25 skipped,245.17s)。
401 lines
15 KiB
CMake
401 lines
15 KiB
CMake
# ═══════════════════════════════════════════════════════════════════════════
|
||
# VDE 微内核 P3-10:kernel 聚合 / kernel SDK 边界守卫(CMake script mode)
|
||
# cmake -DSOURCE_DIR=<repo-root> -P cmake/check_kernel_boundary.cmake
|
||
# 检查:kernel 聚合 allowlist / kernel SDK 安装模块与 export allowlist /
|
||
# 内核 target 源文件不得 include 业务模块头 / kernel SDK 头文件排除
|
||
# (include/vde 业务头目录 + 转发头) / vde::app 不得含内核几何模块。
|
||
# 退出码:0 PASS;违规 message(FATAL_ERROR)。
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
cmake_minimum_required(VERSION 3.16)
|
||
if(NOT DEFINED SOURCE_DIR)
|
||
message(FATAL_ERROR "[kernel-boundary] 缺少 -DSOURCE_DIR=<repo-root>")
|
||
endif()
|
||
set(_root_cmake "${SOURCE_DIR}/CMakeLists.txt")
|
||
set(_src_cmake "${SOURCE_DIR}/src/CMakeLists.txt")
|
||
if(NOT EXISTS "${_root_cmake}" OR NOT EXISTS "${_src_cmake}")
|
||
message(FATAL_ERROR "[kernel-boundary] 找不到根/src CMakeLists")
|
||
endif()
|
||
string(ASCII 9 _TAB)
|
||
string(ASCII 13 _CR)
|
||
string(ASCII 34 _Q)
|
||
set(_kernel_allow foundation plugin core compute curves mesh spatial boolean collision sdf brep platform)
|
||
set(_kernel_geometry foundation plugin core compute curves mesh spatial boolean collision sdf brep)
|
||
set(_biz_modules io cae cam drafting pdm mechanism render ui assembly sheetmetal sketch expression param event infra license)
|
||
set(_kernel_header_dirs foundation core compute curves mesh spatial boolean collision sdf brep plugin capi)
|
||
# 既有内核源文件的“编译期业务头耦合”(无 link 依赖):登记为技术债,需后续拆
|
||
# 分到官方模块;新增耦合必须显式登记 allowlist(守卫会失败)。
|
||
# P3-15c:structural_profiles.cpp / geometric_snap.cpp(含依赖的 snap_ext.cpp)已迁入
|
||
# vde_pdm / vde_ui,内核源列表不再包含这些 TU,allowlist 清零。
|
||
set(_soft_include_allow "")
|
||
set(_soft_findings "")
|
||
set(_biz_header_markers "vde/cae/" "vde/fluid/" "vde/feature/" "vde/param/"
|
||
"vde_drafting/" "vde_pdm/" "vde_ui/" "vde_cam/" "vde_render/"
|
||
"vde_mechanism/" "vde_license/" "vde_event/" "vde_infra/" "vde_expression/"
|
||
"vde_assembly/" "vde_sheetmetal/")
|
||
file(STRINGS "${_root_cmake}" _root_lines)
|
||
file(STRINGS "${_src_cmake}" _src_lines)
|
||
file(READ "${_root_cmake}" _root_text)
|
||
set(_violations "")
|
||
|
||
function(_kb_tokens text out)
|
||
set(_t "${text}")
|
||
string(REPLACE " " ";" _t "${_t}")
|
||
string(REPLACE "${_TAB}" ";" _t "${_t}")
|
||
string(REPLACE "${_CR}" ";" _t "${_t}")
|
||
set(_clean "")
|
||
foreach(_tok IN LISTS _t)
|
||
if(NOT _tok STREQUAL "")
|
||
list(APPEND _clean "${_tok}")
|
||
endif()
|
||
endforeach()
|
||
set(${out} "${_clean}" PARENT_SCOPE)
|
||
endfunction()
|
||
|
||
function(_kb_lstrip text out)
|
||
set(_s "${text}")
|
||
string(LENGTH "${_s}" _len)
|
||
set(_idx 0)
|
||
while(_idx LESS _len)
|
||
string(SUBSTRING "${_s}" ${_idx} 1 _ch)
|
||
if(NOT _ch STREQUAL " ")
|
||
break()
|
||
endif()
|
||
math(EXPR _idx "${_idx} + 1")
|
||
endwhile()
|
||
string(SUBSTRING "${_s}" ${_idx} -1 _s)
|
||
set(${out} "${_s}" PARENT_SCOPE)
|
||
endfunction()
|
||
|
||
function(_kb_parse_list lines marker out)
|
||
set(_acc "")
|
||
set(_in FALSE)
|
||
set(_seen FALSE)
|
||
foreach(_line IN LISTS ${lines})
|
||
_kb_lstrip("${_line}" _lstripped)
|
||
if(NOT _in)
|
||
string(FIND "${_lstripped}" "${marker}" _pos)
|
||
if(_pos EQUAL 0)
|
||
set(_in TRUE)
|
||
set(_seen TRUE)
|
||
string(LENGTH "${marker}" _mlen)
|
||
string(SUBSTRING "${_lstripped}" ${_mlen} -1 _acc)
|
||
endif()
|
||
else()
|
||
string(APPEND _acc " " "${_line}")
|
||
endif()
|
||
if(_in)
|
||
string(FIND "${_acc}" ")" _q)
|
||
if(NOT _q EQUAL -1)
|
||
string(SUBSTRING "${_acc}" 0 ${_q} _acc)
|
||
set(_in FALSE)
|
||
endif()
|
||
endif()
|
||
endforeach()
|
||
if(_seen)
|
||
_kb_tokens("${_acc}" _toks)
|
||
set(${out} "${_toks}" PARENT_SCOPE)
|
||
else()
|
||
set(${out} "" PARENT_SCOPE)
|
||
endif()
|
||
endfunction()
|
||
|
||
function(_kb_is_source_token tok out)
|
||
set(_hit FALSE)
|
||
string(LENGTH "${tok}" _l)
|
||
if(_l GREATER 3)
|
||
math(EXPR _p "${_l} - 4")
|
||
string(SUBSTRING "${tok}" ${_p} 4 _s)
|
||
if(_s STREQUAL ".cpp")
|
||
set(_hit TRUE)
|
||
endif()
|
||
endif()
|
||
if(NOT _hit AND _l GREATER 1)
|
||
math(EXPR _p2 "${_l} - 2")
|
||
string(SUBSTRING "${tok}" ${_p2} 2 _s2)
|
||
if(_s2 STREQUAL ".c")
|
||
set(_hit TRUE)
|
||
endif()
|
||
endif()
|
||
set(${out} ${_hit} PARENT_SCOPE)
|
||
endfunction()
|
||
|
||
function(_kb_biz_header_of line out)
|
||
set(_hit "")
|
||
foreach(_m IN LISTS _biz_header_markers)
|
||
string(FIND "${line}" "${_m}" _p)
|
||
if(NOT _p EQUAL -1)
|
||
set(_hit "${_m}")
|
||
break()
|
||
endif()
|
||
endforeach()
|
||
set(${out} "${_hit}" PARENT_SCOPE)
|
||
endfunction()
|
||
|
||
# ── 1) vde::kernel 聚合 allowlist ──
|
||
_kb_parse_list(_src_lines "set(_vde_kernel_modules" _kernel_agg)
|
||
if(NOT _kernel_agg)
|
||
list(APPEND _violations "未解析到 set(_vde_kernel_modules ...)")
|
||
endif()
|
||
foreach(_m IN LISTS _kernel_agg)
|
||
if(_m IN_LIST _biz_modules)
|
||
list(APPEND _violations "vde::kernel 聚合夹带业务模块 '${_m}'")
|
||
elseif(NOT _m IN_LIST _kernel_allow)
|
||
list(APPEND _violations "vde::kernel 聚合包含非内核模块 '${_m}'")
|
||
endif()
|
||
endforeach()
|
||
|
||
# ── 2) kernel SDK 安装模块 allowlist ──
|
||
_kb_parse_list(_root_lines "set(_vde_kernel_install_modules" _kernel_install)
|
||
if(NOT _kernel_install)
|
||
list(APPEND _violations "未解析到 set(_vde_kernel_install_modules ...)")
|
||
endif()
|
||
foreach(_m IN LISTS _kernel_install)
|
||
if(NOT _m IN_LIST _kernel_allow)
|
||
list(APPEND _violations "kernel SDK 安装列表包含非内核模块 '${_m}'")
|
||
endif()
|
||
endforeach()
|
||
|
||
# ── 3) kernel SDK export target 显式追加 allowlist ──
|
||
set(_export_checked 0)
|
||
foreach(_line IN LISTS _root_lines)
|
||
string(FIND "${_line}" "list(APPEND _vde_kernel_export_targets" _p)
|
||
if(_p EQUAL -1)
|
||
continue()
|
||
endif()
|
||
string(LENGTH "list(APPEND _vde_kernel_export_targets" _plen)
|
||
string(SUBSTRING "${_line}" ${_plen} -1 _rest)
|
||
_kb_tokens("${_rest}" _toks)
|
||
foreach(_tok IN LISTS _toks)
|
||
string(REPLACE ")" "" _tok "${_tok}")
|
||
string(FIND "${_tok}" [=[${]=] _dyn)
|
||
if(NOT _dyn EQUAL -1)
|
||
continue()
|
||
endif()
|
||
string(FIND "${_tok}" "vde_" _vp)
|
||
if(_vp EQUAL 0)
|
||
string(LENGTH "vde_" _vlen)
|
||
string(SUBSTRING "${_tok}" ${_vlen} -1 _mod)
|
||
math(EXPR _export_checked "${_export_checked} + 1")
|
||
if(NOT (_mod IN_LIST _kernel_allow OR _mod STREQUAL "kernel_capi"))
|
||
list(APPEND _violations "kernel SDK export 追加非内核 target '${_tok}'")
|
||
endif()
|
||
endif()
|
||
endforeach()
|
||
endforeach()
|
||
|
||
# ── 3b) 内核 target 链接依赖不得含业务模块 ──
|
||
set(_link_checked 0)
|
||
set(_in_tll FALSE)
|
||
set(_tll_mod "")
|
||
set(_tll_acc "")
|
||
foreach(_line IN LISTS _src_lines)
|
||
if(_in_tll)
|
||
string(APPEND _tll_acc " " "${_line}")
|
||
string(FIND "${_line}" ")" _q)
|
||
if(NOT _q EQUAL -1)
|
||
set(_in_tll FALSE)
|
||
_kb_tokens("${_tll_acc}" _toks)
|
||
foreach(_tok IN LISTS _toks)
|
||
string(FIND "${_tok}" "vde_" _vp)
|
||
if(NOT _vp EQUAL 0)
|
||
continue()
|
||
endif()
|
||
string(REPLACE "${_Q}" "" _tok "${_tok}")
|
||
string(LENGTH "vde_" _vlen)
|
||
string(SUBSTRING "${_tok}" ${_vlen} -1 _dep)
|
||
math(EXPR _link_checked "${_link_checked} + 1")
|
||
if(_dep IN_LIST _biz_modules)
|
||
list(APPEND _violations "内核 target ${_tll_mod} 链接业务模块 '${_dep}'")
|
||
endif()
|
||
endforeach()
|
||
set(_tll_acc "")
|
||
endif()
|
||
else()
|
||
_kb_lstrip("${_line}" _stripped)
|
||
string(FIND "${_stripped}" "target_link_libraries(vde_" _p)
|
||
if(NOT _p EQUAL 0)
|
||
continue()
|
||
endif()
|
||
string(LENGTH "target_link_libraries(vde_" _plen)
|
||
string(SUBSTRING "${_stripped}" ${_plen} -1 _rest)
|
||
string(FIND "${_rest}" " " _sp)
|
||
if(_sp LESS 0)
|
||
set(_mod "${_rest}")
|
||
else()
|
||
string(SUBSTRING "${_rest}" 0 ${_sp} _mod)
|
||
endif()
|
||
if(NOT _mod IN_LIST _kernel_geometry)
|
||
continue()
|
||
endif()
|
||
set(_tll_mod "${_mod}")
|
||
set(_tll_acc "${_rest}")
|
||
string(FIND "${_rest}" ")" _q)
|
||
if(NOT _q EQUAL -1)
|
||
set(_tll_acc "")
|
||
else()
|
||
set(_in_tll TRUE)
|
||
endif()
|
||
endif()
|
||
endforeach()
|
||
|
||
# ── 4) 内核 target 源文件不得 include 业务模块头 ──
|
||
set(_src_scanned 0)
|
||
set(_in_block FALSE)
|
||
set(_block_mod "")
|
||
set(_block_acc "")
|
||
set(_block_files "")
|
||
foreach(_line IN LISTS _src_lines)
|
||
if(_in_block)
|
||
string(APPEND _block_acc " " "${_line}")
|
||
string(FIND "${_line}" ")" _q)
|
||
if(NOT _q EQUAL -1)
|
||
set(_in_block FALSE)
|
||
_kb_tokens("${_block_acc}" _toks)
|
||
foreach(_tok IN LISTS _toks)
|
||
_kb_is_source_token("${_tok}" _issrc)
|
||
if(_issrc)
|
||
string(REPLACE "${_Q}" "" _tok "${_tok}")
|
||
list(APPEND _block_files "${_tok}")
|
||
endif()
|
||
endforeach()
|
||
foreach(_rel IN LISTS _block_files)
|
||
set(_full "${SOURCE_DIR}/src/${_rel}")
|
||
if(EXISTS "${_full}")
|
||
math(EXPR _src_scanned "${_src_scanned} + 1")
|
||
file(STRINGS "${_full}" _flines)
|
||
foreach(_fl IN LISTS _flines)
|
||
_kb_lstrip("${_fl}" _fs)
|
||
string(FIND "${_fs}" "#include" _inc)
|
||
if(NOT _inc EQUAL 0)
|
||
continue()
|
||
endif()
|
||
_kb_biz_header_of("${_fs}" _hitm)
|
||
if(NOT _hitm STREQUAL "")
|
||
set(_soft "${_rel}:${_hitm}")
|
||
if(_soft IN_LIST _soft_include_allow)
|
||
list(APPEND _soft_findings "${_soft}")
|
||
else()
|
||
list(APPEND _violations "内核 target ${_block_mod} 源文件 ${_rel} include 业务头 ${_hitm}(新增耦合,需拆分或登记 allowlist)")
|
||
endif()
|
||
endif()
|
||
endforeach()
|
||
endif()
|
||
endforeach()
|
||
set(_block_files "")
|
||
set(_block_acc "")
|
||
endif()
|
||
else()
|
||
_kb_lstrip("${_line}" _stripped)
|
||
string(FIND "${_stripped}" "add_library(vde_" _p)
|
||
if(NOT _p EQUAL 0)
|
||
continue()
|
||
endif()
|
||
string(LENGTH "add_library(vde_" _plen)
|
||
string(SUBSTRING "${_stripped}" ${_plen} -1 _rest)
|
||
string(FIND "${_rest}" " " _sp)
|
||
if(_sp LESS 0)
|
||
continue()
|
||
endif()
|
||
string(SUBSTRING "${_rest}" 0 ${_sp} _mod)
|
||
if(NOT _mod IN_LIST _kernel_geometry)
|
||
continue()
|
||
endif()
|
||
set(_block_mod "${_mod}")
|
||
set(_block_acc "${_rest}")
|
||
set(_block_files "")
|
||
string(FIND "${_rest}" ")" _q)
|
||
if(NOT _q EQUAL -1)
|
||
set(_block_acc "")
|
||
else()
|
||
set(_in_block TRUE)
|
||
endif()
|
||
endif()
|
||
endforeach()
|
||
if(_in_block)
|
||
list(APPEND _violations "内核 target 源列表解析未闭合(内部错误)")
|
||
endif()
|
||
|
||
# ── 5) 内核 SDK 头文件边界 ──
|
||
file(GLOB _vde_entries RELATIVE "${SOURCE_DIR}/include/vde" "${SOURCE_DIR}/include/vde/*")
|
||
set(_business_header_dirs "")
|
||
set(_forwarder_headers "")
|
||
foreach(_entry IN LISTS _vde_entries)
|
||
set(_dir "${SOURCE_DIR}/include/vde/${_entry}")
|
||
if(NOT IS_DIRECTORY "${_dir}")
|
||
continue()
|
||
endif()
|
||
if(NOT _entry IN_LIST _kernel_header_dirs)
|
||
list(APPEND _business_header_dirs "${_entry}")
|
||
continue()
|
||
endif()
|
||
file(GLOB_RECURSE _hdr_files "${_dir}/*.h" "${_dir}/*.hpp")
|
||
foreach(_hf IN LISTS _hdr_files)
|
||
file(STRINGS "${_hf}" _hf_lines)
|
||
foreach(_fl IN LISTS _hf_lines)
|
||
_kb_lstrip("${_fl}" _fs)
|
||
string(FIND "${_fs}" "#include" _inc)
|
||
if(NOT _inc EQUAL 0)
|
||
continue()
|
||
endif()
|
||
_kb_biz_header_of("${_fs}" _hitm)
|
||
if(NOT _hitm STREQUAL "")
|
||
get_filename_component(_hname "${_hf}" NAME)
|
||
list(APPEND _forwarder_headers "${_hname}")
|
||
break()
|
||
endif()
|
||
endforeach()
|
||
endforeach()
|
||
endforeach()
|
||
list(REMOVE_DUPLICATES _business_header_dirs)
|
||
list(REMOVE_DUPLICATES _forwarder_headers)
|
||
foreach(_d IN LISTS _business_header_dirs)
|
||
set(_need "PATTERN ${_Q}${_d}${_Q} EXCLUDE")
|
||
string(FIND "${_root_text}" "${_need}" _p)
|
||
if(_p EQUAL -1)
|
||
list(APPEND _violations "kernel SDK 头安装未排除业务头目录 include/vde/${_d}/(缺 ${_need})")
|
||
endif()
|
||
endforeach()
|
||
foreach(_h IN LISTS _forwarder_headers)
|
||
set(_need "PATTERN ${_Q}${_h}${_Q} EXCLUDE")
|
||
string(FIND "${_root_text}" "${_need}" _p)
|
||
if(_p EQUAL -1)
|
||
list(APPEND _violations "kernel SDK 头安装未排除转发头 ${_h}(缺 ${_need})")
|
||
endif()
|
||
endforeach()
|
||
set(_vde_biz_headers_literal "install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/vde_")
|
||
string(FIND "${_root_text}" "${_vde_biz_headers_literal}" _p)
|
||
if(NOT _p EQUAL -1)
|
||
list(APPEND _violations "kernel SDK 头安装疑似整体包含 include/vde_* 业务模块头目录")
|
||
endif()
|
||
|
||
# ── 6) vde::app 聚合不得包含内核几何模块 ──
|
||
_kb_parse_list(_src_lines "set(_vde_app_modules" _app_agg)
|
||
if(NOT _app_agg)
|
||
list(APPEND _violations "未解析到 set(_vde_app_modules ...)")
|
||
endif()
|
||
foreach(_m IN LISTS _app_agg)
|
||
if(_m IN_LIST _kernel_geometry)
|
||
list(APPEND _violations "vde::app 聚合包含内核几何模块 '${_m}'")
|
||
endif()
|
||
endforeach()
|
||
|
||
# ── 结果 ──
|
||
list(LENGTH _kernel_agg _kagg_n)
|
||
list(LENGTH _kernel_install _kinstall_n)
|
||
list(LENGTH _business_header_dirs _bizdir_n)
|
||
list(LENGTH _forwarder_headers _fwd_n)
|
||
list(LENGTH _violations _vn)
|
||
message(STATUS "[kernel-boundary] kernel 聚合(@${_kagg_n}): ${_kernel_agg}")
|
||
message(STATUS "[kernel-boundary] kernel SDK 安装模块(@${_kinstall_n}): ${_kernel_install}")
|
||
message(STATUS "[kernel-boundary] kernel SDK export 显式追加检查: ${_export_checked} 条")
|
||
message(STATUS "[kernel-boundary] 内核 target 源文件扫描: ${_src_scanned} 个(既有业务头编译期耦合: ${_soft_findings})")
|
||
message(STATUS "[kernel-boundary] 内核 target 链接依赖检查: ${_link_checked} 条")
|
||
message(STATUS "[kernel-boundary] include/vde 业务头目录(@${_bizdir_n}, 需 EXCLUDE): ${_business_header_dirs}")
|
||
message(STATUS "[kernel-boundary] 内核头转发头(@${_fwd_n}, 需 EXCLUDE): ${_forwarder_headers}")
|
||
message(STATUS "[kernel-boundary] vde::app 聚合(@${_app_agg}) 未含内核几何模块")
|
||
if(_vn GREATER 0)
|
||
string(REPLACE ";" "\n - " _vtext "${_violations}")
|
||
message(FATAL_ERROR "[kernel-boundary] 发现 ${_vn} 处内核边界违规:\n - ${_vtext}")
|
||
endif()
|
||
message(STATUS "[kernel-boundary] PASS:kernel 聚合/kernel SDK/头文件边界符合几何内核定位")
|