]>
Commit | Line | Data |
---|---|---|
04454e1e FG |
1 | #![feature(let_chains)] |
2 | #![feature(let_else)] | |
f20569fa | 3 | #![feature(once_cell)] |
04454e1e | 4 | #![feature(rustc_private)] |
17df50a5 XL |
5 | #![cfg_attr(feature = "deny-warnings", deny(warnings))] |
6 | // warn on lints, that are included in `rust-lang/rust`s bootstrap | |
7 | #![warn(rust_2018_idioms, unused_lifetimes)] | |
f20569fa | 8 | |
04454e1e FG |
9 | extern crate rustc_lexer; |
10 | ||
c295e0f8 | 11 | use std::path::PathBuf; |
f20569fa XL |
12 | |
13 | pub mod bless; | |
14 | pub mod fmt; | |
a2a8927a | 15 | pub mod lint; |
f20569fa | 16 | pub mod new_lint; |
f20569fa | 17 | pub mod serve; |
136023e0 | 18 | pub mod setup; |
f20569fa XL |
19 | pub mod update_lints; |
20 | ||
04454e1e FG |
21 | #[cfg(not(windows))] |
22 | static CARGO_CLIPPY_EXE: &str = "cargo-clippy"; | |
23 | #[cfg(windows)] | |
24 | static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe"; | |
25 | ||
26 | /// Returns the path to the `cargo-clippy` binary | |
27 | #[must_use] | |
28 | pub fn cargo_clippy_path() -> PathBuf { | |
29 | let mut path = std::env::current_exe().expect("failed to get current executable name"); | |
30 | path.set_file_name(CARGO_CLIPPY_EXE); | |
31 | path | |
32 | } | |
33 | ||
f20569fa XL |
34 | /// Returns the path to the Clippy project directory |
35 | /// | |
36 | /// # Panics | |
37 | /// | |
38 | /// Panics if the current directory could not be retrieved, there was an error reading any of the | |
39 | /// Cargo.toml files or ancestor directory is the clippy root directory | |
40 | #[must_use] | |
41 | pub fn clippy_project_root() -> PathBuf { | |
42 | let current_dir = std::env::current_dir().unwrap(); | |
43 | for path in current_dir.ancestors() { | |
44 | let result = std::fs::read_to_string(path.join("Cargo.toml")); | |
45 | if let Err(err) = &result { | |
46 | if err.kind() == std::io::ErrorKind::NotFound { | |
47 | continue; | |
48 | } | |
49 | } | |
50 | ||
51 | let content = result.unwrap(); | |
52 | if content.contains("[package]\nname = \"clippy\"") { | |
53 | return path.to_path_buf(); | |
54 | } | |
55 | } | |
56 | panic!("error: Can't determine root of project. Please run inside a Clippy working dir."); | |
57 | } |