Skip to content

Commit

Permalink
feat(xtask): adds xtask lint and xtask test
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed May 26, 2021
1 parent cea8b15 commit 6e2a607
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 60 deletions.
5 changes: 5 additions & 0 deletions crates/xtask/src/commands/cargo/mod.rs
@@ -0,0 +1,5 @@
mod runner;
mod target;

pub(crate) use runner::CargoRunner;
pub(crate) use target::{Target, POSSIBLE_TARGETS};
66 changes: 66 additions & 0 deletions crates/xtask/src/commands/cargo/runner.rs
@@ -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.
42 changes: 0 additions & 42 deletions crates/xtask/src/commands/dist/build.rs

This file was deleted.

9 changes: 3 additions & 6 deletions crates/xtask/src/commands/dist/mod.rs
@@ -1,9 +1,6 @@
mod build;
mod strip;
mod target;

use build::CargoRunner;
use target::{Target, POSSIBLE_TARGETS};
use crate::commands::{CargoRunner, Target, POSSIBLE_TARGETS};

use anyhow::{Context, Result};
use structopt::StructOpt;
Expand All @@ -18,9 +15,9 @@ pub struct Dist {

impl Dist {
pub fn run(&self, verbose: bool) -> Result<()> {
let cargo_runner = CargoRunner::new(&self.target.to_owned(), verbose)?;
let cargo_runner = CargoRunner::new(verbose)?;
let binary_path = cargo_runner
.build()
.build(self.target.to_owned())
.with_context(|| "Could not build Rover.")?;

let strip_runner = StripRunner::new(binary_path, verbose);
Expand Down
9 changes: 4 additions & 5 deletions crates/xtask/src/commands/lint.rs
@@ -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(())
}
}
2 changes: 2 additions & 0 deletions crates/xtask/src/commands/mod.rs
@@ -1,8 +1,10 @@
mod cargo;
pub(crate) mod dist;
pub(crate) mod lint;
pub(crate) mod prep;
pub(crate) mod test;

pub(crate) use cargo::{CargoRunner, Target, POSSIBLE_TARGETS};
pub(crate) use dist::Dist;
pub(crate) use lint::Lint;
pub(crate) use prep::Prep;
Expand Down
16 changes: 9 additions & 7 deletions crates/xtask/src/commands/test.rs
@@ -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(())
}
}

0 comments on commit 6e2a607

Please sign in to comment.