From 0ec05d0a9961955d8d01fa8b2ef31f6ec30153ee Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 Jul 2020 11:15:58 +0200 Subject: [PATCH] fix for changed rustc directory layout --- src/rustc.rs | 29 ++++++----------------------- src/sysroot.rs | 25 +++++++++++++++++-------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/rustc.rs b/src/rustc.rs index f614f50..9074129 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -1,5 +1,4 @@ use std::env; -use std::ffi::OsStr; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use std::process::Command; @@ -8,7 +7,6 @@ pub use rustc_version::version_meta as version; use serde_json::Value; use serde_json; -use walkdir::WalkDir; use CurrentDirectory; use errors::*; @@ -69,8 +67,8 @@ impl Sysroot { &self.path } - /// Returns the path to Rust source, `$SRC`, where `$SRC/libstd/Carg.toml` - /// exists + /// Returns the path to Rust source, `$SRC`, where `$SRC/libstd/Cargo.toml` + /// or `$SRC/std/Cargo.toml` exists. pub fn src(&self) -> Result { let src = self.path().join("lib").join("rustlib").join("src"); @@ -80,25 +78,10 @@ impl Sysroot { }); } - if src.exists() { - for e in WalkDir::new(src) { - let e = e.chain_err(|| "couldn't walk the sysroot")?; - - // Looking for $SRC/libstd/Cargo.toml - if e.file_type().is_file() && e.file_name() == "Cargo.toml" { - let toml = e.path(); - - if let Some(std) = toml.parent() { - if let Some(src) = std.parent() { - if std.file_name() == Some(OsStr::new("libstd")) { - return Ok(Src { - path: src.to_owned(), - }); - } - } - } - } - } + if src.join("rust").join("library").join("std").join("Cargo.toml").is_file() { + return Ok(Src { + path: src.join("rust").join("library"), + }); } Err( diff --git a/src/sysroot.rs b/src/sysroot.rs index 9d9f2f7..4987dd4 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -412,9 +412,13 @@ impl Blueprint { } /// Add $CRATE to `patch` section, as needed to build libstd. - fn add_patch(patch: &mut Table, mut path: PathBuf, crate_: &str) -> Result<()> { - path.push(crate_); - if path.exists() { + fn add_patch(patch: &mut Table, src_path: &Path, crate_: &str) -> Result<()> { + // Old sysroots have this in `src/tools/$CRATE`, new sysroots in `library/$CRATE`. + let paths = [ + src_path.join(crate_), + src_path.join("tools").join(crate_), + ]; + if let Some(path) = paths.iter().find(|p| p.exists()) { // add crate to patch section (if not specified) fn table_entry<'a>(table: &'a mut Table, key: &str) -> Result<&'a mut Table> { table @@ -479,9 +483,9 @@ impl Blueprint { } } - Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-core")?; - Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-alloc")?; - Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-std")?; + Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-core")?; + Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-alloc")?; + Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-std")?; // Compose dependency sections let deps = match ( @@ -559,8 +563,13 @@ impl Blueprint { if !map.contains_key("path") && !map.contains_key("git") { // No path and no git given. This might be in the sysroot, but if we don't find it there we assume it comes from crates.io. - let path = src.path().join(format!("lib{}", k)); - if path.exists() { + // Current sysroots call it just "std" (etc), but older sysroots use "libstd" (etc), + // so we check both. + let paths = [ + src.path().join(&k), + src.path().join(format!("lib{}", k)), + ]; + if let Some(path) = paths.iter().find(|p| p.exists()) { map.insert("path".to_owned(), Value::String(path.display().to_string())); } }