xtask: reimplement build-integration-test

This command builds the integration test binaries and prints their paths
to stdout.
pull/644/head
Tamir Duberstein 1 year ago
parent c76d5a9950
commit 9086265ac0
No known key found for this signature in database

@ -3,6 +3,7 @@ mod docs;
mod run; mod run;
use clap::Parser; use clap::Parser;
#[derive(Parser)] #[derive(Parser)]
pub struct XtaskOptions { pub struct XtaskOptions {
#[clap(subcommand)] #[clap(subcommand)]
@ -13,6 +14,7 @@ pub struct XtaskOptions {
enum Command { enum Command {
Codegen(codegen::Options), Codegen(codegen::Options),
Docs, Docs,
BuildIntegrationTest(run::BuildOptions),
IntegrationTest(run::Options), IntegrationTest(run::Options),
} }
@ -22,6 +24,17 @@ fn main() -> anyhow::Result<()> {
match command { match command {
Command::Codegen(opts) => codegen::codegen(opts), Command::Codegen(opts) => codegen::codegen(opts),
Command::Docs => docs::docs(), 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), Command::IntegrationTest(opts) => run::run(opts),
} }
} }

@ -10,20 +10,30 @@ use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
use clap::Parser; use clap::Parser;
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct Options { pub struct BuildOptions {
/// Build and run the release target /// Pass --release to `cargo build`.
#[clap(long)] #[clap(long)]
pub release: bool, pub release: bool,
/// The command used to wrap your application /// Pass --target to `cargo build`.
#[clap(long)]
pub target: Option<String>,
}
#[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")] #[clap(short, long, default_value = "sudo -E")]
pub runner: String, pub runner: String,
/// Arguments to pass to your application /// Arguments to pass to your application.
#[clap(name = "args", last = true)] #[clap(name = "args", last = true)]
pub run_args: Vec<String>, pub run_args: Vec<String>,
} }
/// Build the project /// Build the project
fn build(release: bool) -> Result<Vec<(String, PathBuf)>> { pub fn build(opts: BuildOptions) -> Result<Vec<(String, PathBuf)>> {
let BuildOptions { release, target } = opts;
let mut cmd = Command::new("cargo"); let mut cmd = Command::new("cargo");
cmd.args([ cmd.args([
"build", "build",
@ -34,6 +44,9 @@ fn build(release: bool) -> Result<Vec<(String, PathBuf)>> {
if release { if release {
cmd.arg("--release"); cmd.arg("--release");
} }
if let Some(target) = target {
cmd.args(["--target", &target]);
}
let mut cmd = cmd let mut cmd = cmd
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()
@ -80,12 +93,12 @@ fn build(release: bool) -> Result<Vec<(String, PathBuf)>> {
/// Build and run the project /// Build and run the project
pub fn run(opts: Options) -> Result<()> { pub fn run(opts: Options) -> Result<()> {
let Options { let Options {
release, build_options,
runner, runner,
run_args, run_args,
} = opts; } = 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 mut args = runner.trim().split_terminator(' ');
let runner = args.next().ok_or(anyhow::anyhow!("no first argument"))?; let runner = args.next().ok_or(anyhow::anyhow!("no first argument"))?;
let args = args.collect::<Vec<_>>(); let args = args.collect::<Vec<_>>();

Loading…
Cancel
Save