diff options
| author | Philipp Oppermann <dev@phil-opp.com> | 2018-03-24 20:14:59 +0100 |
|---|---|---|
| committer | Philipp Oppermann <dev@phil-opp.com> | 2018-03-26 18:57:24 +0200 |
| commit | 7b49190d3cd98d9e3bc901993861f80269eb4155 (patch) | |
| tree | 62bef8f8ded88300d65c2f72221ba6e767c546a0 /src | |
| parent | 3908b2e4438e89a4f9503a8fa3e378ecc127df45 (diff) | |
Canonicalize paths
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/session/config.rs | 10 | ||||
| -rw-r--r-- | src/librustc_back/target/mod.rs | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 092b84e3ffe..92da47b9d43 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -47,7 +47,7 @@ use std::hash::Hasher; use std::collections::hash_map::DefaultHasher; use std::collections::HashSet; use std::iter::FromIterator; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; pub struct Config { pub target: Target, @@ -1905,7 +1905,13 @@ pub fn build_session_options_and_crate_config( let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); let target_triple = if let Some(target) = matches.opt_str("target") { if target.ends_with(".json") { - TargetTriple::TargetPath(PathBuf::from(target)) + let path = Path::new(&target); + match TargetTriple::from_path(&path) { + Ok(triple) => triple, + Err(_) => { + early_error(error_format, &format!("target file {:?} does not exist", path)) + } + } } else { TargetTriple::TargetTriple(target) } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index ca73a755784..3216aae8918 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -47,7 +47,7 @@ use serialize::json::{Json, ToJson}; use std::collections::BTreeMap; use std::default::Default; -use std::fmt; +use std::{fmt, io}; use std::path::{Path, PathBuf}; use syntax::abi::{Abi, lookup as lookup_abi}; @@ -1029,11 +1029,17 @@ pub enum TargetTriple { } impl TargetTriple { - /// Creates a target target from the passed target triple string. + /// Creates a target triple from the passed target triple string. pub fn from_triple(triple: &str) -> Self { TargetTriple::TargetTriple(triple.to_string()) } + /// Creates a target triple from the passed target path. + pub fn from_path(path: &Path) -> Result<Self, io::Error> { + let canonicalized_path = path.canonicalize()?; + Ok(TargetTriple::TargetPath(canonicalized_path)) + } + /// Returns a string triple for this target. /// /// If this target is a path, the file name (without extension) is returned. |
