// Copyright (c) The Diem Core Contributors // SPDX-License-Identifier: Apache-2.0 use crate::{ cargo::{selected_package::SelectedPackageArgs, CargoCommand}, context::XContext, Result, }; use std::ffi::OsString; use structopt::StructOpt; #[derive(Debug, StructOpt)] pub struct Args { #[structopt(flatten)] package_args: SelectedPackageArgs, /// Do not run the benchmarks, but compile them #[structopt(long)] no_run: bool, #[structopt(name = "BENCHNAME", parse(from_os_str))] benchname: Option, #[structopt(name = "ARGS", parse(from_os_str), last = true)] args: Vec, } pub fn run(mut args: Args, xctx: XContext) -> Result<()> { args.args.extend(args.benchname.clone()); let mut direct_args = Vec::new(); if args.no_run { direct_args.push(OsString::from("--no-run")); }; let cmd = CargoCommand::Bench { cargo_config: xctx.config().cargo_config(), direct_args: direct_args.as_slice(), args: &args.args, env: &[], }; let packages = args.package_args.to_selected_packages(&xctx)?; cmd.run_on_packages(&packages) }