78 lines
2.3 KiB
Markdown
78 lines
2.3 KiB
Markdown
# 维护 ROS 2 源代码检出
|
||
|
||
## [概述](https://docs.ros.org/en/humble/Installation/Maintaining-a-Source-Checkout.html)
|
||
|
||
本文档介绍如何维护从源代码构建的 ROS 2 安装。如果您已经从源代码安装了 ROS 2,并且想要更新到最新的错误修复和功能,请遵循本指南。
|
||
|
||
## [更新 ROS 2 源代码](https://docs.ros.org/en/humble/Installation/Maintaining-a-Source-Checkout.html#updating-ros-2-source-code)
|
||
|
||
### 1. 更新仓库列表文件
|
||
|
||
首先,您需要获取最新的 `ros2.repos` 文件,该文件定义了构建 ROS 2 所需的所有仓库及其分支。
|
||
|
||
```bash
|
||
# 对于 Humble Hawksbill 版本
|
||
cd ~/ros2_humble
|
||
wget https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos -O ros2.repos
|
||
```
|
||
|
||
或者,如果您想使用特定分支(例如主分支)而不是发布分支:
|
||
|
||
```bash
|
||
# 使用主分支(开发版本)
|
||
wget https://raw.githubusercontent.com/ros2/ros2/master/ros2.repos -O ros2.repos
|
||
```
|
||
|
||
### 2. 更新本地仓库
|
||
|
||
使用 `vcs` 工具更新您的本地仓库:
|
||
|
||
```bash
|
||
# 更新所有仓库的远程引用
|
||
vcs custom --args remote update
|
||
```
|
||
|
||
### 3. 下载新的源代码
|
||
|
||
现在,使用新的 `ros2.repos` 文件导入并拉取最新的代码:
|
||
|
||
```bash
|
||
# 导入新仓库定义
|
||
vcs import src < ros2.repos
|
||
|
||
# 拉取所有仓库的最新代码
|
||
vcs pull src
|
||
```
|
||
|
||
**注意**:`vcs import` 命令将覆盖 `src` 目录中现有的仓库定义。如果您有本地修改或添加了额外的仓库,请确保在运行此命令之前备份您的更改。
|
||
|
||
### 4. 重新构建工作空间
|
||
|
||
更新源代码后,需要重新构建工作空间:
|
||
|
||
```bash
|
||
# 返回到工作空间根目录
|
||
cd ~/ros2_humble
|
||
|
||
# 使用 colcon 重新构建
|
||
colcon build --symlink-install
|
||
```
|
||
|
||
构建选项说明:
|
||
- `--symlink-install`:使用符号链接而不是复制文件,这可以加快构建速度并减少磁盘空间使用
|
||
|
||
### 5. 检查源代码状态
|
||
|
||
要查看当前工作空间中所有仓库的状态,可以导出当前的仓库配置:
|
||
|
||
```bash
|
||
# 导出当前仓库状态
|
||
vcs export src > my_ros2.repos
|
||
```
|
||
|
||
这将在当前目录下创建一个 `my_ros2.repos` 文件,其中包含所有仓库的当前提交哈希值。您可以将此文件用于:
|
||
- 备份当前的源代码状态
|
||
- 在其他机器上复制相同的配置
|
||
- 调试构建问题
|
||
|