pub fn search(target: &str) -> Result<Target, String> {
        use std::env;
        use std::ffi::OsString;
        use std::fs::File;
        use std::path::{Path, PathBuf};
        use serialize::json;

        fn load_file(path: &Path) -> Result<Target, String> {
            let mut f = try!(File::open(path).map_err(|e| e.to_string()));
            let mut contents = Vec::new();
            try!(f.read_to_end(&mut contents).map_err(|e| e.to_string()));
            let obj = try!(json::from_reader(&mut &contents[..])
                                .map_err(|e| e.to_string()));
            Ok(Target::from_json(obj))
        }

        // this would use a match if stringify! were allowed in pattern position
        macro_rules! load_specific {
            ( $($name:ident),+ ) => (
                {
                    $(mod $name;)*
                    let target = target.replace("-", "_");
                    if false { }
                    $(
                        else if target == stringify!($name) {
                            let t = $name::target();
                            debug!("Got builtin target: {:?}", t);
                            return Ok(t);
                        }
                    )*
                    else if target == "x86_64-w64-mingw32" {
                        let t = x86_64_pc_windows_gnu::target();
                        return Ok(t);
                    } else if target == "i686-w64-mingw32" {
                        let t = i686_pc_windows_gnu::target();
                        return Ok(t);
                    }
                }
            )
        }

        load_specific!(
            x86_64_unknown_linux_gnu,
            i686_unknown_linux_gnu,
            mips_unknown_linux_gnu,
            mipsel_unknown_linux_gnu,
            powerpc_unknown_linux_gnu,
            arm_unknown_linux_gnueabi,
            arm_unknown_linux_gnueabihf,
            aarch64_unknown_linux_gnu,
            x86_64_unknown_linux_musl,

            arm_linux_androideabi,
            aarch64_linux_android,

            x86_64_unknown_freebsd,

            i686_unknown_dragonfly,
            x86_64_unknown_dragonfly,

            x86_64_unknown_bitrig,
            x86_64_unknown_openbsd,

            x86_64_apple_darwin,
            i686_apple_darwin,

            i386_apple_ios,
            x86_64_apple_ios,
            aarch64_apple_ios,
            armv7_apple_ios,
            armv7s_apple_ios,

            x86_64_pc_windows_gnu,
            i686_pc_windows_gnu
        );


        let path = Path::new(target);

        if path.is_file() {
            return load_file(&path);
        }

        let path = {
            let mut target = target.to_string();
            target.push_str(".json");
            PathBuf::from(target)
        };

        let target_path = env::var_os("RUST_TARGET_PATH")
                              .unwrap_or(OsString::new());

        // FIXME 16351: add a sane default search path?

        for dir in env::split_paths(&target_path) {
            let p =  dir.join(&path);
            if p.is_file() {
                return load_file(&p);
            }
        }

        Err(format!("Could not find specification for target {:?}", target))
    }
/// Search RUST_TARGET_PATH for a JSON file specifying the given target
/// triple. Note that it could also just be a bare filename already, so also
/// check for that. If one of the hardcoded targets we know about, just
/// return it directly.
///
/// The error string could come from any of the APIs called, including
/// filesystem access and JSON decoding.
Search RUST_TARGET_PATH for a JSON file specifying the given target
triple. Note that it could also just be a bare filename already, so also
check for that. If one of the hardcoded targets we know about, just
return it directly.

