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