fix: remove hardcoded ROS shell paths

This commit is contained in:
2026-07-30 19:48:35 +08:00
parent 8de4e20046
commit d03cefb07c
7 changed files with 40 additions and 24 deletions

View File

@@ -48,10 +48,12 @@ cd ~/smart-healthcare-2026/src/mtran
## 3. 准备依赖、sidecar 和模型 ## 3. 准备依赖、sidecar 和模型
`smart-healthcare-2026/src/mtran` 执行: 先加载日常终端环境,再执行:
```bash ```bash
./dependencies/auto_install.sh source ~/.bashrc
cd ~/smart-healthcare-2026/src/mtran/dependencies
./auto_install.sh
``` ```
脚本会请求 `sudo` 安装非 ROS apt 包,在 `dependencies/tools` 安装固定版本 Bun 脚本会请求 `sudo` 安装非 ROS apt 包,在 `dependencies/tools` 安装固定版本 Bun
@@ -66,9 +68,10 @@ Then: source install/setup.bash && ros2 launch mtran translator.launch.py
## 4. 检查准备结果 ## 4. 检查准备结果
仍从 `smart-healthcare-2026/src/mtran` 执行: 返回 `smart-healthcare-2026/src/mtran` 执行:
```bash ```bash
cd ..
file runtime/bin/mtranserver file runtime/bin/mtranserver
test -s runtime/config/records.json test -s runtime/config/records.json
ls -lh models/en_zh-Hans ls -lh models/en_zh-Hans
@@ -96,7 +99,7 @@ models/en_zh-Hans/trgvocab.enzh.spm
从工作区根目录 `smart-healthcare-2026` 执行,而不是从包目录执行: 从工作区根目录 `smart-healthcare-2026` 执行,而不是从包目录执行:
```bash ```bash
source /opt/ros/humble/setup.bash source ~/.bashrc
PYTHONNOUSERSITE=1 colcon build --packages-select mtran PYTHONNOUSERSITE=1 colcon build --packages-select mtran
``` ```
@@ -115,7 +118,7 @@ CMake 不会联网、安装依赖或调用 Bun。它只检查第 4 节的准备
`smart-healthcare-2026` 执行: `smart-healthcare-2026` 执行:
```bash ```bash
source /opt/ros/humble/setup.bash source ~/.bashrc
source install/setup.bash source install/setup.bash
PYTHONNOUSERSITE=1 ros2 launch mtran translator.launch.py PYTHONNOUSERSITE=1 ros2 launch mtran translator.launch.py
``` ```
@@ -132,7 +135,7 @@ MTranServer is healthy and the en-to-zh-Hans model is warm
保留启动终端,在第二个终端中从 `smart-healthcare-2026` 执行: 保留启动终端,在第二个终端中从 `smart-healthcare-2026` 执行:
```bash ```bash
source /opt/ros/humble/setup.bash source ~/.bashrc
source install/setup.bash source install/setup.bash
ros2 service call /translate_en_to_zh \ ros2 service call /translate_en_to_zh \
mtran/srv/TranslateEnglishToChinese \ mtran/srv/TranslateEnglishToChinese \
@@ -215,20 +218,20 @@ C++ 源码和模型数据不区分 CPU 架构。`auto_install.sh` 在运行机
- 架构正确的 sidecar - 架构正确的 sidecar
- 哈希和大小正确的四个模型文件 - 哈希和大小正确的四个模型文件
只重新构建 sidecar`smart-healthcare-2026/src/mtran` 执行: 只重新构建 sidecar`smart-healthcare-2026/src/mtran/dependencies` 执行:
```bash ```bash
rm -f runtime/bin/mtranserver rm -f ../runtime/bin/mtranserver
rm -rf .build/mtranserver rm -rf ../.build/mtranserver
./dependencies/auto_install.sh ./auto_install.sh
``` ```
完全重新准备,从同一目录执行: 完全重新准备,从同一目录执行:
```bash ```bash
rm -rf dependencies/tools .build runtime/config models/en_zh-Hans rm -rf tools ../.build ../runtime/config ../models/en_zh-Hans
rm -f runtime/bin/mtranserver rm -f ../runtime/bin/mtranserver
./dependencies/auto_install.sh ./auto_install.sh
``` ```
清理 ROS2 构建结果,从 `smart-healthcare-2026` 执行: 清理 ROS2 构建结果,从 `smart-healthcare-2026` 执行:

View File

