From 9086265ac0f11c35686d09f6ec699c95e21658b4 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 10 Jul 2023 22:17:05 -0400 Subject: [PATCH] xtask: reimplement build-integration-test This command builds the integration test binaries and prints their paths to stdout. --- xtask/src/main.rs | 13 +++++++++++++ xtask/src/run.rs | 27 ++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4a7736c8..47b425e4 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -3,6 +3,7 @@ mod docs; mod run; use clap::Parser; + #[derive(Parser)] pub struct XtaskOptions { #[clap(subcommand)] @@ -13,6 +14,7 @@ pub struct XtaskOptions { enum Command { Codegen(codegen::Options), Docs, + BuildIntegrationTest(run::BuildOptions), IntegrationTest(run::Options), } @@ -22,6 +24,17 @@ fn main() -> anyhow::Result<()> { match command { Command::Codegen(opts) => codegen::codegen(opts), Command::Docs => docs::docs(), + Command::BuildIntegrationTest(opts) => { + let binaries = run::build(opts)?; + let mut stdout = std::io::stdout(); + for (_name, binary) in binaries { + use std::{io::Write as _, os::unix::ffi::OsStrExt as _}; + + stdout.write_all(binary.as_os_str().as_bytes())?; + stdout.write_all("\n".as_bytes())?; + } + Ok(()) + } Command::IntegrationTest(opts) => run::run(opts), } } diff --git a/xtask/src/run.rs b/xtask/src/run.rs index 8cefcf5f..36e4c40f 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -10,20 +10,30 @@ use cargo_metadata::{Artifact, CompilerMessage, Message, Target}; use clap::Parser; #[derive(Debug, Parser)] -pub struct Options { - /// Build and run the release target +pub struct BuildOptions { + /// Pass --release to `cargo build`. #[clap(long)] pub release: bool, - /// The command used to wrap your application + /// Pass --target to `cargo build`. + #[clap(long)] + pub target: Option, +} + +#[derive(Debug, Parser)] +pub struct Options { + #[command(flatten)] + pub build_options: BuildOptions, + /// The command used to wrap your application. #[clap(short, long, default_value = "sudo -E")] pub runner: String, - /// Arguments to pass to your application + /// Arguments to pass to your application. #[clap(name = "args", last = true)] pub run_args: Vec, } /// Build the project -fn build(release: bool) -> Result> { +pub fn build(opts: BuildOptions) -> Result> { + let BuildOptions { release, target } = opts; let mut cmd = Command::new("cargo"); cmd.args([ "build", @@ -34,6 +44,9 @@ fn build(release: bool) -> Result> { if release { cmd.arg("--release"); } + if let Some(target) = target { + cmd.args(["--target", &target]); + } let mut cmd = cmd .stdout(Stdio::piped()) .spawn() @@ -80,12 +93,12 @@ fn build(release: bool) -> Result> { /// Build and run the project pub fn run(opts: Options) -> Result<()> { let Options { - release, + build_options, runner, run_args, } = opts; - let binaries = build(release).context("error while building userspace application")?; + let binaries = build(build_options).context("error while building userspace application")?; let mut args = runner.trim().split_terminator(' '); let runner = args.next().ok_or(anyhow::anyhow!("no first argument"))?; let args = args.collect::>();