]> git.lizzy.rs Git - rust.git/blob - src/compiletest/util.rs
Auto merge of #24865 - bluss:range-size, r=alexcrichton
[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     ("openbsd", "openbsd"),
25     ("win32", "windows"),
26     ("windows", "windows"),
27 ];
28
29 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
30     ("aarch64", "aarch64"),
31     ("amd64", "x86_64"),
32     ("arm", "arm"),
33     ("arm64", "aarch64"),
34     ("hexagon", "hexagon"),
35     ("i386", "x86"),
36     ("i686", "x86"),
37     ("mips", "mips"),
38     ("msp430", "msp430"),
39     ("powerpc", "powerpc"),
40     ("s390x", "systemz"),
41     ("sparc", "sparc"),
42     ("x86_64", "x86_64"),
43     ("xcore", "xcore"),
44 ];
45
46 pub fn get_os(triple: &str) -> &'static str {
47     for &(triple_os, os) in OS_TABLE {
48         if triple.contains(triple_os) {
49             return os
50         }
51     }
52     panic!("Cannot determine OS from triple");
53 }
54 pub fn get_arch(triple: &str) -> &'static str {
55     for &(triple_arch, arch) in ARCH_TABLE {
56         if triple.contains(triple_arch) {
57             return arch
58         }
59     }
60     panic!("Cannot determine Architecture from triple");
61 }
62
63 pub fn get_env(triple: &str) -> Option<&str> {
64     triple.split('-').nth(3)
65 }
66
67 pub fn make_new_path(path: &str) -> String {
68     assert!(cfg!(windows));
69     // Windows just uses PATH as the library search path, so we have to
70     // maintain the current value while adding our own
71     match env::var(lib_path_env_var()) {
72         Ok(curr) => {
73             format!("{}{}{}", path, path_div(), curr)
74         }
75         Err(..) => path.to_string()
76     }
77 }
78
79 pub fn lib_path_env_var() -> &'static str { "PATH" }
80 fn path_div() -> &'static str { ";" }
81
82 pub fn logv(config: &Config, s: String) {
83     debug!("{}", s);
84     if config.verbose { println!("{}", s); }
85 }