forked from zbw/yiliao2026
fix: remove hardcoded ROS shell paths
This commit is contained in:
@@ -48,10 +48,12 @@ cd ~/smart-healthcare-2026/src/mtran
|
||||
|
||||
## 3. 准备依赖、sidecar 和模型
|
||||
|
||||
从 `smart-healthcare-2026/src/mtran` 执行:
|
||||
先加载日常终端环境,再执行:
|
||||
|
||||
```bash
|
||||
./dependencies/auto_install.sh
|
||||
source ~/.bashrc
|
||||
cd ~/smart-healthcare-2026/src/mtran/dependencies
|
||||
./auto_install.sh
|
||||
```
|
||||
|
||||
脚本会请求 `sudo` 安装非 ROS apt 包,在 `dependencies/tools` 安装固定版本 Bun,
|
||||
@@ -66,9 +68,10 @@ Then: source install/setup.bash && ros2 launch mtran translator.launch.py
|
||||
|
||||
## 4. 检查准备结果
|
||||
|
||||
仍从 `smart-healthcare-2026/src/mtran` 执行:
|
||||
返回 `smart-healthcare-2026/src/mtran` 执行:
|
||||
|
||||
```bash
|
||||
cd ..
|
||||
file runtime/bin/mtranserver
|
||||
test -s runtime/config/records.json
|
||||
ls -lh models/en_zh-Hans
|
||||
@@ -96,7 +99,7 @@ models/en_zh-Hans/trgvocab.enzh.spm
|
||||
从工作区根目录 `smart-healthcare-2026` 执行,而不是从包目录执行:
|
||||
|
||||
```bash
|
||||
source /opt/ros/humble/setup.bash
|
||||
source ~/.bashrc
|
||||
PYTHONNOUSERSITE=1 colcon build --packages-select mtran
|
||||
```
|
||||
|
||||
@@ -115,7 +118,7 @@ CMake 不会联网、安装依赖或调用 Bun。它只检查第 4 节的准备
|
||||
从 `smart-healthcare-2026` 执行:
|
||||
|
||||
```bash
|
||||
source /opt/ros/humble/setup.bash
|
||||
source ~/.bashrc
|
||||
source install/setup.bash
|
||||
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` 执行:
|
||||
|
||||
```bash
|
||||
source /opt/ros/humble/setup.bash
|
||||
source ~/.bashrc
|
||||
source install/setup.bash
|
||||
ros2 service call /translate_en_to_zh \
|
||||
mtran/srv/TranslateEnglishToChinese \
|
||||
@@ -215,20 +218,20 @@ C++ 源码和模型数据不区分 CPU 架构。`auto_install.sh` 在运行机
|
||||
- 架构正确的 sidecar
|
||||
- 哈希和大小正确的四个模型文件
|
||||
|
||||
只重新构建 sidecar,从 `smart-healthcare-2026/src/mtran` 执行:
|
||||
只重新构建 sidecar,从 `smart-healthcare-2026/src/mtran/dependencies` 执行:
|
||||
|
||||
```bash
|
||||
rm -f runtime/bin/mtranserver
|
||||
rm -rf .build/mtranserver
|
||||
./dependencies/auto_install.sh
|
||||
rm -f ../runtime/bin/mtranserver
|
||||
rm -rf ../.build/mtranserver
|
||||
./auto_install.sh
|
||||
```
|
||||
|
||||
完全重新准备,从同一目录执行:
|
||||
|
||||
```bash
|
||||
rm -rf dependencies/tools .build runtime/config models/en_zh-Hans
|
||||
rm -f runtime/bin/mtranserver
|
||||
./dependencies/auto_install.sh
|
||||
rm -rf tools ../.build ../runtime/config ../models/en_zh-Hans
|
||||
rm -f ../runtime/bin/mtranserver
|
||||
./auto_install.sh
|
||||
```
|
||||
|
||||
清理 ROS2 构建结果,从 `smart-healthcare-2026` 执行:
|
||||
|
||||
@@ -17,7 +17,6 @@ bun_bin=""
|
||||
BUN_VERSION=1.3.14
|
||||
os_release_file=${MTRAN_OS_RELEASE_FILE:-/etc/os-release}
|
||||
machine=${MTRAN_MACHINE:-$(uname -m)}
|
||||
ros_prefix=${MTRAN_ROS_PREFIX:-/opt/ros/humble}
|
||||
|
||||
die()
|
||||
{
|
||||
@@ -38,9 +37,8 @@ validate_host()
|
||||
*) die "supported CPU architecture must be x86_64 or aarch64; found ${machine}." ;;
|
||||
esac
|
||||
|
||||
if [[ "${ROS_DISTRO:-}" != "humble" && ! -d "${ros_prefix}" ]]; then
|
||||
die "ROS2 Humble must already be installed by the user."
|
||||
fi
|
||||
[[ "${ROS_DISTRO:-}" == "humble" ]] || \
|
||||
die "ROS2 Humble environment must be sourced before running this script."
|
||||
|
||||
[[ -f "${vendor_source}/package.json" && -f "${vendor_source}/bun.lock" ]] || \
|
||||
die "vendored MTranServer source is missing under vendor/mtranserver."
|
||||
|
||||
@@ -7,6 +7,8 @@ User-provided prerequisites
|
||||
---------------------------
|
||||
- Ubuntu 22.04 on x86_64 or aarch64.
|
||||
- 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.
|
||||
- Required ROS packages:
|
||||
- ament_cmake
|
||||
|
||||
@@ -149,7 +149,6 @@ expect_failure "x86_64 or aarch64" env \
|
||||
expect_failure "ROS2 Humble" env -u ROS_DISTRO \
|
||||
MTRAN_OS_RELEASE_FILE="${ubuntu_release}" \
|
||||
MTRAN_MACHINE=x86_64 \
|
||||
MTRAN_ROS_PREFIX="${tmp_root}/missing-ros" \
|
||||
bash "${installer}"
|
||||
|
||||
missing_vendor="${tmp_root}/missing-vendor"
|
||||
|
||||
@@ -17,10 +17,10 @@ rsync -a \
|
||||
--exclude 'models/en_zh-Hans/' \
|
||||
"${root}/" "${fixture}/"
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
set +u
|
||||
source /opt/ros/humble/setup.bash
|
||||
set -u
|
||||
if [[ "${ROS_DISTRO:-}" != "humble" ]]; then
|
||||
echo "ROS2 Humble environment must be sourced before running this test" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if missing_output=$(cmake -S "${fixture}" -B "${fixture}/build-missing" 2>&1); then
|
||||
echo "CMake unexpectedly configured without prepared runtime files" >&2
|
||||
|
||||
@@ -6,7 +6,9 @@ readme="${root}/README.md"
|
||||
|
||||
required_entries=(
|
||||
"smart-healthcare-2026/src/mtran"
|
||||
"./dependencies/auto_install.sh"
|
||||
"src/mtran/dependencies"
|
||||
"./auto_install.sh"
|
||||
"source ~/.bashrc"
|
||||
"colcon build --packages-select mtran"
|
||||
"ros2 launch mtran translator.launch.py"
|
||||
"mtran/srv/TranslateEnglishToChinese"
|
||||
@@ -23,7 +25,7 @@ for required in "${required_entries[@]}"; do
|
||||
grep -Fq "${required}" "${readme}"
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
12
src/mtran/test/test_shell_paths.py
Normal file
12
src/mtran/test/test_shell_paths.py
Normal 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
|
||||
Reference in New Issue
Block a user