-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1604e18
commit 09e9d8d
Showing
8 changed files
with
108 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,8 @@ | ||
[package] | ||
name = "xtask" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
clap.workspace = true |
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,72 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Workspace-related developer tools | ||
//! | ||
//! See <https://github.com/matklad/cargo-xtask>. | ||
use anyhow::{bail, Context, Result}; | ||
use clap::{Parser, Subcommand}; | ||
use std::process::Command; | ||
|
||
#[derive(Parser)] | ||
#[command(name = "cargo xtask", about = "Workspace-related developer tools")] | ||
struct Args { | ||
#[command(subcommand)] | ||
cmd: Cmds, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
enum Cmds { | ||
/// Run configured clippy checks | ||
Clippy, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
match args.cmd { | ||
Cmds::Clippy => cmd_clippy(), | ||
} | ||
} | ||
|
||
fn cmd_clippy() -> Result<()> { | ||
let cargo = | ||
std::env::var("CARGO").unwrap_or_else(|_| String::from("cargo")); | ||
let mut command = Command::new(&cargo); | ||
command | ||
.arg("clippy") | ||
// Make sure we check everything. | ||
.arg("--all-targets") | ||
.arg("--") | ||
// We disallow warnings by default. | ||
.arg("--deny") | ||
.arg("warnings") | ||
// Clippy's style nits are useful, but not worth keeping in CI. This | ||
// override belongs in src/lib.rs, and it is there, but that doesn't | ||
// reliably work due to rust-lang/rust-clippy#6610. | ||
.arg("--allow") | ||
.arg("clippy::style"); | ||
|
||
eprintln!( | ||
"running: {:?} {}", | ||
&cargo, | ||
command | ||
.get_args() | ||
.map(|arg| format!("{:?}", arg.to_str().unwrap())) | ||
.collect::<Vec<_>>() | ||
.join(" ") | ||
); | ||
|
||
let exit_status = command | ||
.spawn() | ||
.context("failed to spawn child process")? | ||
.wait() | ||
.context("failed to wait for child process")?; | ||
|
||
if !exit_status.success() { | ||
bail!("clippy failed: {}", exit_status); | ||
} | ||
|
||
Ok(()) | ||
} |