From a846945b82f1bfe5f01aff6688927ddb5f4b2514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 9 Mar 2021 14:06:42 +0100 Subject: [PATCH] lintcheck: make sure we lauch from the repo root This will terminate the program if run via "cargo run". "cargo run" does currently not work because at least a bunch of paths do not take that into account. --- lintcheck/src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index f5a54cfa8dc..e6b2d49cfef 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -1,5 +1,6 @@ // Run clippy on a fixed set of crates and collect the warnings. -// This helps observing the impact clippy changes have on a set of real-world code (and not just our testsuite). +// This helps observing the impact clippy changes have on a set of real-world code (and not just our +// testsuite). // // When a new lint is introduced, we can search the results for new warnings and check for false // positives. @@ -556,12 +557,29 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool { logs_modified < clippy_modified } +fn is_in_clippy_root() -> bool { + if let Ok(pb) = std::env::current_dir() { + if let Some(file) = pb.file_name() { + return file == PathBuf::from("rust-clippy"); + } + } + + false +} + /// lintchecks `main()` function /// /// # Panics /// -/// This function panics if the clippy binaries don't exist. +/// This function panics if the clippy binaries don't exist +/// or if lintcheck is executed from the wrong directory (aka none-repo-root) pub fn main() { + // assert that we launch lintcheck from the repo root (via cargo dev-lintcheck) + if !is_in_clippy_root() { + eprintln!("lintcheck needs to be run from clippys repo root!\nUse `cargo dev-lintcheck` alternatively."); + std::process::exit(3); + } + let clap_config = &get_clap_config(); let config = LintcheckConfig::from_clap(clap_config);