Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xtask): adds xtask lint and xtask test
- Loading branch information
1 parent
cea8b15
commit 6e2a607
Showing
8 changed files
with
89 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod runner; | ||
mod target; | ||
|
||
pub(crate) use runner::CargoRunner; | ||
pub(crate) use target::{Target, POSSIBLE_TARGETS}; |
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,66 @@ | ||
use anyhow::Result; | ||
use camino::Utf8PathBuf; | ||
|
||
use crate::commands::Target; | ||
use crate::utils::{self, CommandOutput}; | ||
|
||
pub(crate) struct CargoRunner { | ||
rover_package_directory: Utf8PathBuf, | ||
verbose: bool, | ||
} | ||
|
||
impl CargoRunner { | ||
pub(crate) fn new(verbose: bool) -> Result<Self> { | ||
let rover_package_directory = utils::project_root()?; | ||
|
||
Ok(CargoRunner { | ||
rover_package_directory, | ||
verbose, | ||
}) | ||
} | ||
|
||
pub(crate) fn build(&self, target: Target) -> Result<Utf8PathBuf> { | ||
let target_str = target.to_string(); | ||
let mut args = vec!["build", "--release", "--target", &target_str]; | ||
if !target.composition_js() { | ||
args.push("--no-default-features"); | ||
} | ||
self.cargo_exec(&args)?; | ||
Ok(self | ||
.rover_package_directory | ||
.join("target") | ||
.join(&target_str) | ||
.join("release") | ||
.join("rover")) | ||
} | ||
|
||
pub(crate) fn lint(&self) -> Result<()> { | ||
self.cargo_exec(&["fmt", "--all", "--", "--check"])?; | ||
self.cargo_exec(&["clippy", "--all", "--", "-D", "warnings"])?; | ||
self.cargo_exec(&[ | ||
"clippy", | ||
"--all", | ||
"--no-default-features", | ||
"--", | ||
"-D", | ||
"warnings", | ||
])?; | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn test(&self, target: Target) -> Result<()> { | ||
self.lint()?; | ||
let target_str = target.to_string(); | ||
let mut args = vec!["test", "--workspace", "--locked", "--target", &target_str]; | ||
if !target.composition_js() { | ||
args.push("--no-default-features"); | ||
} | ||
self.cargo_exec(&args)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn cargo_exec(&self, args: &[&str]) -> Result<CommandOutput> { | ||
utils::exec("cargo", args, &self.rover_package_directory, self.verbose) | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use anyhow::Result; | ||
use structopt::StructOpt; | ||
|
||
use crate::utils; | ||
use crate::commands::CargoRunner; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub struct Lint {} | ||
|
||
impl Lint { | ||
pub fn run(&self, _verbose: bool) -> Result<()> { | ||
utils::info("TODO: run cargo fmt --check"); | ||
utils::info("TODO: run cargo clippy --check"); | ||
|
||
pub fn run(&self, verbose: bool) -> Result<()> { | ||
let cargo_runner = CargoRunner::new(verbose)?; | ||
cargo_runner.lint()?; | ||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
use anyhow::Result; | ||
use structopt::StructOpt; | ||
|
||
use crate::utils; | ||
use crate::commands::CargoRunner; | ||
use crate::commands::{Target, POSSIBLE_TARGETS}; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub struct Test {} | ||
pub struct Test { | ||
#[structopt(long = "target", possible_values = &POSSIBLE_TARGETS)] | ||
target: Target, | ||
} | ||
|
||
impl Test { | ||
pub fn run(&self, _verbose: bool) -> Result<()> { | ||
utils::info("TODO: run cargo test --workspace --locked --target {target}"); | ||
utils::info( | ||
"TODO: run cargo test --workspace --locked --no-default-features --target {target}", | ||
); | ||
pub fn run(&self, verbose: bool) -> Result<()> { | ||
let cargo_runner = CargoRunner::new(verbose)?; | ||
cargo_runner.test(self.target.to_owned())?; | ||
Ok(()) | ||
} | ||
} |