+// When we'll want to use `extern crate ..` for a dependency that is used
+// both by the crate and the compiler itself, we can't simply pass -L flags
+// as we'll get a duplicate matching versions. Instead, disambiguate with
+// `--extern dep=path`.
+// See https://github.com/rust-lang/rust-clippy/issues/4015.
+//
+// FIXME: We cannot use `cargo build --message-format=json` to resolve to dependency files.
+// Because it would force-rebuild if the options passed to `build` command is not the same
+// as what we manually pass to `cargo` invocation
+fn third_party_crates() -> String {
+ use std::collections::HashMap;
+ static CRATES: &[&str] = &["serde", "serde_derive", "regex", "clippy_lints"];
+ let dep_dir = cargo::TARGET_LIB.join("deps");
+ let mut crates: HashMap<&str, PathBuf> = HashMap::with_capacity(CRATES.len());
+ for entry in fs::read_dir(dep_dir).unwrap() {
+ let path = match entry {
+ Ok(entry) => entry.path(),
+ _ => continue,
+ };
+ if let Some(name) = path.file_name().and_then(OsStr::to_str) {
+ for dep in CRATES {
+ if name.starts_with(&format!("lib{}-", dep)) && name.ends_with(".rlib") {
+ crates.entry(dep).or_insert(path);
+ break;
+ }
+ }
+ }
+ }