Lintcheck: Normalize thread IDs in shared_target_dir
This commit is contained in:
parent
9d82fb460a
commit
46ebe0cb68
@ -6,6 +6,7 @@
|
|||||||
// positives.
|
// positives.
|
||||||
|
|
||||||
#![feature(iter_collect_into)]
|
#![feature(iter_collect_into)]
|
||||||
|
#![feature(let_chains)]
|
||||||
#![warn(
|
#![warn(
|
||||||
trivial_casts,
|
trivial_casts,
|
||||||
trivial_numeric_casts,
|
trivial_numeric_casts,
|
||||||
@ -87,8 +88,6 @@ impl Crate {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
|
|
||||||
|
|
||||||
let cargo_home = env!("CARGO_HOME");
|
let cargo_home = env!("CARGO_HOME");
|
||||||
|
|
||||||
// `src/lib.rs` -> `target/lintcheck/sources/crate-1.2.3/src/lib.rs`
|
// `src/lib.rs` -> `target/lintcheck/sources/crate-1.2.3/src/lib.rs`
|
||||||
@ -132,7 +131,7 @@ impl Crate {
|
|||||||
// The wrapper is set to `lintcheck` itself so we can force enable linting and ignore certain crates
|
// The wrapper is set to `lintcheck` itself so we can force enable linting and ignore certain crates
|
||||||
// (see `crate::driver`)
|
// (see `crate::driver`)
|
||||||
let status = cmd
|
let status = cmd
|
||||||
.env("CARGO_TARGET_DIR", shared_target_dir.join("recursive"))
|
.env("CARGO_TARGET_DIR", shared_target_dir("recursive"))
|
||||||
.env("RUSTC_WRAPPER", env::current_exe().unwrap())
|
.env("RUSTC_WRAPPER", env::current_exe().unwrap())
|
||||||
// Pass the absolute path so `crate::driver` can find `clippy-driver`, as it's executed in various
|
// Pass the absolute path so `crate::driver` can find `clippy-driver`, as it's executed in various
|
||||||
// different working directories
|
// different working directories
|
||||||
@ -150,9 +149,10 @@ impl Crate {
|
|||||||
cmd.arg("--message-format=json");
|
cmd.arg("--message-format=json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let shared_target_dir = shared_target_dir(&format!("_{thread_index:?}"));
|
||||||
let all_output = cmd
|
let all_output = cmd
|
||||||
// use the looping index to create individual target dirs
|
// use the looping index to create individual target dirs
|
||||||
.env("CARGO_TARGET_DIR", shared_target_dir.join(format!("_{thread_index:?}")))
|
.env("CARGO_TARGET_DIR", shared_target_dir.as_os_str())
|
||||||
// Roughly equivalent to `cargo clippy`/`cargo clippy --fix`
|
// Roughly equivalent to `cargo clippy`/`cargo clippy --fix`
|
||||||
.env("RUSTC_WORKSPACE_WRAPPER", clippy_driver_path)
|
.env("RUSTC_WORKSPACE_WRAPPER", clippy_driver_path)
|
||||||
.output()
|
.output()
|
||||||
@ -186,7 +186,10 @@ impl Crate {
|
|||||||
// get all clippy warnings and ICEs
|
// get all clippy warnings and ICEs
|
||||||
let mut entries: Vec<ClippyCheckOutput> = Message::parse_stream(stdout.as_bytes())
|
let mut entries: Vec<ClippyCheckOutput> = Message::parse_stream(stdout.as_bytes())
|
||||||
.filter_map(|msg| match msg {
|
.filter_map(|msg| match msg {
|
||||||
Ok(Message::CompilerMessage(message)) => ClippyWarning::new(message.message, &self.base_url),
|
Ok(Message::CompilerMessage(message)) => ClippyWarning::new(
|
||||||
|
normalize_diag(message.message, shared_target_dir.to_str().unwrap()),
|
||||||
|
&self.base_url,
|
||||||
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(ClippyCheckOutput::ClippyWarning)
|
.map(ClippyCheckOutput::ClippyWarning)
|
||||||
@ -202,6 +205,31 @@ impl Crate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The target directory can sometimes be stored in the file name of spans.
|
||||||
|
/// This is problematic since the directory in constructed from the thread
|
||||||
|
/// ID and also used in our CI to determine if two lint emissions are the
|
||||||
|
/// same or not. This function simply normalizes the `_<thread_id>` to `_*`.
|
||||||
|
fn normalize_diag(
|
||||||
|
mut message: cargo_metadata::diagnostic::Diagnostic,
|
||||||
|
thread_target_dir: &str,
|
||||||
|
) -> cargo_metadata::diagnostic::Diagnostic {
|
||||||
|
let mut dir_found = false;
|
||||||
|
message
|
||||||
|
.spans
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|span| span.file_name.starts_with(thread_target_dir))
|
||||||
|
.for_each(|span| {
|
||||||
|
dir_found = true;
|
||||||
|
span.file_name
|
||||||
|
.replace_range(0..thread_target_dir.len(), shared_target_dir("_*").to_str().unwrap());
|
||||||
|
});
|
||||||
|
|
||||||
|
if dir_found && let Some(rendered) = &mut message.rendered {
|
||||||
|
*rendered = rendered.replace(thread_target_dir, shared_target_dir("_*").to_str().unwrap());
|
||||||
|
}
|
||||||
|
message
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds clippy inside the repo to make sure we have a clippy executable we can use.
|
/// Builds clippy inside the repo to make sure we have a clippy executable we can use.
|
||||||
fn build_clippy() -> String {
|
fn build_clippy() -> String {
|
||||||
let output = Command::new("cargo")
|
let output = Command::new("cargo")
|
||||||
@ -388,6 +416,15 @@ fn clippy_project_root() -> &'static Path {
|
|||||||
Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap()
|
Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The qualifier can be used to separate different threads from another. By
|
||||||
|
/// default it should be set to `_<thread_id>`
|
||||||
|
#[must_use]
|
||||||
|
fn shared_target_dir(qualifier: &str) -> PathBuf {
|
||||||
|
clippy_project_root()
|
||||||
|
.join("target/lintcheck/shared_target_dir")
|
||||||
|
.join(qualifier)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lintcheck_test() {
|
fn lintcheck_test() {
|
||||||
let args = [
|
let args = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user