diff options
| author | Igor Matuszewski <Xanewok@gmail.com> | 2019-04-22 15:04:48 +0200 |
|---|---|---|
| committer | Igor Matuszewski <Xanewok@gmail.com> | 2019-04-23 10:32:41 +0200 |
| commit | 56389f36a3e99d374684c74c8dbddd7691023968 (patch) | |
| tree | d42e23f7cd6273a5ef96e79642338130900bc911 | |
| parent | d420589e1a8208c85368d07c1644c6725367650b (diff) | |
| download | rust-56389f36a3e99d374684c74c8dbddd7691023968.tar.gz rust-56389f36a3e99d374684c74c8dbddd7691023968.zip | |
compiletest: Disambiguate extern crate deps shared with the compiler
| -rw-r--r-- | tests/compile-test.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/compile-test.rs b/tests/compile-test.rs index bafd64e934f..65561b7fbd7 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -46,9 +46,32 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config { config.run_lib_path = rustc_lib_path(); config.compile_lib_path = rustc_lib_path(); } + + // 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. + let needs_disambiguation = ["serde"]; + // This assumes that deps are compiled (they are for Cargo integration tests). + let deps = std::fs::read_dir(host_libs().join("deps")).unwrap(); + let disambiguated = deps + .filter_map(|dep| { + let path = dep.ok()?.path(); + let name = path.file_name()?.to_string_lossy(); + // NOTE: This only handles a single dep + // https://github.com/laumann/compiletest-rs/issues/101 + needs_disambiguation + .iter() + .find(|dep| name.starts_with(&format!("lib{}-", dep))) + .map(|dep| format!("--extern {}={}", dep, path.display())) + }) + .collect::<Vec<_>>(); + config.target_rustcflags = Some(format!( - "-L {0} -L {0}/deps -Dwarnings -Zui-testing", - host_libs().display() + "-L {0} -L {0}/deps -Dwarnings -Zui-testing {1}", + host_libs().display(), + disambiguated.join(" ") )); config.mode = cfg_mode; |
