From c5101b6dffd2c917e1670ee0d94a146cc075f956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 6 Jan 2019 13:55:15 +0100 Subject: [PATCH] Revert "Auto merge of #57101 - o01eg:fix-57014, r=alexcrichton" This reverts commit 68614265d312fc2cbe8a696f7dabb9416eb6f221, reversing changes made to cae623c5ce12df8f237264d8f2c31fdaa664c382. Should fix tools on windows. Reopens #57014 --- src/librustc/session/filesearch.rs | 7 ------ src/librustc_driver/lib.rs | 40 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index c6e68ba379ec3..19f1c7a18fad1 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -114,13 +114,6 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { sysroot.join(&relative_target_lib_path(sysroot, target_triple)) } -pub fn target_lib_path(target_triple: &str) -> PathBuf { - let mut p = PathBuf::from(RUST_LIB_DIR); - p.push(target_triple); - p.push("lib"); - p -} - pub fn get_or_default_sysroot() -> PathBuf { // Follow symlinks. If the resolved path is relative, make it absolute. fn canonicalize(path: Option) -> Option { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 20a3009378d37..1ec14fbb06c79 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -269,35 +269,37 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box { } let target = session::config::host_triple(); - // get target libdir path based on executable binary path - let sysroot = filesearch::get_or_default_sysroot(); - let mut libdir_candidates = vec![filesearch::make_target_lib_path(&sysroot, &target)]; + let mut sysroot_candidates = vec![filesearch::get_or_default_sysroot()]; let path = current_dll_path() .and_then(|s| s.canonicalize().ok()); if let Some(dll) = path { - // use `parent` once to chop off the file name - if let Some(path) = dll.parent() { + // use `parent` twice to chop off the file name and then also the + // directory containing the dll which should be either `lib` or `bin`. + if let Some(path) = dll.parent().and_then(|p| p.parent()) { // The original `path` pointed at the `rustc_driver` crate's dll. // Now that dll should only be in one of two locations. The first is - // in the compiler's libdir, for example `$sysroot/$libdir/*.dll`. The + // in the compiler's libdir, for example `$sysroot/lib/*.dll`. The // other is the target's libdir, for example - // `$sysroot/$libdir/rustlib/$target/lib/*.dll`. + // `$sysroot/lib/rustlib/$target/lib/*.dll`. // // We don't know which, so let's assume that if our `path` above - // doesn't end in `$target` we *could* be in the main libdir, and always - // assume that we may be in the target libdir. - libdir_candidates.push(path.to_owned()); - - if !path.parent().map_or(false, |p| p.ends_with(target)) { - libdir_candidates.push(path.join(filesearch::target_lib_path(target))); + // ends in `$target` we *could* be in the target libdir, and always + // assume that we may be in the main libdir. + sysroot_candidates.push(path.to_owned()); + + if path.ends_with(target) { + sysroot_candidates.extend(path.parent() // chop off `$target` + .and_then(|p| p.parent()) // chop off `rustlib` + .and_then(|p| p.parent()) // chop off `lib` + .map(|s| s.to_owned())); } } } - let sysroot = libdir_candidates.iter() - .map(|libdir| { - debug!("Trying target libdir: {}", libdir.display()); - libdir.with_file_name( + let sysroot = sysroot_candidates.iter() + .map(|sysroot| { + let libdir = filesearch::relative_target_lib_path(&sysroot, &target); + sysroot.join(libdir).with_file_name( option_env!("CFG_CODEGEN_BACKENDS_DIR").unwrap_or("codegen-backends")) }) .filter(|f| { @@ -306,12 +308,12 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box { }) .next(); let sysroot = sysroot.unwrap_or_else(|| { - let candidates = libdir_candidates.iter() + let candidates = sysroot_candidates.iter() .map(|p| p.display().to_string()) .collect::>() .join("\n* "); let err = format!("failed to find a `codegen-backends` folder \ - in the libdir candidates:\n* {}", candidates); + in the sysroot candidates:\n* {}", candidates); early_error(ErrorOutputType::default(), &err); }); info!("probing {} for a codegen backend", sysroot.display());