Skip to content

Commit

Permalink
xtask: 使用eprintln代替println
Browse files Browse the repository at this point in the history
  • Loading branch information
luojia65 committed Dec 30, 2021
1 parent bc31070 commit e388db4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
11 changes: 8 additions & 3 deletions test-kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![no_std]
#![no_main]


mod console;
mod mm;
mod sbi;
Expand Down Expand Up @@ -75,7 +74,10 @@ pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
}

extern "C" fn hart_2_resume(hart_id: usize, param: usize) {
println!("<< The parameter passed to hart {} resume is: {:#x}", hart_id, param);
println!(
"<< The parameter passed to hart {} resume is: {:#x}",
hart_id, param
);
let param = 0x12345678;
println!(">> Start hart 3 with parameter {:#x}", param);
/* start_addr should be physical address, and here pa == va */
Expand All @@ -85,7 +87,10 @@ extern "C" fn hart_2_resume(hart_id: usize, param: usize) {
}

extern "C" fn hart_3_start(hart_id: usize, param: usize) {
println!("<< The parameter passed to hart {} start is: {:#x}", hart_id, param);
println!(
"<< The parameter passed to hart {} start is: {:#x}",
hart_id, param
);
println!("<< Test-kernel: All hart SBI test SUCCESS, shutdown");
sbi::shutdown()
}
Expand Down
47 changes: 25 additions & 22 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@ fn main() {
let mut xtask_env = XtaskEnv {
compile_mode: CompileMode::Debug,
};
println!("xtask: mode: {:?}", xtask_env.compile_mode);
if let Some(matches) = matches.subcommand_matches("make") {
if matches.is_present("release") {
xtask_env.compile_mode = CompileMode::Release;
}
eprintln!("xtask make: mode: {:?}", xtask_env.compile_mode);
xtask_build_sbi(&xtask_env);
xtask_binary_sbi(&xtask_env);
} else if let Some(matches) = matches.subcommand_matches("asm") {
if matches.is_present("release") {
xtask_env.compile_mode = CompileMode::Release;
}
eprintln!("xtask asm: mode: {:?}", xtask_env.compile_mode);
xtask_build_sbi(&xtask_env);
xtask_asm_sbi(&xtask_env);
} else if let Some(matches) = matches.subcommand_matches("image") {
if matches.is_present("release") {
xtask_env.compile_mode = CompileMode::Release;
}
eprintln!("xtask image: mode: {:?}", xtask_env.compile_mode);
xtask_build_sbi(&xtask_env);
xtask_binary_sbi(&xtask_env);
if matches.value_of("PAYLOAD") == Some("test-kernel") {
Expand All @@ -82,11 +84,12 @@ fn main() {
xtask_sd_image(&xtask_env);
}
} else if let Some(_matches) = matches.subcommand_matches("gdb") {
eprintln!("xtask gdb: mode: {:?}", xtask_env.compile_mode);
xtask_build_sbi(&xtask_env);
xtask_binary_sbi(&xtask_env);
xtask_unmatched_gdb(&xtask_env);
} else {
println!("Use `cargo make` to build, `cargo xtask --help` for help")
eprintln!("Use `cargo make` to build, `cargo xtask --help` for help")
}
}

Expand All @@ -105,7 +108,7 @@ fn xtask_build_sbi(xtask_env: &XtaskEnv) {
command.args(&["--target", DEFAULT_TARGET]);
let status = command.status().unwrap();
if !status.success() {
println!("cargo build failed");
eprintln!("cargo build failed");
process::exit(1);
}
}
Expand All @@ -122,7 +125,7 @@ fn xtask_binary_sbi(xtask_env: &XtaskEnv) {
.unwrap();

if !status.success() {
println!("objcopy binary failed");
eprintln!("objcopy binary failed");
process::exit(1);
}
}
Expand Down Expand Up @@ -153,13 +156,14 @@ fn xtask_unmatched_gdb(xtask_env: &XtaskEnv) {
let status = command.status().expect("run program");

if !status.success() {
println!("gdb failed with status {}", status);
eprintln!("gdb failed with status {}", status);
process::exit(status.code().unwrap_or(1));
}
}

fn xtask_sd_image(xtask_env: &XtaskEnv) {
let status = find_mkimage().expect("find mkimage tool")
let status = find_mkimage()
.expect("find mkimage tool")
.current_dir(project_root())
.arg("-f")
.arg(&format!("sd-image-{}.its", xtask_env.compile_mode))
Expand All @@ -168,7 +172,7 @@ fn xtask_sd_image(xtask_env: &XtaskEnv) {
.expect("create sd card image");

if !status.success() {
println!("mkimage failed with status {}", status);
eprintln!("mkimage failed with status {}", status);
process::exit(status.code().unwrap_or(1));
}
}
Expand All @@ -188,7 +192,7 @@ fn xtask_build_test_kernel(xtask_env: &XtaskEnv) {
command.args(&["--target", DEFAULT_TARGET]);
let status = command.status().unwrap();
if !status.success() {
println!("cargo build failed");
eprintln!("cargo build failed");
process::exit(1);
}
}
Expand All @@ -205,22 +209,26 @@ fn xtask_binary_test_kernel(xtask_env: &XtaskEnv) {
.unwrap();

if !status.success() {
println!("objcopy binary failed");
eprintln!("objcopy binary failed");
process::exit(1);
}
}

fn xtask_sd_image_test_kernel(xtask_env: &XtaskEnv) {
let status = find_mkimage().expect("find mkimage tool")
let status = find_mkimage()
.expect("find mkimage tool")
.current_dir(project_root())
.arg("-f")
.arg(&format!("test-kernel/sd-image-{}.its", xtask_env.compile_mode))
.arg(&format!(
"test-kernel/sd-image-{}.its",
xtask_env.compile_mode
))
.arg("target/rustsbi-with-test-kernel.img")
.status()
.expect("create sd card image");

if !status.success() {
println!("mkimage failed with status {}", status);
eprintln!("mkimage failed with status {}", status);
process::exit(status.code().unwrap_or(1));
}
}
Expand All @@ -243,23 +251,18 @@ fn project_root() -> PathBuf {
}

fn find_mkimage() -> std::io::Result<Command> {
let mkimage = Command::new("mkimage")
.arg("-V")
.status();
let mkimage = Command::new("mkimage").arg("-V").status();
if mkimage.is_ok() {
return Ok(Command::new("mkimage"))
return Ok(Command::new("mkimage"));
}
#[cfg(windows)]
{
let wsl_mkimage = Command::new("wsl")
.arg("mkimage")
.arg("-V")
.status();
let wsl_mkimage = Command::new("wsl").arg("mkimage").arg("-V").status();
if wsl_mkimage.is_ok() {
let mut cmd = Command::new("wsl");
cmd.arg("mkimage");
return Ok(cmd)
return Ok(cmd);
}
}
return Err(mkimage.unwrap_err())
return Err(mkimage.unwrap_err());
}

0 comments on commit e388db4

Please sign in to comment.