diff --git a/axvisor.sh b/axvisor.sh index 5e5be3e7..b528ad91 100755 --- a/axvisor.sh +++ b/axvisor.sh @@ -1,12 +1,12 @@ #!/bin/bash # -*- coding: utf-8 -*- -# Axvisor 统一管理脚本 -# 替代 Makefile,提供完整的项目管理功能 +# Axvisor unified management script +# Replaces the Makefile, providing complete project management functionality set -e -# 颜色定义 +# Color definitions RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' @@ -14,7 +14,7 @@ BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' # No Color -# 项目配置 +# Project configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$SCRIPT_DIR" HVCONFIG="$PROJECT_ROOT/.hvconfig.toml" @@ -23,10 +23,10 @@ VENV_DIR="$PROJECT_ROOT/venv" VENV_MARKER="$VENV_DIR/.bootstrapped" REQUIREMENTS="$PROJECT_ROOT/scripts/requirements.txt" -# 切换到项目根目录 +# Switch to project root cd "$PROJECT_ROOT" -# 输出函数 - 统一使用emoji符号 +# Output helper functions - unified emoji style info() { echo -e "${BLUE}ℹ️${NC} $*"; } success() { echo -e "${GREEN}✅${NC} $*"; } warning() { echo -e "${YELLOW}⚠️${NC} $*"; } @@ -34,48 +34,48 @@ error() { echo -e "${RED}❌${NC} $*"; } step() { echo -e "${CYAN}🚀${NC} $*"; } debug() { echo -e "${CYAN}🔍${NC} $*"; } -# 错误处理 +# Error handling handle_error() { error "命令失败: $1" exit 1 } -trap 'handle_error "脚本执行中断"' ERR +trap 'handle_error "Script interrupted"' ERR -# 检查系统依赖 +# Check system dependencies check_system_deps() { local missing_deps=() - # 检查 Python 3 + # Check Python 3 if ! command -v python3 >/dev/null 2>&1; then missing_deps+=("python3") fi - # 检查 Cargo + # Check Cargo if ! command -v cargo >/dev/null 2>&1; then missing_deps+=("cargo") fi if [[ ${#missing_deps[@]} -gt 0 ]]; then - error "缺少必要依赖: ${missing_deps[*]}" - info "请安装缺少的依赖后重试" + error "Missing required dependencies: ${missing_deps[*]}" + info "Install the missing dependencies and retry" exit 1 fi } -# 检查虚拟环境是否需要设置 +# Determine whether venv setup is needed needs_venv_setup() { - # 虚拟环境不存在 + # Virtual environment directory does not exist if [[ ! -d "$VENV_DIR" ]]; then return 0 fi - # Python 可执行文件不存在 + # Python executable missing inside venv if [[ ! -x "$VENV_DIR/bin/python3" ]]; then return 0 fi - # requirements.txt 更新了 + # requirements.txt is newer than the bootstrap marker if [[ "$REQUIREMENTS" -nt "$VENV_MARKER" ]]; then return 0 fi @@ -83,70 +83,69 @@ needs_venv_setup() { return 1 } -# 设置虚拟环境 +# Setup virtual environment setup_venv() { if ! needs_venv_setup; then return 0 fi - step "设置 Python 虚拟环境..." + step "Setting up Python virtual environment..." # 运行 bootstrap 脚本 ./scripts/bootstrap.sh - success "虚拟环境设置完成" + success "Virtual environment ready" } -# 配置文件管理 +# Config file management setup_defconfig() { - step "设置默认配置..." + step "Setting default config..." if [[ ! -f "$DEFAULT_HVCONFIG" ]]; then - error "默认配置文件 $DEFAULT_HVCONFIG 不存在" + error "Default config file $DEFAULT_HVCONFIG not found" exit 1 fi if [[ -f "$HVCONFIG" ]]; then - warning "配置文件 $HVCONFIG 已存在" - read -p "是否覆盖现有配置?(y/N): " -n 1 -r + warning "Config file $HVCONFIG already exists" + read -p "Overwrite existing config? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then - info "已取消操作" + info "Operation cancelled" return 0 fi fi cp "$DEFAULT_HVCONFIG" "$HVCONFIG" - success "已复制 $DEFAULT_HVCONFIG -> $HVCONFIG" + success "Copied $DEFAULT_HVCONFIG -> $HVCONFIG" - info "配置文件设置完成" - info "可以编辑 $HVCONFIG 来自定义配置" + info "Config file setup completed" + info "Edit $HVCONFIG to customize settings" } -# 确保配置文件存在(静默方式) +# Ensure config file exists (silent) ensure_config() { if [[ ! -f "$HVCONFIG" ]]; then if [[ -f "$DEFAULT_HVCONFIG" ]]; then - info "自动复制默认配置文件..." + info "Auto copying default config file..." cp "$DEFAULT_HVCONFIG" "$HVCONFIG" - success "已复制 $DEFAULT_HVCONFIG -> $HVCONFIG" + success "Copied $DEFAULT_HVCONFIG -> $HVCONFIG" else - warning "默认配置文件 $DEFAULT_HVCONFIG 不存在" - warning "请先运行 './axvisor.sh defconfig' 设置配置文件" + warning "Default config file $DEFAULT_HVCONFIG not found" + warning "Run './axvisor.sh defconfig' first to create it" fi fi } -# 运行 Python 任务 -# 运行 Python 任务 - 统一的任务执行入口 +# Run Python task (unified entry point) run_python_task() { local cmd="$1" shift - # 检查是否需要帮助 + # Check if help flag requested for arg in "$@"; do if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then - step "显示 $cmd 命令帮助..." + step "Showing help for $cmd..." setup_venv source "$VENV_DIR/bin/activate" python3 scripts/task.py "$cmd" --help @@ -154,7 +153,7 @@ run_python_task() { fi done - # 根据命令类型进行智能参数解析 + # Smart argument parsing based on command case "$cmd" in "clippy") parse_clippy_args "$@" @@ -169,10 +168,10 @@ run_python_task() { parse_run_args "$@" ;; *) - # 其他命令直接透传所有参数 - step "执行 $cmd 命令..." + # Other commands: pass all args + step "Executing command $cmd..." if [[ $# -gt 0 ]]; then - debug "参数: $*" + debug "Args: $*" fi setup_venv source "$VENV_DIR/bin/activate" @@ -181,12 +180,12 @@ run_python_task() { esac } -# 解析 clippy 命令参数 +# Parse clippy command arguments parse_clippy_args() { - local arch="aarch64" # 默认架构 + local arch="aarch64" # default arch local extra_args=() - # 解析参数 + # Parse args while [[ $# -gt 0 ]]; do case $1 in --arch) @@ -194,7 +193,7 @@ parse_clippy_args() { shift 2 ;; *) - # 如果没有 --arch 标志且是第一个未处理的参数,将其作为架构 + # First positional arg (without --arch) is treated as architecture if [[ ${#extra_args[@]} -eq 0 && "$1" != -* ]]; then arch="$1" shift @@ -206,9 +205,9 @@ parse_clippy_args() { esac done - step "运行代码检查 (架构: $arch)..." + step "Running clippy (arch: $arch)..." if [[ ${#extra_args[@]} -gt 0 ]]; then - debug "额外参数: ${extra_args[*]}" + debug "Extra args: ${extra_args[*]}" fi setup_venv @@ -216,12 +215,12 @@ parse_clippy_args() { python3 scripts/task.py clippy --arch "$arch" "${extra_args[@]}" } -# 解析 disk_img 命令参数 +# Parse disk_img command arguments parse_disk_img_args() { - local image="disk.img" # 默认镜像名 + local image="disk.img" # default image name local extra_args=() - # 解析参数 + # Parse args while [[ $# -gt 0 ]]; do case $1 in --image) @@ -229,7 +228,7 @@ parse_disk_img_args() { shift 2 ;; *) - # 如果没有 --image 标志且是第一个未处理的参数,将其作为镜像名 + # First positional arg (without --image) is image name if [[ ${#extra_args[@]} -eq 0 && "$1" != -* ]]; then image="$1" shift @@ -241,9 +240,9 @@ parse_disk_img_args() { esac done - step "创建磁盘镜像: $image" + step "Creating disk image: $image" if [[ ${#extra_args[@]} -gt 0 ]]; then - debug "额外参数: ${extra_args[*]}" + debug "Extra args: ${extra_args[*]}" fi setup_venv @@ -251,11 +250,11 @@ parse_disk_img_args() { python3 scripts/task.py disk_img --image "$image" "${extra_args[@]}" } -# 解析 build 命令参数 +# Parse build command arguments parse_build_args() { - step "构建项目..." + step "Building project..." if [[ $# -gt 0 ]]; then - debug "构建参数: $*" + debug "Build args: $*" fi setup_venv @@ -263,11 +262,11 @@ parse_build_args() { python3 scripts/task.py build "$@" } -# 解析 run 命令参数 +# Parse run command arguments parse_run_args() { - step "运行项目..." + step "Running project..." if [[ $# -gt 0 ]]; then - debug "运行参数: $*" + debug "Run args: $*" fi setup_venv @@ -275,112 +274,112 @@ parse_run_args() { python3 scripts/task.py run "$@" } -# 显示帮助信息 +# Show help information show_help() { - echo -e "${CYAN}🔧 Axvisor 项目管理工具${NC}" + echo -e "${CYAN}🔧 Axvisor Project Management Tool${NC}" echo - echo -e "${YELLOW}📋 用法:${NC} $0 <命令> [参数...]" + echo -e "${YELLOW}📋 Usage:${NC} $0 [args...]" echo - echo -e "${YELLOW}🛠️ 环境管理:${NC}" - echo " setup - 🚀 设置开发环境" - echo " defconfig - ⚙️ 设置默认配置文件" - echo " check-deps - ✅ 检查系统依赖" - echo " rebuild-venv - 🔄 强制重建虚拟环境" - echo " dev-env - 🔧 开发环境工具" + echo -e "${YELLOW}🛠️ Environment:${NC}" + echo " setup - 🚀 Setup development environment" + echo " defconfig - ⚙️ Copy default config file" + echo " check-deps - ✅ Check system dependencies" + echo " rebuild-venv - 🔄 Force rebuild virtual environment" + echo " dev-env - 🔧 Development environment helper" echo - echo -e "${YELLOW}🔨 构建命令:${NC}" - echo " build [args] - 🏗️ 构建项目 (支持完整参数透传)" - echo " clean [args] - 🧹 清理构建产物" - echo " clippy [args] - 🔍 运行代码检查 (支持 --arch 和其他参数)" + echo -e "${YELLOW}🔨 Build:${NC}" + echo " build [args] - 🏗️ Build project (args passthrough)" + echo " clean [args] - 🧹 Clean build artifacts" + echo " clippy [args] - 🔍 Run clippy lint (supports --arch)" echo - echo -e "${YELLOW}▶️ 运行命令:${NC}" - echo " run [args] - 🚀 运行项目 (支持完整参数透传)" - echo " disk_img [args] - 💾 创建磁盘镜像 (支持 --image 和其他参数)" + echo -e "${YELLOW}▶️ Run:${NC}" + echo " run [args] - 🚀 Run project (args passthrough)" + echo " disk_img [args] - 💾 Create disk image (supports --image)" echo - echo -e "${YELLOW}ℹ️ 信息命令:${NC}" - echo " status - 📊 显示项目状态" - echo " version - 📦 显示版本信息" - echo " help - ❓ 显示此帮助信息" + echo -e "${YELLOW}ℹ️ Info:${NC}" + echo " status - 📊 Show project status" + echo " version - 📦 Show version information" + echo " help - ❓ Show this help" echo - echo -e "${YELLOW}🎯 高级功能:${NC}" - echo " • 所有命令支持 --help 查看详细参数" - echo " • 参数完全透传到 task.py,支持所有原生功能" - echo " • 智能参数解析,兼容新老调用方式" + echo -e "${YELLOW}🎯 Advanced:${NC}" + echo " • All commands support --help" + echo " • Arguments passed directly to task.py" + echo " • Smart argument parsing (legacy/new)" echo - echo -e "${YELLOW}📚 构建示例:${NC}" + echo -e "${YELLOW}📚 Build examples:${NC}" echo " $0 build --plat aarch64-qemu-virt-hv" echo " $0 build --plat aarch64-generic --features fs" echo " $0 clippy --arch aarch64" echo - echo -e "${YELLOW}🎮 运行示例:${NC}" + echo -e "${YELLOW}🎮 Run examples:${NC}" echo " $0 run --plat aarch64-qemu-virt-hv" echo " $0 run --vmconfigs configs/vms/linux-qemu-aarch64.toml" } -# 显示项目状态 +# Show project status show_status() { - step "项目状态" + step "Project status" - echo "项目根目录: $PROJECT_ROOT" - echo "配置文件: $([ -f "$HVCONFIG" ] && echo "✓ 存在" || echo "✗ 不存在")" - echo "虚拟环境: $([ -d "$VENV_DIR" ] && echo "✓ 已设置" || echo "✗ 未设置")" + echo "Project root: $PROJECT_ROOT" + echo "Config file: $([ -f "$HVCONFIG" ] && echo "✓ Present" || echo "✗ Missing")" + echo "Virtual env: $([ -d "$VENV_DIR" ] && echo "✓ Present" || echo "✗ Missing")" if [[ -f "$VENV_MARKER" ]]; then - echo "环境状态: ✓ 已初始化" - local timestamp=$(grep "timestamp:" "$VENV_MARKER" 2>/dev/null | cut -d' ' -f2- || echo "未知") - echo "初始化时间: $timestamp" + echo "Env status: ✓ Initialized" + local timestamp=$(grep "timestamp:" "$VENV_MARKER" 2>/dev/null | cut -d' ' -f2- || echo "unknown") + echo "Initialized time: $timestamp" else - echo "环境状态: ✗ 未初始化" + echo "Env status: ✗ Not initialized" fi - # 检查系统依赖 - echo "系统依赖:" + # Check system dependencies + echo "System deps:" command -v python3 >/dev/null 2>&1 && echo " Python3: ✓" || echo " Python3: ✗" command -v cargo >/dev/null 2>&1 && echo " Cargo: ✓" || echo " Cargo: ✗" - # 显示最近的构建产物 + # Show latest build artifact timestamp if [[ -f "axvisor-dev_aarch64-generic.bin" ]]; then local build_time=$(stat -c %y "axvisor-dev_aarch64-generic.bin" 2>/dev/null | cut -d' ' -f1,2) - echo "最近构建: $build_time" + echo "Latest build: $build_time" fi } -# 显示版本信息 +# Show version information show_version() { - echo "Axvisor 管理脚本 v2.0" - echo "项目: axvisor-dev" - echo "分支: $(git branch --show-current 2>/dev/null || echo "未知")" - echo "提交: $(git rev-parse --short HEAD 2>/dev/null || echo "未知")" + echo "Axvisor management script v2.0" + echo "Project: axvisor-dev" + echo "Branch: $(git branch --show-current 2>/dev/null || echo "unknown")" + echo "Commit: $(git rev-parse --short HEAD 2>/dev/null || echo "unknown")" } -# 强制重建虚拟环境 +# Force rebuild virtual environment rebuild_venv() { - step "强制重建虚拟环境..." + step "Force rebuilding virtual environment..." if [[ -d "$VENV_DIR" ]]; then - warning "删除现有虚拟环境..." + warning "Removing existing virtual environment..." rm -rf "$VENV_DIR" fi setup_venv - success "虚拟环境重建完成" + success "Virtual environment rebuilt" } -# 设置完整的开发环境 +# Setup full development environment setup_environment() { - step "设置开发环境..." + step "Setting up development environment..." check_system_deps setup_venv - success "开发环境设置完成" + success "Development environment setup completed" } -# 主命令处理 +# Main command dispatcher main() { local cmd="${1:-help}" shift || true # 移除第一个参数,剩余参数传递给子命令 case "$cmd" in - # 帮助和信息 + # Help & info "help"|"-h"|"--help") show_help ;; @@ -391,7 +390,7 @@ main() { show_status ;; - # 环境管理 + # Environment management "setup") setup_environment ;; @@ -406,18 +405,18 @@ main() { rebuild_venv ;; - # 构建和开发命令 - 统一使用 run_python_task + # Build & development commands "build") run_python_task build "$@" ;; "clean") run_python_task clean "$@" - # 额外清理 cargo 产物 + # Additionally clean cargo artifacts if command -v cargo >/dev/null 2>&1; then - step "清理 Cargo 构建产物..." + step "Cleaning Cargo build artifacts..." cargo clean fi - success "清理完成" + success "Clean completed" ;; "clippy") run_python_task clippy "$@" @@ -429,26 +428,26 @@ main() { run_python_task disk_img "$@" ;; "dev-env") - step "设置开发环境..." + step "Setting up development environment..." setup_venv source "$VENV_DIR/bin/activate" python3 scripts/dev_env.py "$@" ;; - # 未知命令 + # Unknown command *) - error "未知命令: $cmd" - info "使用 '$0 help' 查看可用命令" + error "Unknown command: $cmd" + info "Use '$0 help' to list available commands" exit 1 ;; esac } -# 脚本入口点 +# Script entry point if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # 处理中断信号 - trap 'echo -e "\n${YELLOW}用户中断操作${NC}"; exit 130' INT + # Handle interrupt signal + trap 'echo -e "\n${YELLOW}User cancelled operation${NC}"; exit 130' INT - # 执行主函数 + # Execute main function main "$@" fi diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 43f26d6b..76e9bce7 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -2,51 +2,51 @@ # -*- coding: utf-8 -*- # Axvisor Bootstrap Script -# 此脚本用于创建 Python 虚拟环境并安装 task.py 所需的依赖 +# This script creates a Python virtual environment and installs task.py dependencies -set -e # 遇到错误时退出 +set -e # Exit on error -# 颜色输出 +# Colored output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color -# 输出函数 +# Output helpers info() { echo -e "${BLUE}ℹ${NC} $1"; } success() { echo -e "${GREEN}✓${NC} $1"; } warning() { echo -e "${YELLOW}⚠${NC} $1"; } error() { echo -e "${RED}✗${NC} $1"; } -# 获取项目根目录 +# Get project root directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_ROOT" -# 检查是否已经在虚拟环境中 +# If already inside a virtual environment, just update deps if [[ -n "$VIRTUAL_ENV" ]]; then - info "检测到已在虚拟环境中: $VIRTUAL_ENV" + info "Detected active virtual environment: $VIRTUAL_ENV" - # 检查 requirements.txt 文件是否存在 + # Ensure requirements.txt exists if [[ ! -f "scripts/requirements.txt" ]]; then - error "scripts/requirements.txt 文件未找到" + error "scripts/requirements.txt not found" exit 1 fi - # 安装/更新依赖 - info "更新 Python 依赖..." + # Install / update dependencies + info "Updating Python dependencies..." pip install -q -r scripts/requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple - success "依赖更新完成" + success "Dependencies updated" exit 0 fi -# 虚拟环境和标记文件 +# Virtual environment and marker file VENV_DIR="venv" MARKER_FILE="$VENV_DIR/.bootstrapped" REQUIREMENTS_FILE="scripts/requirements.txt" -# 计算依赖哈希值 +# Compute dependency hash compute_dep_hash() { local pyver pyver=$(python3 --version 2>/dev/null || echo "unknown") @@ -60,128 +60,128 @@ compute_dep_hash() { fi } -# 检查是否需要重新引导 +# Decide if bootstrap is needed check_bootstrap_needed() { - # 如果虚拟环境不存在,需要引导 + # Need bootstrap if venv directory missing if [[ ! -d "$VENV_DIR" ]]; then - return 0 # 需要引导 + return 0 # need bootstrap fi - # 如果标记文件不存在,需要引导 + # Need bootstrap if marker file missing if [[ ! -f "$MARKER_FILE" ]]; then - return 0 # 需要引导 + return 0 # need bootstrap fi - # 检查哈希值是否匹配 + # Check dependency hash local existing_hash current_hash existing_hash=$(awk -F":" '/^hash:/ {print $2}' "$MARKER_FILE" 2>/dev/null | tr -d '[:space:]') || existing_hash="" current_hash=$(compute_dep_hash) if [[ "$existing_hash" != "$current_hash" ]]; then - info "检测到依赖变更,需要重新引导" - return 0 # 需要引导 + info "Dependency changes detected, re-bootstrap required" + return 0 # need bootstrap fi - # 检查虚拟环境的Python是否可用 + # Ensure python executable exists in venv if [[ ! -x "$VENV_DIR/bin/python3" ]]; then - warning "虚拟环境的 Python 不可用,需要重新引导" - return 0 # 需要引导 + warning "Python in virtual env not available, re-bootstrap required" + return 0 # need bootstrap fi - return 1 # 不需要引导 + return 1 # bootstrap not needed } -# 快速检查并退出 +# Fast path: already bootstrapped if ! check_bootstrap_needed; then - success "引导已完成且依赖未更改,跳过引导" + success "Bootstrap already done and dependencies unchanged, skipping" exit 0 fi -info "开始设置 Python 虚拟环境..." +info "Starting Python virtual environment setup..." -# 检查系统依赖 +# Check system dependencies check_system_deps() { - info "检查系统依赖..." + info "Checking system dependencies..." - # 检查 Python 3 + # Check python3 exists if ! command -v python3 >/dev/null 2>&1; then - error "python3 未找到,请先安装 Python 3" + error "python3 not found. Please install Python 3" exit 1 fi - # 检查 Python 版本 + # Report Python version local pyver pyver=$(python3 --version 2>&1 | awk '{print $2}' | cut -d. -f1,2) - info "检测到 Python 版本: $pyver" + info "Detected Python version: $pyver" - # 检查 venv 模块 + # Check venv module if ! python3 -c "import venv" 2>/dev/null; then - error "python3-venv 模块未找到" - echo "请安装 python3-venv:" - echo " Ubuntu/Debian: sudo apt install python3-venv" - echo " CentOS/RHEL: sudo yum install python3-venv" - echo " Fedora: sudo dnf install python3-venv" + error "python3-venv module not found" + echo "Install python3-venv via your package manager:" + echo " Ubuntu/Debian: sudo apt install python3-venv" + echo " CentOS/RHEL: sudo yum install python3-venv" + echo " Fedora: sudo dnf install python3-venv" exit 1 fi - # 检查 requirements.txt + # Check requirements.txt exists if [[ ! -f "$REQUIREMENTS_FILE" ]]; then - error "$REQUIREMENTS_FILE 文件未找到" + error "$REQUIREMENTS_FILE not found" exit 1 fi - success "系统依赖检查完成" + success "System dependency check passed" } -# 创建虚拟环境 +# Create virtual environment setup_venv() { - info "设置虚拟环境..." + info "Preparing virtual environment..." - # 如果虚拟环境已存在但损坏,删除它 + # Remove broken venv if [[ -d "$VENV_DIR" ]] && [[ ! -x "$VENV_DIR/bin/python3" ]]; then - warning "检测到损坏的虚拟环境,正在删除..." + warning "Corrupted virtual environment detected, removing..." rm -rf "$VENV_DIR" fi - # 创建虚拟环境 + # Create venv if missing if [[ ! -d "$VENV_DIR" ]]; then - info "创建新的虚拟环境..." + info "Creating new virtual environment..." python3 -m venv "$VENV_DIR" - success "虚拟环境已创建" + success "Virtual environment created" else - info "使用现有虚拟环境" + info "Using existing virtual environment" fi } -# 安装依赖 +# Install dependencies install_deps() { - info "安装 Python 依赖..." + info "Installing Python dependencies..." # 激活虚拟环境 source "$VENV_DIR/bin/activate" - # 升级 pip(静默) + # Upgrade pip (quiet) python -m pip install -q --upgrade pip -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple - # 安装依赖 + # Install requirements pip install -q -r "$REQUIREMENTS_FILE" -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple - success "依赖安装完成" + success "Dependencies installed" } -# 验证安装 +# Verify installation verify_installation() { - info "验证安装..." + info "Verifying installation..." # 测试 task.py if source "$VENV_DIR/bin/activate" && python3 ./scripts/task.py --help >/dev/null 2>&1; then - success "task.py 运行正常" + success "task.py runs correctly" else - error "task.py 运行失败" + error "task.py execution failed" exit 1 fi } -# 写入完成标记 +# Write completion marker write_marker() { local dep_hash dep_hash=$(compute_dep_hash) @@ -192,10 +192,10 @@ timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ) python_version: $(python3 --version) EOF - success "引导完成标记已写入 (hash: ${dep_hash:0:8}...)" + success "Bootstrap marker written (hash: ${dep_hash:0:8}...)" } -# 主要执行流程 +# Main execution flow main() { check_system_deps setup_venv @@ -203,10 +203,10 @@ main() { verify_installation write_marker - success "虚拟环境设置完成!" - info "使用 'source venv/bin/activate' 激活环境" - info "使用 'make help' 查看可用命令" + success "Virtual environment setup complete!" + info "Activate with: source venv/bin/activate" + info "Use 'make help' to see available commands" } -# 执行主函数 +# Execute main function main "$@" diff --git a/scripts/build.py b/scripts/build.py index 1bd4e893..c54e5294 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -9,50 +9,52 @@ def main(args) -> int: - """构建项目""" - print("执行 build 功能...") + """Build the project""" + print("Running build task...") - # 获取配置文件路径 + # Get config file path config_file_path = getattr(args, "config", ".hvconfig.toml") - - # 检查配置文件是否存在 + # Check if config file exists config_exists = os.path.exists(config_file_path) - # 首先设置 arceos 依赖 - print("设置 arceos 依赖...") + # Setup arceos dependency first + print("Setting up arceos dependency...") if not setup_arceos(): - print("设置 arceos 失败,无法继续构建") + print("Failed to setup arceos, cannot build") return 1 - # 创建配置对象 + # Create config object config: AxvisorConfig = create_config_from_args(args) - - # 构建 make 命令 + # Build make command cmd = config.format_make_command("") - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: - # 执行 make 命令 + # Run make command result = subprocess.run( cmd, shell=True, check=True, env=config.get_subprocess_env() ) - print("构建成功!") + print("Build succeeded!") - # 如果配置文件不存在且有有意义的命令行参数,则创建配置文件 + # If config file missing and CLI args meaningful, create the config file if not config_exists: - print(f"检测到 {config_file_path} 不存在,根据命令行参数创建配置文件...") + print( + f"Detected missing {config_file_path}, creating config file from arguments..." + ) if save_config_to_file(config, config_file_path): print( - f"配置文件创建成功,下次可以直接运行 './task.py build -c {config_file_path}' 而无需指定参数" + f"Config file created. Next time just run './task.py build -c {config_file_path}'" ) else: - print("配置文件创建失败,下次仍需手动指定参数") + print( + "Failed to create config file; you'll need to pass arguments again next run" + ) return 0 except subprocess.CalledProcessError as e: - print(f"构建失败,退出码: {e.returncode}") + print(f"Build failed, exit code: {e.returncode}") return e.returncode except Exception as e: - print(f"构建过程中发生错误: {e}") + print(f"Error during build: {e}") return 1 diff --git a/scripts/clean.py b/scripts/clean.py index f99e9b24..d8ef62fb 100644 --- a/scripts/clean.py +++ b/scripts/clean.py @@ -6,32 +6,32 @@ def main(args) -> int: - """清理构建产物""" - print("执行 clean 功能...") + """Clean build artifacts""" + print("Running clean task...") - # 首先设置 arceos 依赖 - print("设置 arceos 依赖...") + # Setup arceos dependency first + print("Setting up arceos dependency...") if not setup_arceos(): - print("设置 arceos 失败,无法继续执行 clean") + print("Failed to setup arceos, cannot clean") return 1 cmd = format_make_command_base() cmd.append("clean") - # 构建 make 命令 + # Build make command string cmd = " ".join(cmd) - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: - # 执行 make 命令 + # Run make command subprocess.run(cmd, shell=True, check=True) - print("清理完成!") + print("Clean succeeded!") return 0 except subprocess.CalledProcessError as e: - print(f"清理失败,退出码: {e.returncode}") + print(f"Clean failed, exit code: {e.returncode}") return e.returncode except Exception as e: - print(f"清理过程中发生错误: {e}") + print(f"Error during clean: {e}") return 1 diff --git a/scripts/clippy.py b/scripts/clippy.py index 18c30da4..c7db4e37 100644 --- a/scripts/clippy.py +++ b/scripts/clippy.py @@ -15,62 +15,61 @@ def main(args) -> int: - """运行 clippy 代码检查""" - print("执行 clippy 功能...") + """Run clippy lint checks""" + print("Running clippy task...") - # 首先设置 arceos 依赖 - print("设置 arceos 依赖...") + # First setup arceos dependency + print("Setting up arceos dependency...") if not setup_arceos(): - print("设置 arceos 失败,无法继续执行 clippy") + print("Failed to setup arceos, cannot continue clippy") return 1 - # 读取根目录的 Cargo.toml 并解析 [features] + # Read root Cargo.toml and parse [features] cargo_toml_path = os.path.join(os.getcwd(), "Cargo.toml") if not os.path.exists(cargo_toml_path): - print(f"未找到 {cargo_toml_path},无法继续") + print(f"Not found {cargo_toml_path}, abort") return 1 - - # 解析 Cargo.toml,使用第三方 toml 包(文本模式) + # Parse Cargo.toml using third-party toml package parsed = None if _toml_impl is None: - print("需要安装 python-toml 包(pip install toml)来解析 Cargo.toml") + print("Need python 'toml' package (pip install toml) to parse Cargo.toml") return 1 try: with open(cargo_toml_path, "r", encoding="utf-8") as f: parsed = _toml_impl.load(f) except Exception as e: - print(f"解析 Cargo.toml 失败: {e}") + print(f"Failed to parse Cargo.toml: {e}") return 1 features_dict = parsed.get("features", {}) if isinstance(parsed, dict) else {} all_features: List[str] = list(features_dict.keys()) - # 找出以 plat- 开头的 feature + # Collect features starting with plat- plat_features = [f for f in all_features if f.startswith("plat-")] - # 其他非 plat 的 feature + # Non-plat features non_plat_features = [f for f in all_features if not f.startswith("plat-")] if not plat_features: print( - "在 Cargo.toml 的 [features] 中未找到以 'plat-' 开头的 feature,将以所有 feature 运行一次 clippy" + "No 'plat-' features found in Cargo.toml [features]; running single clippy pass with all features" ) features_arg = ",".join(all_features) if all_features else "" cmd_parts = ["cargo", "clippy"] if features_arg: cmd_parts.extend(["--features", f'"{features_arg}"']) cmd = " ".join(cmd_parts) - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: subprocess.run(cmd, shell=True, check=True) - print("clippy 检查完成!") + print("Clippy finished successfully") return 0 except subprocess.CalledProcessError as e: - print(f"clippy 检查失败,退出码: {e.returncode}") + print(f"Clippy failed with exit code: {e.returncode}") return e.returncode except Exception as e: - print(f"clippy 检查过程中发生错误: {e}") + print(f"Error while running clippy: {e}") return 1 - # 简单的 arch -> target 三元组映射(可按需扩展) + # Simple arch -> target triple map (extend as needed) arch_target_map = { "aarch64": "aarch64-unknown-none-softfloat", "x86": "x86_64-unknown-none", @@ -81,12 +80,12 @@ def main(args) -> int: any_failure = False for plat in plat_features: - # 从 plat 名称尝试提取 arch token(plat--...) + # Extract arch token from plat name (plat--...) parts = plat.split("-") arch_token = parts[1] if len(parts) > 1 else None target = arch_target_map.get(arch_token) if arch_token else None - # 构建 features: 选中当前 plat + 所有非 plat features(避免同时启用多个 plat) + # Build features: current plat + all non-plat ones (avoid enabling multiple plat features) features_to_use = [plat] + non_plat_features features_arg = ",".join(features_to_use) if features_to_use else "" @@ -96,17 +95,25 @@ def main(args) -> int: if features_arg: cmd_parts.extend(["--features", f'"{features_arg}"']) + cmd_parts.extend( + [ + "--", + "-D", + "warnings", + ] + ) + cmd = " ".join(cmd_parts) - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: subprocess.run(cmd, shell=True, check=True) - print(f"{plat}: clippy 检查完成") + print(f"{plat}: clippy finished successfully") except subprocess.CalledProcessError as e: - print(f"{plat}: clippy 检查失败,退出码: {e.returncode}") + print(f"{plat}: clippy failed, exit code: {e.returncode}") any_failure = True except Exception as e: - print(f"{plat}: clippy 检查过程中发生错误: {e}") + print(f"{plat}: error while running clippy: {e}") any_failure = True return 1 if any_failure else 0 diff --git a/scripts/disk_img.py b/scripts/disk_img.py index dd7d4840..be263cfd 100644 --- a/scripts/disk_img.py +++ b/scripts/disk_img.py @@ -9,43 +9,42 @@ def main(args) -> int: - """创建磁盘镜像""" - print("执行 disk_img 功能...") + """Create disk image""" + print("Running disk_img task...") - # 首先设置 arceos 依赖 - print("设置 arceos 依赖...") + # Setup arceos dependency first + print("Setting up arceos dependency...") if not setup_arceos(): - print("设置 arceos 失败,无法继续执行 disk_img") + print("Failed to setup arceos, cannot create disk image") return 1 cmd = format_make_command_base() if args.image: - # 处理镜像路径,如果是相对路径则转换为绝对路径 + # Handle image path: convert relative path to absolute image_path = args.image if not os.path.isabs(image_path): - # 相对于项目根目录计算绝对路径 + # Compute absolute path relative to project root project_root = os.getcwd() image_path = os.path.abspath(os.path.join(project_root, image_path)) - - # 如果指定了镜像路径和文件名,则添加到命令中 + # Add image path to command if specified cmd.append(f"DISK_IMG={image_path}") cmd.append("disk_img") - # 构建 make 命令 + # Build make command cmd = " ".join(cmd) - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: - # 执行 make 命令 + # Run make command subprocess.run(cmd, shell=True, check=True) - print("磁盘镜像创建完成!") + print("Disk image created successfully!") return 0 except subprocess.CalledProcessError as e: - print(f"磁盘镜像创建失败,退出码: {e.returncode}") + print(f"Disk image creation failed, exit code: {e.returncode}") return e.returncode except Exception as e: - print(f"磁盘镜像创建过程中发生错误: {e}") + print(f"Error during disk image creation: {e}") return 1 diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 7fc9d50d..861a3962 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,2 +1,2 @@ -# Axvisor task.py 依赖 +# Axvisor task.py dependencies toml>=0.10.0 diff --git a/scripts/run.py b/scripts/run.py index 383a89cc..c3675e0c 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -10,34 +10,32 @@ def main(args) -> int: - """运行项目""" - print("执行 run 功能...") + """Run the project""" + print("Running run task...") - # 创建配置对象 + # Create config object config: AxvisorConfig = create_config_from_args(args) - - # 首先执行 build - print("运行前先构建项目...") + # Build first + print("Building project before run...") build_result = build.main(args) if build_result != 0: - print("构建失败,无法运行") + print("Build failed; aborting run") return build_result - - # 构建 make 命令 + # Build make command cmd = config.format_make_command("run") - print(f"执行命令: {cmd}") + print(f"Executing: {cmd}") try: - # 执行 make run 命令 + # Run make run command result = subprocess.run( cmd, shell=True, check=True, env=config.get_subprocess_env() ) - print("运行完成!") + print("Run completed!") return 0 except subprocess.CalledProcessError as e: - print(f"运行失败,退出码: {e.returncode}") + print(f"Run failed, exit code: {e.returncode}") return e.returncode except Exception as e: - print(f"运行过程中发生错误: {e}") + print(f"Error during run: {e}") return 1 diff --git a/scripts/setup.py b/scripts/setup.py index 7393e2b7..38fd5dbb 100644 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -5,13 +5,13 @@ def setup_arceos(): - """设置 arceos 依赖""" + """Setup arceos dependency""" arceos_dir = ".arceos" if not os.path.exists(arceos_dir): - print("正在克隆 arceos 仓库...") + print("Cloning arceos repository...") try: - # 克隆 arceos 仓库 + # Clone arceos repository result = subprocess.run( [ "git", @@ -25,22 +25,21 @@ def setup_arceos(): capture_output=True, text=True, ) - - print("arceos 仓库克隆完成") + print("arceos repository cloned") return True except subprocess.CalledProcessError as e: - print(f"克隆 arceos 仓库失败: {e}") - print(f"错误输出: {e.stderr}") + print(f"Failed to clone arceos repository: {e}") + print(f"Stderr: {e.stderr}") return False except Exception as e: - print(f"设置 arceos 过程中发生错误: {e}") + print(f"Error while setting up arceos: {e}") return False else: - print(".arceos 文件夹已存在") + print(".arceos directory already exists") return True def main(args=None): - """作为独立命令使用时的入口""" - print("执行 setup-arceos 功能...") + """Entry point when used as standalone command""" + print("Running setup-arceos task...") return 0 if setup_arceos() else 1 diff --git a/src/vmm/config.rs b/src/vmm/config.rs index fa14b3c0..06afc5ca 100644 --- a/src/vmm/config.rs +++ b/src/vmm/config.rs @@ -13,13 +13,12 @@ use crate::vmm::fdt::*; use alloc::sync::Arc; -#[allow(clippy::module_inception)] +#[allow(clippy::module_inception, dead_code)] pub mod config { use alloc::string::String; use alloc::vec::Vec; /// Default static VM configs. Used when no VM config is provided. - #[allow(dead_code)] pub fn default_static_vm_configs() -> Vec<&'static str> { vec![ #[cfg(target_arch = "x86_64")] diff --git a/src/vmm/fdt/mod.rs b/src/vmm/fdt/mod.rs index ad294cf9..b76da293 100644 --- a/src/vmm/fdt/mod.rs +++ b/src/vmm/fdt/mod.rs @@ -96,7 +96,8 @@ pub fn get_developer_provided_dtb( use axerrno::ax_err_type; use std::io::{BufReader, Read}; if let Some(dtb_path) = &crate_config.kernel.dtb_path { - let (dtb_file, dtb_size) = crate::vmm::images::open_image_file(dtb_path).unwrap(); + let (dtb_file, dtb_size) = + crate::vmm::images::fs::open_image_file(dtb_path).unwrap(); info!("DTB file in fs, size: 0x{:x}", dtb_size); let mut file = BufReader::new(dtb_file); diff --git a/src/vmm/images/mod.rs b/src/vmm/images/mod.rs index 922a15a2..cfe0fca7 100644 --- a/src/vmm/images/mod.rs +++ b/src/vmm/images/mod.rs @@ -192,7 +192,7 @@ pub fn load_vm_image_from_memory( } #[cfg(feature = "fs")] -mod fs { +pub mod fs { use super::*; use crate::hal::CacheOp; use axerrno::{AxResult, ax_err, ax_err_type}; @@ -328,6 +328,3 @@ mod fs { Ok((file, file_size)) } } - -#[cfg(feature = "fs")] -pub use fs::open_image_file;