Skip to content

Commit 7b49190

Browse files
committed
Canonicalize paths
1 parent 3908b2e commit 7b49190

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: src/librustc/session/config.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::hash::Hasher;
4747
use std::collections::hash_map::DefaultHasher;
4848
use std::collections::HashSet;
4949
use std::iter::FromIterator;
50-
use std::path::PathBuf;
50+
use std::path::{Path, PathBuf};
5151

5252
pub struct Config {
5353
pub target: Target,
@@ -1905,7 +1905,13 @@ pub fn build_session_options_and_crate_config(
19051905
let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m));
19061906
let target_triple = if let Some(target) = matches.opt_str("target") {
19071907
if target.ends_with(".json") {
1908-
TargetTriple::TargetPath(PathBuf::from(target))
1908+
let path = Path::new(&target);
1909+
match TargetTriple::from_path(&path) {
1910+
Ok(triple) => triple,
1911+
Err(_) => {
1912+
early_error(error_format, &format!("target file {:?} does not exist", path))
1913+
}
1914+
}
19091915
} else {
19101916
TargetTriple::TargetTriple(target)
19111917
}

Diff for: src/librustc_back/target/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
use serialize::json::{Json, ToJson};
4848
use std::collections::BTreeMap;
4949
use std::default::Default;
50-
use std::fmt;
50+
use std::{fmt, io};
5151
use std::path::{Path, PathBuf};
5252
use syntax::abi::{Abi, lookup as lookup_abi};
5353

@@ -1029,11 +1029,17 @@ pub enum TargetTriple {
10291029
}
10301030

10311031
impl TargetTriple {
1032-
/// Creates a target target from the passed target triple string.
1032+
/// Creates a target triple from the passed target triple string.
10331033
pub fn from_triple(triple: &str) -> Self {
10341034
TargetTriple::TargetTriple(triple.to_string())
10351035
}
10361036

1037+
/// Creates a target triple from the passed target path.
1038+
pub fn from_path(path: &Path) -> Result<Self, io::Error> {
1039+
let canonicalized_path = path.canonicalize()?;
1040+
Ok(TargetTriple::TargetPath(canonicalized_path))
1041+
}
1042+
10371043
/// Returns a string triple for this target.
10381044
///
10391045
/// If this target is a path, the file name (without extension) is returned.

0 commit comments

Comments
 (0)