File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 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;
4747use std:: collections:: hash_map:: DefaultHasher ;
4848use std:: collections:: HashSet ;
4949use std:: iter:: FromIterator ;
50- use std:: path:: PathBuf ;
50+ use std:: path:: { Path , PathBuf } ;
5151
5252pub 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 }
Original file line number Diff line number Diff line change 4747use serialize:: json:: { Json , ToJson } ;
4848use std:: collections:: BTreeMap ;
4949use std:: default:: Default ;
50- use std:: fmt;
50+ use std:: { fmt, io } ;
5151use std:: path:: { Path , PathBuf } ;
5252use syntax:: abi:: { Abi , lookup as lookup_abi} ;
5353
@@ -1029,11 +1029,17 @@ pub enum TargetTriple {
10291029}
10301030
10311031impl 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.
You can’t perform that action at this time.
0 commit comments