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.
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.
14 /// Conversion table from triple OS name to Rust SYSNAME
15 const OS_TABLE: &'static [(&'static str, &'static str)] = &[
16 ("android", "android"),
19 ("dragonfly", "dragonfly"),
20 ("freebsd", "freebsd"),
23 ("mingw32", "windows"),
25 ("openbsd", "openbsd"),
27 ("windows", "windows"),
30 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
31 ("aarch64", "aarch64"),
35 ("hexagon", "hexagon"),
40 ("powerpc", "powerpc"),
41 ("powerpc64", "powerpc64"),
42 ("powerpc64le", "powerpc64le"),
49 pub fn get_os(triple: &str) -> &'static str {
50 for &(triple_os, os) in OS_TABLE {
51 if triple.contains(triple_os) {
55 panic!("Cannot determine OS from triple");
57 pub fn get_arch(triple: &str) -> &'static str {
58 for &(triple_arch, arch) in ARCH_TABLE {
59 if triple.contains(triple_arch) {
63 panic!("Cannot determine Architecture from triple");
66 pub fn get_env(triple: &str) -> Option<&str> {
67 triple.split('-').nth(3)
70 pub fn make_new_path(path: &str) -> String {
71 assert!(cfg!(windows));
72 // Windows just uses PATH as the library search path, so we have to
73 // maintain the current value while adding our own
74 match env::var(lib_path_env_var()) {
76 format!("{}{}{}", path, path_div(), curr)
78 Err(..) => path.to_owned()
82 pub fn lib_path_env_var() -> &'static str { "PATH" }
83 fn path_div() -> &'static str { ";" }
85 pub fn logv(config: &Config, s: String) {
87 if config.verbose { println!("{}", s); }