]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/util.rs
Refactor away `inferred_obligations` from the trait selector
[rust.git] / src / tools / compiletest / src / 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     ("cloudabi", "cloudabi"),
19     ("darwin", "macos"),
20     ("dragonfly", "dragonfly"),
21     ("freebsd", "freebsd"),
22     ("haiku", "haiku"),
23     ("ios", "ios"),
24     ("linux", "linux"),
25     ("mingw32", "windows"),
26     ("netbsd", "netbsd"),
27     ("openbsd", "openbsd"),
28     ("win32", "windows"),
29     ("windows", "windows"),
30     ("solaris", "solaris"),
31     ("emscripten", "emscripten"),
32 ];
33
34 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
35     ("aarch64", "aarch64"),
36     ("amd64", "x86_64"),
37     ("arm", "arm"),
38     ("arm64", "aarch64"),
39     ("hexagon", "hexagon"),
40     ("i386", "x86"),
41     ("i586", "x86"),
42     ("i686", "x86"),
43     ("mips", "mips"),
44     ("msp430", "msp430"),
45     ("powerpc", "powerpc"),
46     ("powerpc64", "powerpc64"),
47     ("s390x", "s390x"),
48     ("sparc", "sparc"),
49     ("x86_64", "x86_64"),
50     ("xcore", "xcore"),
51     ("asmjs", "asmjs"),
52     ("wasm32", "wasm32"),
53 ];
54
55 pub fn matches_os(triple: &str, name: &str) -> bool {
56     // For the wasm32 bare target we ignore anything also ignored on emscripten
57     // and then we also recognize `wasm32-bare` as the os for the target
58     if triple == "wasm32-unknown-unknown" {
59         return name == "emscripten" || name == "wasm32-bare"
60     }
61     for &(triple_os, os) in OS_TABLE {
62         if triple.contains(triple_os) {
63             return os == name;
64         }
65     }
66     panic!("Cannot determine OS from triple");
67 }
68 pub fn get_arch(triple: &str) -> &'static str {
69     for &(triple_arch, arch) in ARCH_TABLE {
70         if triple.contains(triple_arch) {
71             return arch;
72         }
73     }
74     panic!("Cannot determine Architecture from triple");
75 }
76
77 pub fn get_env(triple: &str) -> Option<&str> {
78     triple.split('-').nth(3)
79 }
80
81 pub fn get_pointer_width(triple: &str) -> &'static str {
82     if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
83         "64bit"
84     } else {
85         "32bit"
86     }
87 }
88
89 pub fn make_new_path(path: &str) -> String {
90     assert!(cfg!(windows));
91     // Windows just uses PATH as the library search path, so we have to
92     // maintain the current value while adding our own
93     match env::var(lib_path_env_var()) {
94         Ok(curr) => format!("{}{}{}", path, path_div(), curr),
95         Err(..) => path.to_owned(),
96     }
97 }
98
99 pub fn lib_path_env_var() -> &'static str {
100     "PATH"
101 }
102 fn path_div() -> &'static str {
103     ";"
104 }
105
106 pub fn logv(config: &Config, s: String) {
107     debug!("{}", s);
108     if config.verbose {
109         println!("{}", s);
110     }
111 }