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