Skip to content

Commit

Permalink
Misc code cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Oct 7, 2019
1 parent 28b066c commit 9b21164
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use serde_json::Value;
use std::env;
use std::ffi::OsString;
use std::fs::File;
use std::io::prelude::*;
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -42,10 +41,7 @@ use self::triple::{Endianness, PointerWidth, Triple};
/// Assuming `target` is a path to a custom target json config file, open it
/// and build a `Triple` using its contents.
fn read_target_from_file(path: &Path) -> Triple {
let mut file = File::open(path).expect("error opening target file");
let mut json = String::new();
file.read_to_string(&mut json)
.expect("error reading target file");
let json = fs::read_to_string(path).expect("error reading target file");

let v: Value = serde_json::from_str(&json).expect("error parsing target file as json");
let target = v["llvm-target"]
Expand Down Expand Up @@ -110,10 +106,7 @@ fn main() {
let triple = if target.ends_with(".json") {
read_target_from_file(Path::new(&target))
} else {
match Triple::from_str(&target) {
Ok(triple) => triple,
Err(_) => read_target_from_file_in_path(&target),
}
Triple::from_str(&target).unwrap_or_else(|_| read_target_from_file_in_path(&target))
};

let out = File::create(out_dir.join("host.rs")).expect("error creating host.rs");
Expand Down

0 comments on commit 9b21164

Please sign in to comment.