-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This improves generated commands.
- Loading branch information
Showing
4 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::ffi::OsStr; | ||
|
||
use clap::Args; | ||
use xshell::Cmd; | ||
|
||
use crate::artifact::Artifact; | ||
|
||
#[derive(Args)] | ||
pub struct CargoBuild { | ||
#[command(flatten)] | ||
pub artifact: Artifact, | ||
|
||
/// Do not activate the `default` feature. | ||
#[arg(long)] | ||
no_default_features: bool, | ||
|
||
/// Space or comma separated list of features to activate. | ||
#[arg(long)] | ||
features: Vec<String>, | ||
} | ||
|
||
pub trait CmdExt { | ||
fn cargo_build_args(self, cargo_build: &CargoBuild) -> Self; | ||
fn target_dir_args(self, cargo_build: &CargoBuild) -> Self; | ||
} | ||
|
||
impl CmdExt for Cmd<'_> { | ||
fn cargo_build_args(self, cargo_build: &CargoBuild) -> Self { | ||
let cmd = self | ||
.target_dir_args(cargo_build) | ||
.args(cargo_build.no_default_features_args()) | ||
.args(cargo_build.features_args()) | ||
.args(cargo_build.release_args()); | ||
|
||
if let Some(profile) = &cargo_build.artifact.profile { | ||
cmd.args(&["--profile", profile]) | ||
} else { | ||
cmd | ||
} | ||
} | ||
|
||
fn target_dir_args(self, cargo_build: &CargoBuild) -> Self { | ||
if let Some(target_dir) = &cargo_build.artifact.target_dir { | ||
self.args::<&[&OsStr]>(&["--target-dir".as_ref(), target_dir.as_ref()]) | ||
} else { | ||
self | ||
} | ||
} | ||
} | ||
|
||
impl CargoBuild { | ||
fn release_args(&self) -> &'static [&'static str] { | ||
if self.artifact.release { | ||
&["--release"] | ||
} else { | ||
&[] | ||
} | ||
} | ||
|
||
fn no_default_features_args(&self) -> &'static [&'static str] { | ||
if self.no_default_features { | ||
&["--no-default-features"] | ||
} else { | ||
&[] | ||
} | ||
} | ||
|
||
fn features_args(&self) -> impl Iterator<Item = &str> { | ||
self.features | ||
.iter() | ||
.flat_map(|feature| ["--features", feature.as_str()]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ mod arch; | |
mod archive; | ||
mod artifact; | ||
mod build; | ||
mod cargo_build; | ||
mod clippy; | ||
|
||
use std::path::Path; | ||
|