]> git.lizzy.rs Git - rust.git/blob - src/compiletest/util.rs
778629dd2028f53ed838dd533198e2705045c358
[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 common::Config;
12
13 #[cfg(target_os = "windows")]
14 use std::env;
15
16 /// Conversion table from triple OS name to Rust SYSNAME
17 static OS_TABLE: &'static [(&'static str, &'static str)] = &[
18     ("mingw32", "windows"),
19     ("win32", "windows"),
20     ("windows", "windows"),
21     ("darwin", "macos"),
22     ("android", "android"),
23     ("linux", "linux"),
24     ("freebsd", "freebsd"),
25     ("dragonfly", "dragonfly"),
26     ("bitrig", "bitrig"),
27     ("openbsd", "openbsd"),
28 ];
29
30 pub fn get_os(triple: &str) -> &'static str {
31     for &(triple_os, os) in OS_TABLE {
32         if triple.contains(triple_os) {
33             return os
34         }
35     }
36     panic!("Cannot determine OS from triple");
37 }
38
39 #[cfg(target_os = "windows")]
40 pub fn make_new_path(path: &str) -> String {
41
42     // Windows just uses PATH as the library search path, so we have to
43     // maintain the current value while adding our own
44     match env::var(lib_path_env_var()) {
45       Ok(curr) => {
46         format!("{}{}{}", path, path_div(), curr)
47       }
48       Err(..) => path.to_string()
49     }
50 }
51
52 #[cfg(target_os = "windows")]
53 pub fn lib_path_env_var() -> &'static str { "PATH" }
54
55 #[cfg(target_os = "windows")]
56 pub fn path_div() -> &'static str { ";" }
57
58 pub fn logv(config: &Config, s: String) {
59     debug!("{}", s);
60     if config.verbose { println!("{}", s); }
61 }