Files
VSAG_SENTRY_SIM_27RMUL/tools/gen_compdb.sh
T
mzx f7412ec369 初始化:RMUL 2027 哨兵导航仿真工程
- Gazebo Sim (Jetty 10.6) + ROS 2 Lyrical + Nav2 全栈
- 整车模型:URDF/SDF + 减面网格(SolidWorks 装配体实测尺寸)
- 场地:RMUL 2027 官方包(2D 栅格地图 + 3D 场地模型),放在 field/
- sentry_nav C++ 包:self_filter 点云自滤 / patrol 航点巡逻
- 文档:README(含本机开发环境实测)、MID-360 接入说明

已排除:build/ install/ log/ 缓存目录,以及 115 MB 的原始高模
(仿真实际用的是 meshes/base.stl 减面版,约 25.7 万面)
2026-11-14 21:18:04 +08:00

67 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
#
# 重新生成工作区根的 compile_commands.json(VS Code / clangd 的智能感知数据源)。
#
# 做了两件事:
# 1. 用 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 跑一遍 colcon build(增量,很快)
# 2. 把 build/<包>/compile_commands.json 合并到工作区根目录
#
# 什么时候要重跑:新增/重命名了新 .cpp、新增了 C++ 包、改了 CMakeLists 的
# include 目录或依赖、换了 ROS 发行版。
#
# 用法:
# tools/gen_compdb.sh # 全部包
# tools/gen_compdb.sh sentry_nav # 只处理某个包
set -euo pipefail
ROS_SETUP="${ROS_SETUP:-/opt/ros/lyrical/setup.bash}"
# 本脚本在 tools/ 下,工作区根是它的父目录。
WS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ ! -f "${ROS_SETUP}" ]]; then
echo "找不到 ${ROS_SETUP},请用 ROS_SETUP=/opt/ros/<distro>/setup.bash 指定" >&2
exit 1
fi
# shellcheck disable=SC1090
# ROS 的 setup.bash 里有未定义变量,必须临时关掉 set -u 才能 source。
set +u
# shellcheck disable=SC1090
source "${ROS_SETUP}"
set -u
cd "${WS_ROOT}"
# 位置参数 = 包名列表;不给参数就构建整个工作区。
if [[ $# -gt 0 ]]; then
PACKAGE_ARGS=(--packages-select "$@")
else
PACKAGE_ARGS=()
fi
colcon build --symlink-install \
"${PACKAGE_ARGS[@]}" \
--cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
python3 - "${WS_ROOT}" <<'PY'
import glob
import json
import os
import sys
root = sys.argv[1]
out = []
for path in sorted(glob.glob(os.path.join(root, "build", "*", "compile_commands.json"))):
with open(path, encoding="utf-8") as f:
entries = json.load(f)
print(f"{len(entries):4d} 条 <- {os.path.relpath(path, root)}")
out.extend(entries)
if not out:
sys.exit("没有找到任何 compile_commands.json,检查包是否含 C/C++ 源文件")
with open(os.path.join(root, "compile_commands.json"), "w", encoding="utf-8") as f:
json.dump(out, f, indent=2)
print(f"合并完成 -> {os.path.join(root, 'compile_commands.json')}({len(out)} 条)")
PY