@@ -17,7 +17,6 @@ bun_bin=""
BUN_VERSION=1.3.14 BUN_VERSION=1.3.14
os_release_file=${MTRAN_OS_RELEASE_FILE:-/etc/os-release} os_release_file=${MTRAN_OS_RELEASE_FILE:-/etc/os-release}
machine=${MTRAN_MACHINE:-$(uname -m)} machine=${MTRAN_MACHINE:-$(uname -m)}
ros_prefix=${MTRAN_ROS_PREFIX:-/opt/ros/humble}
die() die()
{ {
@@ -38,9 +37,8 @@ validate_host()
*) die "supported CPU architecture must be x86_64 or aarch64; found ${machine}." ;; *) die "supported CPU architecture must be x86_64 or aarch64; found ${machine}." ;;
esac esac
if [[ "${ROS_DISTRO:-}" != "humble" && ! -d "${ros_prefix}" ]]; then [[ "${ROS_DISTRO:-}" == "humble" ]] || \
die "ROS2 Humble must already be installed by the user." die "ROS2 Humble environment must be sourced before running this script."
fi
[[ -f "${vendor_source}/package.json" && -f "${vendor_source}/bun.lock" ]] || \ [[ -f "${vendor_source}/package.json" && -f "${vendor_source}/bun.lock" ]] || \
die "vendored MTranServer source is missing under vendor/mtranserver." die "vendored MTranServer source is missing under vendor/mtranserver."

View File

@@ -7,6 +7,8 @@ User-provided prerequisites
--------------------------- ---------------------------
- Ubuntu 22.04 on x86_64 or aarch64. - Ubuntu 22.04 on x86_64 or aarch64.
- ROS2 Humble, installed and maintained by the user. - ROS2 Humble, installed and maintained by the user.
- The ROS2 Humble environment must be sourced before running auto_install.sh
or the package shell tests.
- Python 3 from Ubuntu/ROS2, used for runtime-data integrity checks. - Python 3 from Ubuntu/ROS2, used for runtime-data integrity checks.
- Required ROS packages: - Required ROS packages:
- ament_cmake - ament_cmake

View File

@@ -149,7 +149,6 @@ expect_failure "x86_64 or aarch64" env \
expect_failure "ROS2 Humble" env -u ROS_DISTRO \ expect_failure "ROS2 Humble" env -u ROS_DISTRO \
MTRAN_OS_RELEASE_FILE="${ubuntu_release}" \ MTRAN_OS_RELEASE_FILE="${ubuntu_release}" \
MTRAN_MACHINE=x86_64 \ MTRAN_MACHINE=x86_64 \
MTRAN_ROS_PREFIX="${tmp_root}/missing-ros" \
bash "${installer}" bash "${installer}"
missing_vendor="${tmp_root}/missing-vendor" missing_vendor="${tmp_root}/missing-vendor"

View File

@@ -17,10 +17,10 @@ rsync -a \
--exclude 'models/en_zh-Hans/' \ --exclude 'models/en_zh-Hans/' \
"${root}/" "${fixture}/" "${root}/" "${fixture}/"
# shellcheck disable=SC1091 if [[ "${ROS_DISTRO:-}" != "humble" ]]; then
set +u echo "ROS2 Humble environment must be sourced before running this test" >&2
source /opt/ros/humble/setup.bash exit 1
set -u fi
if missing_output=$(cmake -S "${fixture}" -B "${fixture}/build-missing" 2>&1); then if missing_output=$(cmake -S "${fixture}" -B "${fixture}/build-missing" 2>&1); then
echo "CMake unexpectedly configured without prepared runtime files" >&2 echo "CMake unexpectedly configured without prepared runtime files" >&2

View File

@@ -6,7 +6,9 @@ readme="${root}/README.md"
required_entries=( required_entries=(
"smart-healthcare-2026/src/mtran" "smart-healthcare-2026/src/mtran"
"./dependencies/auto_install.sh" "src/mtran/dependencies"
"./auto_install.sh"
"source ~/.bashrc"
"colcon build --packages-select mtran" "colcon build --packages-select mtran"
"ros2 launch mtran translator.launch.py" "ros2 launch mtran translator.launch.py"
"mtran/srv/TranslateEnglishToChinese" "mtran/srv/TranslateEnglishToChinese"
@@ -23,7 +25,7 @@ for required in "${required_entries[@]}"; do
grep -Fq "${required}" "${readme}" grep -Fq "${required}" "${readme}"
done done
if rg -n 'mtran_ros2|/home/hikos/MTranServer|Path\.cwd|build_mtranserver\.sh' "${readme}"; then if rg -n 'mtran_ros2|MTranServer/migrate_ws|Path\.cwd|build_mtranserver\.sh' "${readme}"; then
echo "README still contains an obsolete package name or local path" >&2 echo "README still contains an obsolete package name or local path" >&2
exit 1 exit 1
fi fi

View File

@@ -0,0 +1,12 @@
from pathlib import Path
root = Path(__file__).resolve().parents[1]
installer = (root / "dependencies" / "auto_install.sh").read_text(encoding="utf-8")
cmake_test = (root / "test" / "test_cmake_preparation.sh").read_text(encoding="utf-8")
assert "pwd -P" in installer
assert "/opt/ros/humble" not in installer
assert "MTRAN_ROS_PREFIX" not in installer
assert "/opt/ros/humble" not in cmake_test
assert "ROS_DISTRO" in cmake_test