Skip to content

Commit c6911a0

Browse files
committed
Support different lintcheck CARGO_TARGET_DIR
1 parent d4e7e5b commit c6911a0

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

lintcheck/src/input.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88
use serde::Deserialize;
99
use walkdir::{DirEntry, WalkDir};
1010

11-
use crate::{Crate, LINTCHECK_DOWNLOADS, LINTCHECK_SOURCES};
11+
use crate::{Crate, lintcheck_downloads, lintcheck_sources, target_dir};
1212

1313
const DEFAULT_DOCS_LINK: &str = "https://docs.rs/{krate}/{version}/src/{krate_}/{file}.html#{line}";
1414
const DEFAULT_GITHUB_LINK: &str = "{url}/blob/{hash}/src/{file}#L{line}";
@@ -201,8 +201,8 @@ impl CrateWithSource {
201201
let file_link = &self.file_link;
202202
match &self.source {
203203
CrateSource::CratesIo { version } => {
204-
let extract_dir = PathBuf::from(LINTCHECK_SOURCES);
205-
let krate_download_dir = PathBuf::from(LINTCHECK_DOWNLOADS);
204+
let extract_dir = PathBuf::from(lintcheck_sources());
205+
let krate_download_dir = PathBuf::from(lintcheck_downloads());
206206

207207
// url to download the crate from crates.io
208208
let url = format!("https://crates.io/api/v1/crates/{name}/{version}/download");
@@ -236,7 +236,7 @@ impl CrateWithSource {
236236
},
237237
CrateSource::Git { url, commit } => {
238238
let repo_path = {
239-
let mut repo_path = PathBuf::from(LINTCHECK_SOURCES);
239+
let mut repo_path = PathBuf::from(lintcheck_sources());
240240
// add a -git suffix in case we have the same crate from crates.io and a git repo
241241
repo_path.push(format!("{name}-git"));
242242
repo_path
@@ -286,7 +286,7 @@ impl CrateWithSource {
286286
// copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
287287
// The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
288288
// as a result of this filter.
289-
let dest_crate_root = PathBuf::from(LINTCHECK_SOURCES).join(name);
289+
let dest_crate_root = PathBuf::from(lintcheck_sources()).join(name);
290290
if dest_crate_root.exists() {
291291
println!("Deleting existing directory at `{}`", dest_crate_root.display());
292292
fs::remove_dir_all(&dest_crate_root).unwrap();
@@ -326,7 +326,7 @@ impl CrateWithSource {
326326
///
327327
/// This function panics if creating one of the dirs fails.
328328
fn create_dirs(krate_download_dir: &Path, extract_dir: &Path) {
329-
fs::create_dir("target/lintcheck/").unwrap_or_else(|err| {
329+
fs::create_dir(format!("{}/lintcheck/", target_dir())).unwrap_or_else(|err| {
330330
assert_eq!(
331331
err.kind(),
332332
ErrorKind::AlreadyExists,

lintcheck/src/main.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ use input::read_crates;
4343
use output::{ClippyCheckOutput, ClippyWarning, RustcIce};
4444
use rayon::prelude::*;
4545

46-
const LINTCHECK_DOWNLOADS: &str = "target/lintcheck/downloads";
47-
const LINTCHECK_SOURCES: &str = "target/lintcheck/sources";
46+
#[must_use]
47+
pub fn target_dir() -> String {
48+
env::var("CARGO_TARGET_DIR").unwrap_or("target".to_owned())
49+
}
50+
51+
fn lintcheck_downloads() -> String {
52+
format!("{}/lintcheck/downloads", target_dir())
53+
}
54+
55+
fn lintcheck_sources() -> String {
56+
format!("{}/lintcheck/sources", target_dir())
57+
}
4858

4959
/// Represents the actual source code of a crate that we ran "cargo clippy" on
5060
#[derive(Debug)]
@@ -307,15 +317,17 @@ fn main() {
307317
fn lintcheck(config: LintcheckConfig) {
308318
let clippy_ver = build_clippy(config.perf);
309319
let clippy_driver_path = fs::canonicalize(format!(
310-
"target/{}/clippy-driver{EXE_SUFFIX}",
320+
"{}/{}/clippy-driver{EXE_SUFFIX}",
321+
target_dir(),
311322
if config.perf { "release" } else { "debug" }
312323
))
313324
.unwrap();
314325

315326
// assert that clippy is found
316327
assert!(
317328
clippy_driver_path.is_file(),
318-
"target/{}/clippy-driver binary not found! {}",
329+
"{}/{}/clippy-driver binary not found! {}",
330+
target_dir(),
319331
if config.perf { "release" } else { "debug" },
320332
clippy_driver_path.display()
321333
);
@@ -386,7 +398,7 @@ fn lintcheck(config: LintcheckConfig) {
386398
.unwrap();
387399

388400
let server = config.recursive.then(|| {
389-
let _: io::Result<()> = fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive");
401+
let _: io::Result<()> = fs::remove_dir_all(format!("{}/lintcheck/shared_target_dir/recursive", target_dir()));
390402

391403
LintcheckServer::spawn(recursive_options)
392404
});
@@ -488,7 +500,7 @@ fn clippy_project_root() -> &'static Path {
488500
#[must_use]
489501
fn shared_target_dir(qualifier: &str) -> PathBuf {
490502
clippy_project_root()
491-
.join("target/lintcheck/shared_target_dir")
503+
.join(format!("{}/lintcheck/shared_target_dir", target_dir()))
492504
.join(qualifier)
493505
}
494506

0 commit comments

Comments
 (0)