]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/util.rs
Add support for the Haiku operating system on x86 and x86_64 machines
[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)] = &[("android", "android"),
16                                                             ("bitrig", "bitrig"),
17                                                             ("darwin", "macos"),
18                                                             ("dragonfly", "dragonfly"),
19                                                             ("freebsd", "freebsd"),
20                                                             ("haiku", "haiku"),
21                                                             ("ios", "ios"),
22                                                             ("linux", "linux"),
23                                                             ("mingw32", "windows"),
24                                                             ("netbsd", "netbsd"),
25                                                             ("openbsd", "openbsd"),
26                                                             ("win32", "windows"),
27                                                             ("windows", "windows"),
28                                                             ("solaris", "solaris"),
29                                                             ("emscripten", "emscripten")];
30
31 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[("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                                                               ("powerpc64", "powerpc64"),
42                                                               ("s390x", "s390x"),
43                                                               ("sparc", "sparc"),
44                                                               ("x86_64", "x86_64"),
45                                                               ("xcore", "xcore"),
46                                                               ("asmjs", "asmjs")];
47
48 pub fn get_os(triple: &str) -> &'static str {
49     for &(triple_os, os) in OS_TABLE {
50         if triple.contains(triple_os) {
51             return os;
52         }
53     }
54     panic!("Cannot determine OS from triple");
55 }
56 pub fn get_arch(triple: &str) -> &'static str {
57     for &(triple_arch, arch) in ARCH_TABLE {
58         if triple.contains(triple_arch) {
59             return arch;
60         }
61     }
62     panic!("Cannot determine Architecture from triple");
63 }
64
65 pub fn get_env(triple: &str) -> Option<&str> {
66     triple.split('-').nth(3)
67 }
68
69 pub fn make_new_path(path: &str) -> String {
70     assert!(cfg!(windows));
71     // Windows just uses PATH as the library search path, so we have to
72     // maintain the current value while adding our own
73     match env::var(lib_path_env_var()) {
74         Ok(curr) => format!("{}{}{}", path, path_div(), curr),
75         Err(..) => path.to_owned(),
76     }
77 }
78
79 pub fn lib_path_env_var() -> &'static str {
80     "PATH"
81 }
82 fn path_div() -> &'static str {
83     ";"
84 }
85
86 pub fn logv(config: &Config, s: String) {
87     debug!("{}", s);
88     if config.verbose {
89         println!("{}", s);
90     }
91 }