mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-11 22:02:55 +00:00
Improve conflicting rlibs error again
This commit is contained in:
parent
3214de3fe6
commit
3c517b3b24
1 changed files with 50 additions and 39 deletions
|
@ -1,5 +1,6 @@
|
||||||
#![feature(test)] // compiletest_rs requires this attribute
|
#![feature(test)] // compiletest_rs requires this attribute
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
|
#![feature(try_blocks)]
|
||||||
|
|
||||||
use compiletest_rs as compiletest;
|
use compiletest_rs as compiletest;
|
||||||
use compiletest_rs::common::Mode as TestMode;
|
use compiletest_rs::common::Mode as TestMode;
|
||||||
|
@ -45,48 +46,49 @@ fn third_party_crates() -> String {
|
||||||
"syn",
|
"syn",
|
||||||
];
|
];
|
||||||
let dep_dir = cargo::TARGET_LIB.join("deps");
|
let dep_dir = cargo::TARGET_LIB.join("deps");
|
||||||
let mut crates: HashMap<&str, PathBuf> = HashMap::with_capacity(CRATES.len());
|
let mut crates: HashMap<&str, Vec<PathBuf>> = HashMap::with_capacity(CRATES.len());
|
||||||
for entry in fs::read_dir(dep_dir).unwrap() {
|
let mut flags = String::new();
|
||||||
let path = match entry {
|
for entry in fs::read_dir(dep_dir).unwrap().flatten() {
|
||||||
Ok(entry) => entry.path(),
|
let path = entry.path();
|
||||||
Err(_) => continue,
|
if let Some(name) = try {
|
||||||
};
|
let name = path.file_name()?.to_str()?;
|
||||||
if let Some(name) = path.file_name().and_then(OsStr::to_str) {
|
let (name, _) = name.strip_suffix(".rlib")?.strip_prefix("lib")?.split_once('-')?;
|
||||||
for dep in CRATES {
|
CRATES.iter().copied().find(|&c| c == name)?
|
||||||
if name.starts_with(&format!("lib{}-", dep))
|
} {
|
||||||
&& name.rsplit('.').next().map(|ext| ext.eq_ignore_ascii_case("rlib")) == Some(true)
|
flags += &format!(" --extern {}={}", name, path.display());
|
||||||
{
|
crates.entry(name).or_default().push(path.clone());
|
||||||
if let Some(old) = crates.insert(dep, path.clone()) {
|
|
||||||
// Check which action should be done in order to remove compiled deps.
|
|
||||||
// If pre-installed version of compiler is used, `cargo clean` will do.
|
|
||||||
// Otherwise (for bootstrapped compiler), the dependencies directory
|
|
||||||
// must be removed manually.
|
|
||||||
let suggested_action = if std::env::var_os("RUSTC_BOOTSTRAP").is_some() {
|
|
||||||
"remove the stageN-tools directory"
|
|
||||||
} else {
|
|
||||||
"run `cargo clean`"
|
|
||||||
};
|
|
||||||
|
|
||||||
panic!(
|
|
||||||
"\n---------------------------------------------------\n\n \
|
|
||||||
Found multiple rlibs for crate `{}`: `{:?}` and `{:?}`.\n \
|
|
||||||
Probably, you need to {} before running tests again.\n \
|
|
||||||
\nFor details on that error see https://github.com/rust-lang/rust-clippy/issues/7343 \
|
|
||||||
\n---------------------------------------------------\n",
|
|
||||||
dep, old, path, suggested_action
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
crates.retain(|_, paths| paths.len() > 1);
|
||||||
|
if !crates.is_empty() {
|
||||||
|
let crate_names = crates.keys().map(|s| format!("`{}`", s)).collect::<Vec<_>>().join(", ");
|
||||||
|
// add backslashes for an easy copy-paste `rm` command
|
||||||
|
let paths = crates
|
||||||
|
.into_values()
|
||||||
|
.flatten()
|
||||||
|
.map(|p| strip_current_dir(&p).display().to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" \\\n");
|
||||||
|
// Check which action should be done in order to remove compiled deps.
|
||||||
|
// If pre-installed version of compiler is used, `cargo clean` will do.
|
||||||
|
// Otherwise (for bootstrapped compiler), the dependencies directory
|
||||||
|
// must be removed manually.
|
||||||
|
let suggested_action = if std::env::var_os("RUSTC_BOOTSTRAP").is_some() {
|
||||||
|
"removing the stageN-tools directory"
|
||||||
|
} else {
|
||||||
|
"running `cargo clean`"
|
||||||
|
};
|
||||||
|
|
||||||
let v: Vec<_> = crates
|
panic!(
|
||||||
.into_iter()
|
"\n----------------------------------------------------------------------\n\
|
||||||
.map(|(dep, path)| format!("--extern {}={}", dep, path.display()))
|
ERROR: Found multiple rlibs for crates: {}\n\
|
||||||
.collect();
|
Try {} or remove the following files:\n\n{}\n\n\
|
||||||
v.join(" ")
|
For details on this error see https://github.com/rust-lang/rust-clippy/issues/7343\n\
|
||||||
|
----------------------------------------------------------------------\n",
|
||||||
|
crate_names, suggested_action, paths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
flags
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_config() -> compiletest::Config {
|
fn default_config() -> compiletest::Config {
|
||||||
|
@ -313,3 +315,12 @@ impl Drop for VarGuard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strip_current_dir(path: &Path) -> &Path {
|
||||||
|
if let Ok(curr) = env::current_dir() {
|
||||||
|
if let Ok(stripped) = path.strip_prefix(curr) {
|
||||||
|
return stripped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue