- name
- ros2-workspace-ops
- description
- Build, test, and source ROS 2 colcon workspaces (ament_cmake/python, rosdep, overlays, parallel-workers). Use for colcon build/test failures, package.xml / CMakeLists issues, workspace setup, or when the user mentions colcon, ament, rosdep, or ROS 2 packages.
# ROS 2 Workspace Ops
## Hard constraints (this machine)
- **`colcon` parallel workers: max 2** (`--parallel-workers 2`) unless the user overrides — more can OOM/crash the host.
- Prefer container builds when the project rule says so (e.g. SIRB `./sirb build-ws`); never fight that rule.
## Standard loop
```bash
source /opt/ros/$ROS_DISTRO/setup.bash
cd <ws>
rosdep install --from-paths src --ignore-src -y # when deps changed
colcon build --symlink-install --parallel-workers 2 --packages-select <pkg>
source install/setup.bash
colcon test --parallel-workers 2 --packages-select <pkg>
colcon test-result --verbose
```
Useful flags:
```bash
colcon build --packages-up-to <pkg> --parallel-workers 2
colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
colcon build --event-handlers console_direct+
```
## Overlay order
Source **underlay → shared overlay → your overlay**. Always `install/setup.bash`, never `build/`.
## Triage
| Symptom | Likely fix |
|---------|------------|
| Package not found | `colcon list`; wrong cwd / not sourced |
| Missing CMake package | source underlay; `rosdep install` |
| Msgs unknown at runtime | rebuild interface pkg + re-source overlay |
| Python edits ignored | `--symlink-install` or clean rebuild |
| OOM mid-build | `--parallel-workers 2` or `--executor sequential` |
| Duplicate package name | two copies under `src/` |
## Report format
- Workspace + package scope
- Commands run
- Pass/fail + first actionable error
- Recommended next fix
在 GitHub 查看