Skip to content

y test: improve verbose output formatting #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions bootstrap/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use color_print::cprintln;
use std::path::{Path, PathBuf};
use std::process::Command;

#[derive(Debug)]
pub struct Manifest {
pub verbose: bool,
pub release: bool,
Expand All @@ -12,36 +13,70 @@ pub struct Manifest {
impl Manifest {
/// Builds the rustc codegen c library
pub fn prepare(&self) {
cprintln!("<b>[BUILD]</b> codegen backend");
// Build codegen backend
if self.verbose {
cprintln!("<b>[BUILD]</b> preparing codegen backend");
cprintln!(" target: {}", self.codegen_backend().display());
} else {
cprintln!("<b>[BUILD]</b> codegen backend");
}

let mut command = Command::new("cargo");
command.arg("build").args(["--manifest-path", "crates/Cargo.toml"]);
if self.verbose {
command.args(["-F", "debug"]);
command.args(["-v"]);
cprintln!(" command: {}", format!("{:?}", command).replace('"', ""));
}
if self.release {
command.arg("--release");
}
log::debug!("running {:?}", command);
command.status().unwrap();
let status = command.status().unwrap();
if self.verbose && status.success() {
cprintln!(" <g>success</g>");
}

// Build runtime library
if self.verbose {
cprintln!("<b>[BUILD]</b> preparing librust_runtime");
cprintln!(" output: {}", self.out_dir.display());
} else {
cprintln!("<b>[BUILD]</b> librust_runtime");
}

cprintln!("<b>[BUILD]</b> librust_runtime");
std::fs::create_dir_all(&self.out_dir).unwrap();
let cc = std::env::var("CC").unwrap_or("clang".to_string());

// Compile runtime.c
let mut command = Command::new(&cc);
command
.arg("rust_runtime/rust_runtime.c")
.arg("-o")
.arg(self.out_dir.join("rust_runtime.o"))
.arg("-c");
if self.verbose {
cprintln!(" compile: {}", format!("{:?}", command).replace('"', ""));
}
log::debug!("running {:?}", command);
command.status().unwrap();
let status = command.status().unwrap();
if self.verbose && status.success() {
cprintln!(" <g>success</g>");
}

// Create static library
let mut command = Command::new("ar");
command
.arg("rcs")
.arg(self.out_dir.join("librust_runtime.a"))
.arg(self.out_dir.join("rust_runtime.o"));
if self.verbose {
cprintln!(" archive: {}", format!("{:?}", command).replace('"', ""));
}
log::debug!("running {:?}", command);
command.status().unwrap();
let status = command.status().unwrap();
if self.verbose && status.success() {
cprintln!(" <g>success</g>");
}
}

/// The path to the rustc codegen c library
Expand Down
73 changes: 64 additions & 9 deletions bootstrap/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,76 @@ impl Run for TestCommand {
cprintln!("<r,s>Test failed</r,s>: {}", info);
}));

if manifest.verbose {
cprintln!("<b>[TEST]</b> preparing to run tests with manifest: {:?}", manifest);
}

cprintln!("<b>[TEST]</b> running cargo test");
let mut command = std::process::Command::new("cargo");
command.args(["test", "--manifest-path", "crates/Cargo.toml"]);
if manifest.verbose {
cprintln!("<b>[TEST]</b> executing command: {:?}", command);
}
log::debug!("running {:?}", command);
assert!(command.status().unwrap().success(), "failed to run {:?}", command);

let testcases = self.collect_testcases(manifest);
cprintln!("<b>[TEST]</b> found {} testcases", testcases.len());
if manifest.verbose {
for case in &testcases {
cprintln!("<b>[TEST]</b> found test: {} ({:?})", case.name, case.test);
}
}

let filechecker = FileChecker::new();
for testcase in testcases {
match testcase.test {
TestType::FileCheck => {
cprint!("File checking {}...", testcase.name);
if manifest.verbose {
cprintln!("<b>[TEST]</b> file checking <cyan>{}</cyan>", testcase.name);
cprintln!(" source: {}", testcase.source.display());
cprintln!(" output: {}", testcase.output_file.display());
} else {
cprint!("File checking {}... ", testcase.name);
}
testcase.build(manifest);
filechecker.run(&testcase);
}
TestType::Bless => {
cprint!("Blessing {}...", testcase.name);
if manifest.verbose {
cprintln!("<b>[TEST]</b> blessing <cyan>{}</cyan>", testcase.name);
cprintln!(" source: {}", testcase.source.display());
cprintln!(" output: {}", testcase.output_file.display());
} else {
cprint!("Blessing {}... ", testcase.name);
}
testcase.build(manifest);
bless(self.bless, &testcase);
}
TestType::Compile => {
cprint!("Compiling {}...", testcase.name);
if manifest.verbose {
cprintln!("<b>[TEST]</b> compiling <cyan>{}</cyan>", testcase.name);
cprintln!(" source: {}", testcase.source.display());
cprintln!(" output: {}", testcase.output_file.display());
} else {
cprint!("Compiling {}... ", testcase.name);
}
testcase.build(manifest);
}
TestType::CompileLib => {
cprint!("Compiling lib {}...", testcase.name);
if manifest.verbose {
cprintln!("<b>[TEST]</b> compiling lib <cyan>{}</cyan>", testcase.name);
cprintln!(" source: {}", testcase.source.display());
cprintln!(" output: {}", testcase.output_file.display());
} else {
cprint!("Compiling lib {}... ", testcase.name);
}
testcase.build_lib(manifest);
}
}
cprintln!("<g>OK</g>");
if !manifest.verbose {
cprintln!("<g>OK</g>");
}
}
}
}
Expand Down Expand Up @@ -116,6 +154,7 @@ impl TestCommand {
}
}

#[derive(Debug)]
pub enum TestType {
/// Test an executable can be compiled
Compile,
Expand Down Expand Up @@ -145,8 +184,16 @@ impl TestCase {
.arg(&self.source)
.arg("-o")
.arg(&self.output_file);
if manifest.verbose {
cprintln!(" command: {}", format!("{:?}", command).replace('"', ""));
}
log::debug!("running {:?}", command);
command.status().unwrap();
let status = command.status().unwrap();
if manifest.verbose {
if status.success() {
cprintln!(" <g>success</g>");
}
}
}

pub fn build_lib(&self, manifest: &Manifest) {
Expand All @@ -157,10 +204,18 @@ impl TestCase {
.args(["--crate-type", "lib"])
.arg("-O")
.arg(&self.source)
.arg("--out-dir") // we use `--out-dir` to integrate with the default name convention
.arg(output_dir); // so here we ignore the filename and just use the directory
.arg("--out-dir")
.arg(output_dir);
if manifest.verbose {
cprintln!(" command: {}", format!("{:?}", command).replace('"', ""));
}
log::debug!("running {:?}", command);
command.status().unwrap();
let status = command.status().unwrap();
if manifest.verbose {
if status.success() {
cprintln!(" <g>success</g>");
}
}
}

/// Get the generated C file f
Expand Down