Skip to content

Commit 4e63860

Browse files
authored
optimize build command (#319)
* feat: enhance build commands with detailed descriptions and aliases * chore: update axvm dependency to remove specific ref * fix: update log messages to English for consistency * feat: implement tar extraction using flate2 and tar crates * refactor: remove 'pull' alias from image download command and update related documentation * feat: update image download command to use 'no_extract' flag for extraction control
1 parent 3e0a195 commit 4e63860

File tree

6 files changed

+61
-39
lines changed

6 files changed

+61
-39
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ axaddrspace = "0.1.1"
5959
axhvc = {git = "https://github.com/arceos-hypervisor/axhvc.git"}
6060
axruntime = {path = "modules/axruntime"}
6161
axvcpu = "0.1"
62-
axvm = {git = "https://github.com/arceos-hypervisor/axvm.git", branch = "next", ref = "0393f27"}
62+
axvm = {git = "https://github.com/arceos-hypervisor/axvm.git", branch = "next"}
6363

6464
# System independent crates provided by ArceOS, these crates could be imported by remote url.
6565
axerrno = "0.1.0"

xtask/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ toml.workspace = true
2222
zerocopy = "=0.8.28"
2323
# adapt nightly-2025-05-20
2424
axvmconfig = {workspace = true, features = ["std"]}
25+
tar = "0.4"
26+
flate2 = "1.0"

xtask/src/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Context {
2525
PathBuf::from(format!(".qemu-{arch:?}.toml").to_lowercase())
2626
};
2727

28-
// 如果配置文件不存在,从默认位置复制
28+
// If the configuration file does not exist, copy from the default location
2929
if !config_path.exists() {
3030
fs::copy(
3131
PathBuf::from("scripts")

xtask/src/image.rs

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//!! ```
1212
//! // List available images
1313
//! xtask image ls
14-
//! // Download a specific image and automatically extract it
14+
//! // Download a specific image and automatically extract it (default behavior)
1515
//! xtask image download evm3588_arceos --output-dir ./images
1616
//! // Download a specific image without extracting
1717
//! xtask image download evm3588_arceos --output-dir ./images --no-extract
@@ -21,12 +21,13 @@
2121
2222
use anyhow::{Result, anyhow};
2323
use clap::{Parser, Subcommand};
24+
use flate2::read::GzDecoder;
2425
use sha2::{Digest, Sha256};
2526
use std::env;
2627
use std::fs;
2728
use std::io::Read;
2829
use std::path::Path;
29-
use std::process::Command;
30+
use tar::Archive;
3031
use tokio::io::{AsyncWriteExt, BufWriter};
3132

3233
/// Base URL for downloading images
@@ -43,23 +44,28 @@ pub struct ImageArgs {
4344
/// Image management commands
4445
#[derive(Subcommand)]
4546
pub enum ImageCommands {
46-
/// List all available image
47+
/// List all available images
4748
Ls,
49+
4850
/// Download the specified image and automatically extract it
49-
#[command(alias = "pull")]
5051
Download {
52+
/// Name of the image to download
5153
image_name: String,
54+
55+
/// Output directory for the downloaded image
5256
#[arg(short, long)]
5357
output_dir: Option<String>,
54-
#[arg(
55-
short,
56-
long,
57-
help = "Automatically extract after download (default: true)"
58-
)]
59-
extract: Option<bool>,
58+
59+
/// Do not extract after download
60+
#[arg(long, help = "Do not extract after download")]
61+
no_extract: bool,
6062
},
63+
6164
/// Remove the specified image from temp directory
62-
Rm { image_name: String },
65+
Rm {
66+
/// Name of the image to remove
67+
image_name: String
68+
},
6369
}
6470

6571
/// Representation of a guest image
@@ -315,8 +321,6 @@ fn image_list() -> Result<()> {
315321
/// ```
316322
/// // Download the evm3588_arceos image to the ./images directory and automatically extract it
317323
/// xtask image download evm3588_arceos --output-dir ./images
318-
/// // Or use the pull alias
319-
/// xtask image pull evm3588_arceos --output-dir ./images
320324
/// ```
321325
async fn image_download(image_name: &str, output_dir: Option<String>, extract: bool) -> Result<()> {
322326
let image = Image::find_by_name(image_name).ok_or_else(|| {
@@ -421,8 +425,6 @@ async fn image_download(image_name: &str, output_dir: Option<String>, extract: b
421425
.await
422426
.map_err(|e| anyhow!("Error flushing file: {e}"))?;
423427

424-
println!("\nDownload completed");
425-
426428
// Verify downloaded file
427429
match image_verify_sha256(&output_path, image.sha256) {
428430
Ok(true) => {
@@ -431,12 +433,12 @@ async fn image_download(image_name: &str, output_dir: Option<String>, extract: b
431433
Ok(false) => {
432434
// Remove the invalid downloaded file
433435
let _ = fs::remove_file(&output_path);
434-
return Err(anyhow!("Downloaded file SHA256 verification failed"));
436+
return Err(anyhow!("Download completed but file SHA256 verification failed"));
435437
}
436438
Err(e) => {
437439
// Remove the potentially corrupted downloaded file
438440
let _ = fs::remove_file(&output_path);
439-
return Err(anyhow!("Error verifying downloaded file: {e}"));
441+
return Err(anyhow!("Download completed but error verifying downloaded file: {e}"));
440442
}
441443
}
442444

@@ -453,18 +455,13 @@ async fn image_download(image_name: &str, output_dir: Option<String>, extract: b
453455
// Ensure extraction directory exists
454456
fs::create_dir_all(&extract_dir)?;
455457

456-
// Use tar command to extract file
457-
let mut child = Command::new("tar")
458-
.arg("-xzf")
459-
.arg(&output_path)
460-
.arg("-C")
461-
.arg(&extract_dir)
462-
.spawn()?;
463-
464-
let status = child.wait()?;
465-
if !status.success() {
466-
return Err(anyhow!("Extraction failed, tar exit code: {status}"));
467-
}
458+
// Open the compressed tar file
459+
let tar_gz = fs::File::open(&output_path)?;
460+
let decoder = GzDecoder::new(tar_gz);
461+
let mut archive = Archive::new(decoder);
462+
463+
// Extract the archive
464+
archive.unpack(&extract_dir)?;
468465

469466
println!("Image extracted to: {}", extract_dir.display());
470467
}
@@ -529,8 +526,6 @@ fn image_remove(image_name: &str) -> Result<()> {
529526
/// // Run image management commands
530527
/// xtask image ls
531528
/// xtask image download evm3588_arceos --output-dir ./images
532-
/// // Or use the pull alias
533-
/// xtask image pull evm3588_arceos --output-dir ./images
534529
/// xtask image rm evm3588_arceos
535530
/// ```
536531
pub async fn run_image(args: ImageArgs) -> Result<()> {
@@ -541,9 +536,11 @@ pub async fn run_image(args: ImageArgs) -> Result<()> {
541536
ImageCommands::Download {
542537
image_name,
543538
output_dir,
544-
extract,
539+
no_extract,
545540
} => {
546-
image_download(&image_name, output_dir, extract.unwrap_or(true)).await?;
541+
// Determine if extraction should be performed
542+
let should_extract = !no_extract;
543+
image_download(&image_name, output_dir, should_extract).await?;
547544
}
548545
ImageCommands::Rm { image_name } => {
549546
image_remove(&image_name)?;

xtask/src/main.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ struct Cli {
2929
enum Commands {
3030
/// Set default build configuration from board configs
3131
Defconfig {
32-
/// Board configuration name (e.g., qemu-aarch64, orangepi-5-plus)
32+
/// Board configuration name (e.g., qemu-aarch64, orangepi-5-plus, phytiumpi)
3333
board_name: String,
3434
},
35+
/// Build the ArceOS project with current configuration
3536
Build,
3637
/// Run clippy checks across all targets and feature combinations
3738
Clippy(ClippyArgs),
39+
/// Run ArceOS in QEMU emulation environment
3840
Qemu(QemuArgs),
41+
/// Run ArceOS with U-Boot bootloader
3942
Uboot(UbootArgs),
43+
/// Generate VM configuration schema
4044
Vmconfig,
45+
/// Interactive menu-based configuration editor
4146
Menuconfig,
4247
/// Guest Image management
4348
Image(image::ImageArgs),
@@ -47,10 +52,15 @@ enum Commands {
4752

4853
#[derive(Parser)]
4954
struct QemuArgs {
55+
/// Path to custom build configuration file (TOML format)
5056
#[arg(long)]
5157
build_config: Option<PathBuf>,
58+
59+
/// Path to custom QEMU configuration file
5260
#[arg(long)]
5361
qemu_config: Option<PathBuf>,
62+
63+
/// Comma-separated list of VM configuration files
5464
#[arg(long)]
5565
vmconfigs: Vec<String>,
5666
}
@@ -60,29 +70,39 @@ struct ClippyArgs {
6070
/// Only check specific packages (comma separated)
6171
#[arg(long)]
6272
packages: Option<String>,
73+
6374
/// Only check specific targets (comma separated)
6475
#[arg(long)]
6576
targets: Option<String>,
77+
6678
/// Continue on error instead of exiting immediately
6779
#[arg(long)]
6880
continue_on_error: bool,
81+
6982
/// Dry run - show what would be checked without running clippy
7083
#[arg(long)]
7184
dry_run: bool,
85+
7286
/// Automatically fix clippy warnings where possible
7387
#[arg(long)]
7488
fix: bool,
89+
7590
/// Allow fixing when the working directory is dirty (has uncommitted changes)
7691
#[arg(long)]
7792
allow_dirty: bool,
7893
}
7994

8095
#[derive(Parser)]
8196
struct UbootArgs {
97+
/// Path to custom build configuration file (TOML format)
8298
#[arg(long)]
8399
build_config: Option<PathBuf>,
100+
101+
/// Path to custom U-Boot configuration file
84102
#[arg(long)]
85103
uboot_config: Option<PathBuf>,
104+
105+
/// Comma-separated list of VM configuration files
86106
#[arg(long)]
87107
vmconfigs: Vec<String>,
88108
}
@@ -95,7 +115,10 @@ struct DevspaceArgs {
95115

96116
#[derive(Subcommand)]
97117
enum DevspaceCommand {
118+
/// Start the development workspace
98119
Start,
120+
121+
/// Stop the development workspace
99122
Stop,
100123
}
101124

xtask/src/menuconfig.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::sync::Arc; // HashMap is unused
66
impl Context {
77
/// Main menuconfig runner function
88
pub async fn run_menuconfig(&mut self) -> anyhow::Result<()> {
9-
println!("配置运行参数");
9+
println!("Configure runtime parameters");
1010
let config_path = self.ctx.workspace_folder.join(".build.toml");
1111
if config_path.exists() {
12-
println!("\n当前 .build.toml 配置文件: {}", config_path.display());
12+
println!("\nCurrent .build.toml configuration file: {}", config_path.display());
1313
} else {
14-
println!("\n未找到 .build.toml 配置文件,将使用默认配置");
14+
println!("\nNo .build.toml configuration file found, will use default configuration");
1515
}
1616

1717
let Some(_c): Option<Config> =

0 commit comments

Comments
 (0)