-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clippy command to xtask #128
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
76f1d2c
Add clippy support to xtask check
smklein e67dbb0
Merge branch 'master' into clippy
smklein abac873
Separate clippy from check task
smklein c5cb79b
Merge branch 'master' into clippy
smklein c82eab0
Allow a limited set of lints
smklein d416006
Merge branch 'master' into clippy
smklein 11926b5
Merge branch 'master' into clippy
smklein 3963743
Merge branch 'master' into clippy
smklein 0078616
Merge branch 'master' into clippy
smklein 1c2ff1b
Merge branch 'master' into clippy
smklein 2283c74
Merge branch 'master' into clippy
smklein 4f12023
Merge branch 'master' into clippy
smklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,63 @@ | ||
use std::env; | ||
use std::process::Command; | ||
|
||
use anyhow::{bail, Result}; | ||
|
||
pub fn run(package: Option<String>, target: Option<String>) -> Result<()> { | ||
let package = package.unwrap_or_else(|| { | ||
let path = env::current_dir().unwrap(); | ||
let manifest_path = path.join("Cargo.toml"); | ||
let contents = std::fs::read(manifest_path).unwrap(); | ||
let toml: toml::Value = toml::from_slice(&contents).unwrap(); | ||
|
||
// someday, try blocks will be stable... | ||
toml.get("package") | ||
.and_then(|v| v.get("name")) | ||
.and_then(|v| v.as_str()) | ||
.expect("Couldn't find [package.name]; pass -p <package> to run clippy on a specific package or --all to check all packages") | ||
.to_string() | ||
}); | ||
|
||
println!("Running clippy on: {}", package); | ||
|
||
let mut cmd = Command::new("cargo"); | ||
cmd.arg("clippy"); | ||
// TODO: Remove this argument once resolved on stable: | ||
// | ||
// https://github.com/rust-lang/rust-clippy/issues/4612 | ||
// | ||
// TL;DR: Switching back and forth between "clippy" and "check" | ||
// caches the results from one execution. This means a succeeding | ||
// "check" execution may hide a failing "clippy" execution. | ||
cmd.arg("-Zunstable-options"); | ||
cmd.arg("-p"); | ||
cmd.arg(&package); | ||
|
||
if let Some(target) = target { | ||
cmd.arg("--target"); | ||
cmd.arg(target); | ||
} | ||
|
||
// Clippy arguments | ||
cmd.arg("--"); | ||
cmd.arg("-D"); | ||
cmd.arg("clippy::all"); | ||
cmd.arg("-A"); | ||
cmd.arg("clippy::missing_safety_doc"); | ||
cmd.arg("-A"); | ||
cmd.arg("clippy::identity_op"); | ||
cmd.arg("-A"); | ||
cmd.arg("clippy::too_many_arguments"); | ||
|
||
// this is only actually used for demo-stm32h7 but is harmless to include, so let's do | ||
// it unconditionally | ||
cmd.env("HUBRIS_BOARD", "nucleo-h743zi2"); | ||
|
||
let status = cmd.status()?; | ||
|
||
if !status.success() { | ||
bail!("Could not build {}", package); | ||
} | ||
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm. This information comes from the app.toml normally. It would be nice to be able to run clippy on an app. That doesn't need to happen in this change though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, full transparency, this was basically lifted exactly from
xtask/src/check.rs
. I also see it being set inxtask/src/dist.rs
when "HUBRIS_BOARD" is set before running rustc - how is this extracted from app.toml files?