2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-04-16 13:56:39 +09:00
|
|
|
use common::Config;
|
2011-07-30 21:11:14 -07:00
|
|
|
|
2014-08-10 21:26:45 -07:00
|
|
|
#[cfg(target_os = "windows")]
|
2013-06-30 19:36:55 -07:00
|
|
|
use std::os::getenv;
|
2013-03-01 10:44:43 -08:00
|
|
|
|
2013-09-03 19:34:23 +09:00
|
|
|
/// Conversion table from triple OS name to Rust SYSNAME
|
|
|
|
static OS_TABLE: &'static [(&'static str, &'static str)] = &[
|
2014-08-10 21:26:45 -07:00
|
|
|
("mingw32", "windows"),
|
|
|
|
("win32", "windows"),
|
|
|
|
("windows", "windows"),
|
2013-09-03 19:34:23 +09:00
|
|
|
("darwin", "macos"),
|
|
|
|
("android", "android"),
|
|
|
|
("linux", "linux"),
|
|
|
|
("freebsd", "freebsd"),
|
2014-07-31 02:23:35 +02:00
|
|
|
("dragonfly", "dragonfly"),
|
2013-09-03 19:34:23 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
pub fn get_os(triple: &str) -> &'static str {
|
|
|
|
for &(triple_os, os) in OS_TABLE.iter() {
|
|
|
|
if triple.contains(triple_os) {
|
|
|
|
return os
|
|
|
|
}
|
|
|
|
}
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!("Cannot determine OS from triple");
|
2013-09-03 19:34:23 +09:00
|
|
|
}
|
|
|
|
|
2014-08-10 21:26:45 -07:00
|
|
|
#[cfg(target_os = "windows")]
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn make_new_path(path: &str) -> String {
|
2011-07-30 21:11:14 -07:00
|
|
|
|
|
|
|
// Windows just uses PATH as the library search path, so we have to
|
|
|
|
// maintain the current value while adding our own
|
2014-06-25 07:35:54 +02:00
|
|
|
match getenv(lib_path_env_var()) {
|
2012-12-28 11:28:36 -05:00
|
|
|
Some(curr) => {
|
2014-05-27 20:44:58 -07:00
|
|
|
format!("{}{}{}", path, path_div(), curr)
|
2011-09-29 18:30:00 -07:00
|
|
|
}
|
2014-06-21 03:39:03 -07:00
|
|
|
None => path.to_string()
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 21:26:45 -07:00
|
|
|
#[cfg(target_os = "windows")]
|
2014-06-25 07:35:54 +02:00
|
|
|
pub fn lib_path_env_var() -> &'static str { "PATH" }
|
2011-07-30 21:11:14 -07:00
|
|
|
|
2014-08-10 21:26:45 -07:00
|
|
|
#[cfg(target_os = "windows")]
|
2014-06-25 07:35:54 +02:00
|
|
|
pub fn path_div() -> &'static str { ";" }
|
2011-09-29 18:30:00 -07:00
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn logv(config: &Config, s: String) {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("{}", s);
|
2014-01-09 21:06:55 +11:00
|
|
|
if config.verbose { println!("{}", s); }
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|