Skip to content

Commit

Permalink
Refactor and clean up xtask package (#1540)
Browse files Browse the repository at this point in the history
* Simplify building/running examples, allow building a single example

* Simplify building/running of tests a bit

* Clean up the `run_elfs` function a bit

* Remove unnecessary duplication in `cargo` module
  • Loading branch information
jessebraham authored May 7, 2024
1 parent 8567d35 commit df2b7bd
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 228 deletions.
24 changes: 2 additions & 22 deletions xtask/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ pub fn run(args: &[String], cwd: &Path) -> Result<()> {
let status = Command::new(get_cargo())
.args(args)
.current_dir(cwd)
.stdout(Stdio::piped())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())
.status()?;

// Make sure that we return an appropriate exit code here, as Github Actions
Expand All @@ -35,27 +36,6 @@ pub fn run(args: &[String], cwd: &Path) -> Result<()> {
}
}

/// Execute cargo with the given arguments and from the specified directory.
pub fn run_with_input(args: &[String], cwd: &Path) -> Result<()> {
if !cwd.is_dir() {
bail!("The `cwd` argument MUST be a directory");
}

let status = Command::new(get_cargo())
.args(args)
.current_dir(cwd)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.stdin(std::process::Stdio::inherit())
.status()?;

if status.success() {
Ok(())
} else {
Err(anyhow::anyhow!("Failed to execute cargo subcommand"))
}
}

fn get_cargo() -> String {
#[cfg(target_os = "windows")]
let cargo = if let Ok(cargo) = std::env::var("CARGO_HOME") {
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn execute_app(
let args = builder.build();
log::debug!("{args:#?}");

cargo::run_with_input(&args, package_path)
cargo::run(&args, package_path)
}

/// Build the specified package, using the given toolchain/target/features if
Expand Down
Loading

0 comments on commit df2b7bd

Please sign in to comment.