]> git.lizzy.rs Git - rust.git/blob - src/compiletest/util.rs
Replace all ~"" with "".to_owned()
[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 ];
25
26 pub fn get_os(triple: &str) -> &'static str {
27     for &(triple_os, os) in OS_TABLE.iter() {
28         if triple.contains(triple_os) {
29             return os
30         }
31     }
32     fail!("Cannot determine OS from triple");
33 }
34
35 #[cfg(target_os = "win32")]
36 pub fn make_new_path(path: &str) -> ~str {
37
38     // Windows just uses PATH as the library search path, so we have to
39     // maintain the current value while adding our own
40     match getenv(lib_path_env_var()) {
41       Some(curr) => {
42         format!("{}{}{}", path, path_div(), curr)
43       }
44       None => path.to_str()
45     }
46 }
47
48 #[cfg(target_os = "win32")]
49 pub fn lib_path_env_var() -> ~str { "PATH".to_owned() }
50
51 #[cfg(target_os = "win32")]
52 pub fn path_div() -> ~str { ";".to_owned() }
53
54 pub fn logv(config: &config, s: ~str) {
55     debug!("{}", s);
56     if config.verbose { println!("{}", s); }
57 }