xtask: allow arbitrary flags to cargo build

pull/687/head
Tamir Duberstein 1 year ago committed by Andrew Werner
parent 5ebaf5f393
commit a6b1fb9a1e

@ -1,4 +1,5 @@
use std::{ use std::{
ffi::OsString,
fmt::Write as _, fmt::Write as _,
io::BufReader, io::BufReader,
path::PathBuf, path::PathBuf,
@ -12,12 +13,9 @@ use xtask::AYA_BUILD_INTEGRATION_BPF;
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct BuildOptions { pub struct BuildOptions {
/// Pass --release to `cargo build`. /// Arguments to pass to `cargo build`.
#[clap(long)] #[clap(long)]
pub release: bool, pub cargo_arg: Vec<OsString>,
/// Pass --target to `cargo build`.
#[clap(long)]
pub target: Option<String>,
} }
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
@ -28,26 +26,22 @@ pub struct Options {
#[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(last = true)]
pub run_args: Vec<String>, pub run_args: Vec<OsString>,
} }
/// Build the project /// Build the project
pub fn build(opts: BuildOptions) -> Result<Vec<(String, PathBuf)>> { pub fn build(opts: BuildOptions) -> Result<Vec<(String, PathBuf)>> {
let BuildOptions { release, target } = opts; let BuildOptions { cargo_arg } = opts;
let mut cmd = Command::new("cargo"); let mut cmd = Command::new("cargo");
cmd.env(AYA_BUILD_INTEGRATION_BPF, "true").args([ cmd.env(AYA_BUILD_INTEGRATION_BPF, "true")
"build", .args([
"--tests", "build",
"--message-format=json", "--tests",
"--package=integration-test", "--message-format=json",
]); "--package=integration-test",
if release { ])
cmd.arg("--release"); .args(cargo_arg);
}
if let Some(target) = target {
cmd.args(["--target", &target]);
}
let mut child = cmd let mut child = cmd
.stdout(Stdio::piped()) .stdout(Stdio::piped())

Loading…
Cancel
Save