Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

loader: Change RUSTC env var behavior #121

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! default implementation `CargoAnalysisLoader` for Cargo-emitted save-analysis
//! files.

use std::env;
use std::ffi::OsStr;
use std::fmt;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -113,21 +114,19 @@ fn extract_target_triple(sys_root_path: &Path) -> String {
}

fn sys_root_path() -> PathBuf {
option_env!("SYSROOT")
env::var("SYSROOT")
.ok()
.map(PathBuf::from)
.or_else(|| {
Command::new(option_env!("RUSTC").unwrap_or("rustc"))
Command::new(env::var("RUSTC").unwrap_or(String::from("rustc")))
.arg("--print")
.arg("sysroot")
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.map(|s| PathBuf::from(s.trim()))
})
.expect(
"need to specify SYSROOT or RUSTC env vars, \
or rustc must be in PATH",
)
.expect("need to specify SYSROOT or RUSTC env vars, or rustc must be in PATH")
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down