]> git.lizzy.rs Git - rust.git/blob - src/compiletest/util.rs
libstd: implement From<&Path|PathBuf> for Cow<Path>
[rust.git] / src / compiletest / util.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::env;
12 use common::Config;
13
14 /// Conversion table from triple OS name to Rust SYSNAME
15 const OS_TABLE: &'static [(&'static str, &'static str)] = &[
16     ("android", "android"),
17     ("bitrig", "bitrig"),
18     ("darwin", "macos"),
19     ("dragonfly", "dragonfly"),
20     ("freebsd", "freebsd"),
21     ("ios", "ios"),
22     ("linux", "linux"),
23     ("mingw32", "windows"),
24     ("netbsd", "netbsd"),
25     ("openbsd", "openbsd"),
26     ("win32", "windows"),
27     ("windows", "windows"),
28 ];
29
30 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
31     ("aarch64", "aarch64"),
32     ("amd64", "x86_64"),
33     ("arm", "arm"),
34     ("arm64", "aarch64"),
35     ("hexagon", "hexagon"),
36     ("i386", "x86"),
37     ("i686", "x86"),
38     ("mips", "mips"),
39     ("msp430", "msp430"),
40     ("powerpc", "powerpc"),
41     ("s390x", "systemz"),
42     ("sparc", "sparc"),
43     ("x86_64", "x86_64"),
44     ("xcore", "xcore"),
45 ];
46
47 pub fn get_os(triple: &str) -> &'static str {
48     for &(triple_os, os) in OS_TABLE {
49         if triple.contains(triple_os) {
50             return os
51         }
52     }
53     panic!("Cannot determine OS from triple");
54 }
55 pub fn get_arch(triple: &str) -> &'static str {
56     for &(triple_arch, arch) in ARCH_TABLE {
57         if triple.contains(triple_arch) {
58             return arch
59         }
60     }
61     panic!("Cannot determine Architecture from triple");
62 }
63
64 pub fn get_env(triple: &str) -> Option<&str> {
65     triple.split('-').nth(3)
66 }
67
68 pub fn make_new_path(path: &str) -> String {
69     assert!(cfg!(windows));
70     // Windows just uses PATH as the library search path, so we have to
71     // maintain the current value while adding our own
72     match env::var(lib_path_env_var()) {
73         Ok(curr) => {
74             format!("{}{}{}", path, path_div(), curr)
75         }
76         Err(..) => path.to_owned()
77     }
78 }
79
80 pub fn lib_path_env_var() -> &'static str { "PATH" }
81 fn path_div() -> &'static str { ";" }
82
83 pub fn logv(config: &Config, s: String) {
84     debug!("{}", s);
85     if config.verbose { println!("{}", s); }
86 }