forked from gentoo/gentoo-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix clippy sysroot patch. Fix codegen search.
- Loading branch information
Showing
3 changed files
with
154 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,62 @@ | ||
diff --git a/src/driver.rs b/src/driver.rs | ||
index 99f8bc61..02ffc6db 100644 | ||
--- a/src/tools/clippy/src/driver.rs | ||
+++ b/src/tools/clippy/src/driver.rs | ||
@@ -29,54 +30,22 @@ pub fn main() { | ||
exit(0); | ||
} | ||
--- a/src/tools/clippy/src/driver.rs 2018-12-28 14:57:17.654845497 +0300 | ||
+++ b/src/tools/clippy/src/driver.rs 2018-12-28 15:08:41.902823310 +0300 | ||
@@ -40,54 +40,23 @@ | ||
exit(0); | ||
} | ||
|
||
- let sys_root = option_env!("SYSROOT") | ||
- .map(String::from) | ||
- .or_else(|| std::env::var("SYSROOT").ok()) | ||
- .or_else(|| { | ||
- let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); | ||
- let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); | ||
- home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain))) | ||
- }) | ||
- .or_else(|| { | ||
- Command::new("rustc") | ||
- .arg("--print") | ||
- .arg("sysroot") | ||
- .output() | ||
- .ok() | ||
- .and_then(|out| String::from_utf8(out.stdout).ok()) | ||
- .map(|s| s.trim().to_owned()) | ||
- }) | ||
- .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); | ||
- | ||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. | ||
// We're invoking the compiler programmatically, so we ignore this/ | ||
- let mut orig_args: Vec<String> = env::args().collect(); | ||
- if orig_args.len() <= 1 { | ||
+ let mut args: Vec<String> = env::args().collect(); | ||
+ if args.len() <= 1 { | ||
std::process::exit(1); | ||
} | ||
- if Path::new(&orig_args[1]).file_stem() == Some("rustc".as_ref()) { | ||
+ if Path::new(&args[1]).file_stem() == Some("rustc".as_ref()) { | ||
// we still want to be able to invoke it normally though | ||
- orig_args.remove(1); | ||
+ args.remove(1); | ||
} | ||
- // this conditional check for the --sysroot flag is there so users can call | ||
- // `clippy_driver` directly | ||
- // without having to pass --sysroot or anything | ||
- let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") { | ||
- orig_args.clone() | ||
- } else { | ||
- orig_args | ||
- .clone() | ||
- .into_iter() | ||
- .chain(Some("--sysroot".to_owned())) | ||
- .chain(Some(sys_root)) | ||
- .collect() | ||
- }; | ||
- let sys_root = option_env!("SYSROOT") | ||
- .map(String::from) | ||
- .or_else(|| std::env::var("SYSROOT").ok()) | ||
- .or_else(|| { | ||
- let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); | ||
- let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); | ||
- home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain))) | ||
- }) | ||
- .or_else(|| { | ||
- Command::new("rustc") | ||
- .arg("--print") | ||
- .arg("sysroot") | ||
- .output() | ||
- .ok() | ||
- .and_then(|out| String::from_utf8(out.stdout).ok()) | ||
- .map(|s| s.trim().to_owned()) | ||
- }) | ||
- .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); | ||
|
||
// this check ensures that dependencies are built but not linted and the final | ||
// crate is | ||
// linted but not built | ||
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true") | ||
- || orig_args.iter().any(|s| s == "--emit=dep-info,metadata"); | ||
+ || args.iter().any(|s| s == "--emit=dep-info,metadata"); | ||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. | ||
// We're invoking the compiler programmatically, so we ignore this/ | ||
- let mut orig_args: Vec<String> = env::args().collect(); | ||
- if orig_args.len() <= 1 { | ||
+ let mut args: Vec<String> = env::args().collect(); | ||
+ if args.len() <= 1 { | ||
std::process::exit(1); | ||
} | ||
- if Path::new(&orig_args[1]).file_stem() == Some("rustc".as_ref()) { | ||
+ if Path::new(&args[1]).file_stem() == Some("rustc".as_ref()) { | ||
// we still want to be able to invoke it normally though | ||
- orig_args.remove(1); | ||
+ args.remove(1); | ||
} | ||
- // this conditional check for the --sysroot flag is there so users can call | ||
- // `clippy_driver` directly | ||
- // without having to pass --sysroot or anything | ||
- let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") { | ||
- orig_args.clone() | ||
- } else { | ||
- orig_args | ||
- .clone() | ||
- .into_iter() | ||
- .chain(Some("--sysroot".to_owned())) | ||
- .chain(Some(sys_root)) | ||
- .collect() | ||
- }; | ||
|
||
if clippy_enabled { | ||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); | ||
// this check ensures that dependencies are built but not linted and the final | ||
// crate is | ||
// linted but not built | ||
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true") | ||
- || orig_args.iter().any(|s| s == "--emit=dep-info,metadata"); | ||
+ || args.iter().any(|s| s == "--emit=dep-info,metadata"); | ||
|
||
if clippy_enabled { | ||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs | ||
index c204556d51..8c72869eb1 100644 | ||
--- a/src/librustc/session/filesearch.rs | ||
+++ b/src/librustc/session/filesearch.rs | ||
@@ -124,6 +124,13 @@ 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<PathBuf>) -> Option<PathBuf> { | ||
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs | ||
index 5527c0ad38..0f7e0eeaa8 100644 | ||
--- a/src/librustc_driver/lib.rs | ||
+++ b/src/librustc_driver/lib.rs | ||
@@ -294,37 +294,35 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> { | ||
} | ||
|
||
let target = session::config::host_triple(); | ||
- let mut sysroot_candidates = vec![filesearch::get_or_default_sysroot()]; | ||
+ // 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 path = current_dll_path() | ||
.and_then(|s| s.canonicalize().ok()); | ||
if let Some(dll) = path { | ||
- // 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()) { | ||
+ // use `parent` once to chop off the file name | ||
+ if let Some(path) = dll.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/lib/*.dll`. The | ||
+ // in the compiler's libdir, for example `$sysroot/$libdir/*.dll`. The | ||
// other is the target's libdir, for example | ||
- // `$sysroot/lib/rustlib/$target/lib/*.dll`. | ||
+ // `$sysroot/$libdir/rustlib/$target/lib/*.dll`. | ||
// | ||
// We don't know which, so let's assume that if our `path` above | ||
- // 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())); | ||
+ // 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))); | ||
} | ||
} | ||
} | ||
|
||
- let sysroot = sysroot_candidates.iter() | ||
- .map(|sysroot| { | ||
- let libdir = filesearch::relative_target_lib_path(&sysroot, &target); | ||
- sysroot.join(libdir).with_file_name( | ||
+ let sysroot = libdir_candidates.iter() | ||
+ .map(|libdir| { | ||
+ debug!("Trying target libdir: {}", libdir.display()); | ||
+ libdir.with_file_name( | ||
option_env!("CFG_CODEGEN_BACKENDS_DIR").unwrap_or("codegen-backends")) | ||
}) | ||
.filter(|f| { | ||
@@ -333,12 +331,12 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> { | ||
}) | ||
.next(); | ||
let sysroot = sysroot.unwrap_or_else(|| { | ||
- let candidates = sysroot_candidates.iter() | ||
+ let candidates = libdir_candidates.iter() | ||
.map(|p| p.display().to_string()) | ||
.collect::<Vec<_>>() | ||
.join("\n* "); | ||
let err = format!("failed to find a `codegen-backends` folder \ | ||
- in the sysroot candidates:\n* {}", candidates); | ||
+ in the libdir candidates:\n* {}", candidates); | ||
early_error(ErrorOutputType::default(), &err); | ||
}); | ||
info!("probing {} for a codegen backend", sysroot.display()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters