summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2e72a1e7..c0455935 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -266,24 +266,24 @@ fn builder_state()
// Get the first directory in PATH that contains a file named "clang".
fn get_clang_dir() -> Option<path::PathBuf>{
- match env::var_os("PATH") {
- Some(paths) => {
- for p in env::split_paths(&paths) {
- let mut bin_path = p.clone();
- bin_path.push("clang");
- match fs::metadata(bin_path) {
- Ok(m) => {
- if m.is_file() {
- return Some(p);
- }
+ if let Some(paths) = env::var_os("PATH") {
+ for mut path in env::split_paths(&paths) {
+ path.push("clang");
+ if let Ok(real_path) = fs::canonicalize(&path) {
+ if fs::metadata(&real_path).iter().any(|m| m.is_file()) &&
+ real_path
+ .file_name()
+ .and_then(|f| f.to_str())
+ .iter()
+ .any(|&f| f == "clang") {
+ if let Some(dir) = real_path.parent() {
+ return Some(dir.to_path_buf())
}
- _ => (),
}
}
- None
}
- None => None,
}
+ None
}
// Try to find the directory that contains clang's bundled headers. Clang itself does something