]> git.proxmox.com Git - rustc.git/blame - src/tools/compiletest/src/util.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / tools / compiletest / src / util.rs
CommitLineData
85aaf69f 1// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
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
85aaf69f 11use std::env;
c34b1796 12use common::Config;
1a4d82fc
JJ
13
14/// Conversion table from triple OS name to Rust SYSNAME
32a655c1
SL
15const 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];
c34b1796 32
32a655c1
SL
33const 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];
1a4d82fc 53
abe05a73
XL
54pub fn matches_os(triple: &str, name: &str) -> bool {
55 // For the wasm32 bare target we ignore anything also ignored on emscripten
56 // and then we also recognize `wasm32-bare` as the os for the target
57 if triple == "wasm32-unknown-unknown" {
58 return name == "emscripten" || name == "wasm32-bare"
59 }
85aaf69f 60 for &(triple_os, os) in OS_TABLE {
1a4d82fc 61 if triple.contains(triple_os) {
abe05a73 62 return os == name;
1a4d82fc
JJ
63 }
64 }
65 panic!("Cannot determine OS from triple");
66}
c34b1796
AL
67pub fn get_arch(triple: &str) -> &'static str {
68 for &(triple_arch, arch) in ARCH_TABLE {
69 if triple.contains(triple_arch) {
5bcae85e 70 return arch;
c34b1796
AL
71 }
72 }
73 panic!("Cannot determine Architecture from triple");
74}
223e47cc 75
d9579d0f
AL
76pub fn get_env(triple: &str) -> Option<&str> {
77 triple.split('-').nth(3)
78}
79
041b39d2 80pub fn get_pointer_width(triple: &str) -> &'static str {
abe05a73 81 if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
041b39d2
XL
82 "64bit"
83 } else {
84 "32bit"
85 }
86}
87
1a4d82fc 88pub fn make_new_path(path: &str) -> String {
c34b1796 89 assert!(cfg!(windows));
223e47cc
LB
90 // Windows just uses PATH as the library search path, so we have to
91 // maintain the current value while adding our own
85aaf69f 92 match env::var(lib_path_env_var()) {
5bcae85e
SL
93 Ok(curr) => format!("{}{}{}", path, path_div(), curr),
94 Err(..) => path.to_owned(),
223e47cc
LB
95 }
96}
97
5bcae85e
SL
98pub fn lib_path_env_var() -> &'static str {
99 "PATH"
100}
101fn path_div() -> &'static str {
102 ";"
103}
223e47cc 104
1a4d82fc
JJ
105pub fn logv(config: &Config, s: String) {
106 debug!("{}", s);
5bcae85e
SL
107 if config.verbose {
108 println!("{}", s);
109 }
223e47cc 110}