The error string could come from any of the APIs called, including
filesystem access and JSON decoding.
Search RUST_TARGET_PATH for a JSON file specifying the given target triple . Note that it could also just be a bare filename already so also check for that . If one of the hardcoded targets we know about just return it directly . The error string could come from any of the APIs called including filesystem access and JSON decoding .
pub fn search(target: &str) -> Result<Target, String> {
        use std::env;
        use std::ffi::OsString;
        use std::fs::File;
        use std::path::{Path, PathBuf};
        use serialize::json;
        fn load_file(path: &Path) -> Result<Target, String> {
            let mut f = try!(File::open(path).map_err(|e| e.to_string()));
            let mut contents = Vec::new();
            try!(f.read_to_end(&mut contents).map_err(|e| e.to_string()));
            let obj = try!(json::from_reader(&mut &contents[..])
                                .map_err(|e| e.to_string()));
            Ok(Target::from_json(obj))
        }
        // this would use a match if stringify! were allowed in pattern position
        macro_rules! load_specific {
            ( $($name:ident),+ ) => (
                {
                    $(mod $name;)*
                    let target = target.replace("-", "_");
                    if false { }
                    $(
                        else if target == stringify!($name) {
                            let t = $name::target();
                            debug!("Got builtin target: {:?}", t);
                            return Ok(t);
                        }
                    )*
                    else if target == "x86_64-w64-mingw32" {
                        let t = x86_64_pc_windows_gnu::target();
                        return Ok(t);
                    } else if target == "i686-w64-mingw32" {
                        let t = i686_pc_windows_gnu::target();
                        return Ok(t);
                    }
                }
            )
        }
        load_specific!(
            x86_64_unknown_linux_gnu,
            i686_unknown_linux_gnu,
            mips_unknown_linux_gnu,
            mipsel_unknown_linux_gnu,
            powerpc_unknown_linux_gnu,
            arm_unknown_linux_gnueabi,
            arm_unknown_linux_gnueabihf,
            aarch64_unknown_linux_gnu,
            x86_64_unknown_linux_musl,
            arm_linux_androideabi,
            aarch64_linux_android,
            x86_64_unknown_freebsd,
            i686_unknown_dragonfly,
            x86_64_unknown_dragonfly,
            x86_64_unknown_bitrig,
            x86_64_unknown_openbsd,
            x86_64_apple_darwin,
            i686_apple_darwin,
            i386_apple_ios,
            x86_64_apple_ios,
            aarch64_apple_ios,
            armv7_apple_ios,
            armv7s_apple_ios,
            x86_64_pc_windows_gnu,
            i686_pc_windows_gnu
        );
        let path = Path::new(target);
        if path.is_file() {
            return load_file(&path);
        }
        let path = {
            let mut target = target.to_string();
            target.push_str(".json");
            PathBuf::from(target)
        };
        let target_path = env::var_os("RUST_TARGET_PATH")
                              .unwrap_or(OsString::new());
        // FIXME 16351: add a sane default search path?
        for dir in env::split_paths(&target_path) {
            let p =  dir.join(&path);
            if p.is_file() {
                return load_file(&p);
            }
        }
        Err(format!("Could not find specification for target {:?}", target))
    }
pub fn search ( target : & str ) -> Result < Target , String > { use std :: env ; use std :: ffi :: OsString ; use std :: fs :: File ; use std :: path :: { Path , PathBuf } ; use serialize :: json ; fn load_file ( path : & Path ) -> Result < Target , String > { let mut f = try ! ( File open ( path ) map_err ( e e to_string ( ) ) ) ; let mut contents = Vec :: new ( ) ; try ! ( f read_to_end ( mut contents ) map_err ( e e to_string ( ) ) ) ; let obj = try ! ( json from_reader ( mut contents [ ] ) map_err ( e e to_string ( ) ) ) ; Ok ( Target :: from_json ( obj ) ) } // this would use a match if stringify! were allowed in pattern position macro_rules! load_specific { ( $ ( $name : ident ) + ) => ( { $ ( mod $name ) * let target target replace ( " " " " ) if false { } $ ( else if target stringify ( $name ) { let t $name target ( ) debug ( " " t ) return Ok ( t ) } ) * else if target " " { let t x86_64_pc_windows_gnu target ( ) return Ok ( t ) } else if target " " { let t i686_pc_windows_gnu target ( ) return Ok ( t ) } } ) } load_specific ! ( x86_64_unknown_linux_gnu i686_unknown_linux_gnu mips_unknown_linux_gnu mipsel_unknown_linux_gnu powerpc_unknown_linux_gnu arm_unknown_linux_gnueabi arm_unknown_linux_gnueabihf aarch64_unknown_linux_gnu x86_64_unknown_linux_musl arm_linux_androideabi aarch64_linux_android x86_64_unknown_freebsd i686_unknown_dragonfly x86_64_unknown_dragonfly x86_64_unknown_bitrig x86_64_unknown_openbsd x86_64_apple_darwin i686_apple_darwin i386_apple_ios x86_64_apple_ios aarch64_apple_ios armv7_apple_ios armv7s_apple_ios x86_64_pc_windows_gnu i686_pc_windows_gnu ) ; let path = Path :: new ( target ) ; if path . is_file ( ) { return load_file ( & path ) ; } let path = { let mut target = target . to_string ( ) ; target . push_str ( " " ) ; PathBuf :: from ( target ) } ; let target_path = env :: var_os ( " " ) . unwrap_or ( OsString :: new ( ) ) ; // FIXME 16351: add a sane default search path? for dir in env :: split_paths ( & target_path ) { let p = dir . join ( & path ) ; if p . is_file ( ) { return load_file ( & p ) ; } } Err ( format ! ( " " target ) ) }
Search RUST_TARGET_PATH for a JSON file specifying the given target
triple.
Search RUST_TARGET_PATH for a JSON file specifying the given target triple .
target
&str