Skip to content

Commit a846945

Browse files
committed
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.
1 parent 2546e6f commit a846945

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lintcheck/src/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Run clippy on a fixed set of crates and collect the warnings.
2-
// This helps observing the impact clippy changes have on a set of real-world code (and not just our testsuite).
2+
// This helps observing the impact clippy changes have on a set of real-world code (and not just our
3+
// testsuite).
34
//
45
// When a new lint is introduced, we can search the results for new warnings and check for false
56
// positives.
@@ -556,12 +557,29 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
556557
logs_modified < clippy_modified
557558
}
558559

560+
fn is_in_clippy_root() -> bool {
561+
if let Ok(pb) = std::env::current_dir() {
562+
if let Some(file) = pb.file_name() {
563+
return file == PathBuf::from("rust-clippy");
564+
}
565+
}
566+
567+
false
568+
}
569+
559570
/// lintchecks `main()` function
560571
///
561572
/// # Panics
562573
///
563-
/// This function panics if the clippy binaries don't exist.
574+
/// This function panics if the clippy binaries don't exist
575+
/// or if lintcheck is executed from the wrong directory (aka none-repo-root)
564576
pub fn main() {
577+
// assert that we launch lintcheck from the repo root (via cargo dev-lintcheck)
578+
if !is_in_clippy_root() {
579+
eprintln!("lintcheck needs to be run from clippys repo root!\nUse `cargo dev-lintcheck` alternatively.");
580+
std::process::exit(3);
581+
}
582+
565583
let clap_config = &get_clap_config();
566584

567585
let config = LintcheckConfig::from_clap(clap_config);

0 commit comments

Comments
 (0)