@@ -2183,7 +2183,7 @@ impl Target {
2183
2183
TargetTriple :: TargetTriple ( ref target_triple) => {
2184
2184
load_builtin ( target_triple) . expect ( "built-in target" )
2185
2185
}
2186
- TargetTriple :: TargetPath ( .. ) => {
2186
+ TargetTriple :: TargetJson { .. } => {
2187
2187
panic ! ( "built-in targets doens't support target-paths" )
2188
2188
}
2189
2189
}
@@ -2248,11 +2248,9 @@ impl Target {
2248
2248
2249
2249
Err ( format ! ( "Could not find specification for target {:?}" , target_triple) )
2250
2250
}
2251
- TargetTriple :: TargetPath ( ref target_path) => {
2252
- if target_path. is_file ( ) {
2253
- return load_file ( & target_path) ;
2254
- }
2255
- Err ( format ! ( "Target path {:?} is not a valid file" , target_path) )
2251
+ TargetTriple :: TargetJson { triple : _, ref contents } => {
2252
+ let obj = serde_json:: from_str ( contents) . map_err ( |e| e. to_string ( ) ) ?;
2253
+ Target :: from_json ( obj)
2256
2254
}
2257
2255
}
2258
2256
}
@@ -2424,7 +2422,7 @@ impl ToJson for Target {
2424
2422
#[ derive( PartialEq , Clone , Debug , Hash , Encodable , Decodable ) ]
2425
2423
pub enum TargetTriple {
2426
2424
TargetTriple ( String ) ,
2427
- TargetPath ( PathBuf ) ,
2425
+ TargetJson { triple : String , contents : String } ,
2428
2426
}
2429
2427
2430
2428
impl TargetTriple {
@@ -2436,20 +2434,28 @@ impl TargetTriple {
2436
2434
/// Creates a target triple from the passed target path.
2437
2435
pub fn from_path ( path : & Path ) -> Result < Self , io:: Error > {
2438
2436
let canonicalized_path = path. canonicalize ( ) ?;
2439
- Ok ( TargetTriple :: TargetPath ( canonicalized_path) )
2437
+ let contents = std:: fs:: read_to_string ( & canonicalized_path) . map_err ( |err| {
2438
+ io:: Error :: new (
2439
+ io:: ErrorKind :: InvalidInput ,
2440
+ format ! ( "Target path {:?} is not a valid file: {}" , canonicalized_path, err) ,
2441
+ )
2442
+ } ) ?;
2443
+ let triple = canonicalized_path
2444
+ . file_stem ( )
2445
+ . expect ( "target path must not be empty" )
2446
+ . to_str ( )
2447
+ . expect ( "target path must be valid unicode" )
2448
+ . to_owned ( ) ;
2449
+ Ok ( TargetTriple :: TargetJson { triple, contents } )
2440
2450
}
2441
2451
2442
2452
/// Returns a string triple for this target.
2443
2453
///
2444
2454
/// If this target is a path, the file name (without extension) is returned.
2445
2455
pub fn triple ( & self ) -> & str {
2446
2456
match * self {
2447
- TargetTriple :: TargetTriple ( ref triple) => triple,
2448
- TargetTriple :: TargetPath ( ref path) => path
2449
- . file_stem ( )
2450
- . expect ( "target path must not be empty" )
2451
- . to_str ( )
2452
- . expect ( "target path must be valid unicode" ) ,
2457
+ TargetTriple :: TargetTriple ( ref triple)
2458
+ | TargetTriple :: TargetJson { ref triple, contents : _ } => triple,
2453
2459
}
2454
2460
}
2455
2461
@@ -2461,14 +2467,14 @@ impl TargetTriple {
2461
2467
use std:: collections:: hash_map:: DefaultHasher ;
2462
2468
use std:: hash:: { Hash , Hasher } ;
2463
2469
2464
- let triple = self . triple ( ) ;
2465
- if let TargetTriple :: TargetPath ( ref path ) = * self {
2466
- let mut hasher = DefaultHasher :: new ( ) ;
2467
- path . hash ( & mut hasher) ;
2468
- let hash = hasher . finish ( ) ;
2469
- format ! ( "{}-{}" , triple , hash)
2470
- } else {
2471
- triple . into ( )
2470
+ match self {
2471
+ TargetTriple :: TargetTriple ( triple ) => triple . to_owned ( ) ,
2472
+ TargetTriple :: TargetJson { triple , contents : content } => {
2473
+ let mut hasher = DefaultHasher :: new ( ) ;
2474
+ content . hash ( & mut hasher ) ;
2475
+ let hash = hasher . finish ( ) ;
2476
+ format ! ( "{}-{}" , triple , hash )
2477
+ }
2472
2478
}
2473
2479
}
2474
2480
}
0 commit comments