File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ use std::hash::Hasher;
47
47
use std:: collections:: hash_map:: DefaultHasher ;
48
48
use std:: collections:: HashSet ;
49
49
use std:: iter:: FromIterator ;
50
- use std:: path:: PathBuf ;
50
+ use std:: path:: { Path , PathBuf } ;
51
51
52
52
pub struct Config {
53
53
pub target : Target ,
@@ -1905,7 +1905,13 @@ pub fn build_session_options_and_crate_config(
1905
1905
let sysroot_opt = matches. opt_str ( "sysroot" ) . map ( |m| PathBuf :: from ( & m) ) ;
1906
1906
let target_triple = if let Some ( target) = matches. opt_str ( "target" ) {
1907
1907
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
+ }
1909
1915
} else {
1910
1916
TargetTriple :: TargetTriple ( target)
1911
1917
}
Original file line number Diff line number Diff line change 47
47
use serialize:: json:: { Json , ToJson } ;
48
48
use std:: collections:: BTreeMap ;
49
49
use std:: default:: Default ;
50
- use std:: fmt;
50
+ use std:: { fmt, io } ;
51
51
use std:: path:: { Path , PathBuf } ;
52
52
use syntax:: abi:: { Abi , lookup as lookup_abi} ;
53
53
@@ -1029,11 +1029,17 @@ pub enum TargetTriple {
1029
1029
}
1030
1030
1031
1031
impl TargetTriple {
1032
- /// Creates a target target from the passed target triple string.
1032
+ /// Creates a target triple from the passed target triple string.
1033
1033
pub fn from_triple ( triple : & str ) -> Self {
1034
1034
TargetTriple :: TargetTriple ( triple. to_string ( ) )
1035
1035
}
1036
1036
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
+
1037
1043
/// Returns a string triple for this target.
1038
1044
///
1039
1045
/// If this target is a path, the file name (without extension) is returned.
You can’t perform that action at this time.
0 commit comments