|
|
@ -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<_>>();
|
|
|
|