about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorILyoan <ilyoan@gmail.com>2012-12-20 18:26:27 +0900
committerGraydon Hoare <graydon@mozilla.com>2013-01-08 14:35:28 -0800
commit2d3c22ae590a6ceadd612fbf775f258ca64baa90 (patch)
tree1c8dd845b01d38b5eb2a37ee8109fcbc7b93a951 /src
parent9f7dc1cb33599ea3c6b7e554e36888e8b20441b5 (diff)
downloadrust-2d3c22ae590a6ceadd612fbf775f258ca64baa90.tar.gz
rust-2d3c22ae590a6ceadd612fbf775f258ca64baa90.zip
arrange core::os::consts
Diffstat (limited to 'src')
-rw-r--r--src/compiletest/header.rs2
-rw-r--r--src/compiletest/runtest.rs3
-rw-r--r--src/libcargo/cargo.rc2
-rw-r--r--src/libcore/os.rs112
-rw-r--r--src/librustc/back/link.rs19
-rw-r--r--src/librustc/driver/driver.rs6
-rw-r--r--src/librustc/metadata/loader.rs16
7 files changed, 105 insertions, 55 deletions
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index 49753360279..730e863d04d 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -82,7 +82,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool {
     return found;
 
     fn xfail_target() -> ~str {
-        ~"xfail-" + os::sysname()
+        ~"xfail-" + str::from_slice(os::SYSNAME)
     }
 }
 
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 357d3c6cfb4..a7dbfb9a3b2 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -501,7 +501,8 @@ fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path {
 }
 
 fn make_exe_name(config: config, testfile: &Path) -> Path {
-    Path(output_base_name(config, testfile).to_str() + os::exe_suffix())
+    Path(output_base_name(config, testfile).to_str() +
+            str::from_slice(os::EXE_SUFFIX))
 }
 
 fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc
index d4e68746fd4..8d81f75e0da 100644
--- a/src/libcargo/cargo.rc
+++ b/src/libcargo/cargo.rc
@@ -805,7 +805,7 @@ fn install_one_crate(c: &Cargo, path: &Path, cf: &Path) {
       Some(bp) => bp
     };
     let newv = os::list_dir_path(&buildpath);
-    let exec_suffix = os::exe_suffix();
+    let exec_suffix = str::from_slice(os::EXE_SUFFIX);
     for newv.each |ct| {
         if (exec_suffix != ~"" && str::ends_with(ct.to_str(),
                                                  exec_suffix)) ||
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 2d9f95df749..b42d6d363e3 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -382,13 +382,8 @@ fn dup2(src: c_int, dst: c_int) -> c_int {
 
 
 pub fn dll_filename(base: &str) -> ~str {
-    return pre() + str::from_slice(base) + dll_suffix();
-
-    #[cfg(unix)]
-    fn pre() -> ~str { ~"lib" }
-
-    #[cfg(windows)]
-    fn pre() -> ~str { ~"" }
+    return str::from_slice(DLL_PREFIX) + str::from_slice(base) +
+           str::from_slice(DLL_SUFFIX)
 }
 
 
@@ -878,48 +873,83 @@ extern {
     pub fn _NSGetArgv() -> ***c_char;
 }
 
-#[cfg(unix)]
-pub fn family() -> ~str { ~"unix" }
+mod consts {
 
-#[cfg(windows)]
-pub fn family() -> ~str { ~"windows" }
+    #[cfg(unix)]
+    use os::consts::unix::*;
 
-#[cfg(target_os = "macos")]
-mod consts {
-    pub fn sysname() -> ~str { ~"macos" }
-    pub fn exe_suffix() -> ~str { ~"" }
-    pub fn dll_suffix() -> ~str { ~".dylib" }
-}
+    #[cfg(windows)]
+    use os::consts::windows::*;
 
-#[cfg(target_os = "freebsd")]
-mod consts {
-    pub fn sysname() -> ~str { ~"freebsd" }
-    pub fn exe_suffix() -> ~str { ~"" }
-    pub fn dll_suffix() -> ~str { ~".so" }
-}
+    pub mod unix {
+        pub const FAMILY: &str = "unix";
+    }
 
-#[cfg(target_os = "linux")]
-mod consts {
-    pub fn sysname() -> ~str { ~"linux" }
-    pub fn exe_suffix() -> ~str { ~"" }
-    pub fn dll_suffix() -> ~str { ~".so" }
-}
+    pub mod windows {
+        pub const FAMILY: &str = "windows";
+    }
 
-#[cfg(target_os = "win32")]
-mod consts {
-    pub fn sysname() -> ~str { ~"win32" }
-    pub fn exe_suffix() -> ~str { ~".exe" }
-    pub fn dll_suffix() -> ~str { ~".dll" }
-}
 
-#[cfg(target_arch = "x86")]
-pub fn arch() -> ~str { ~"x86" }
+    #[cfg(target_os = "macos")]
+    use os::consts::macos::*;
+
+    #[cfg(target_os = "freebsd")]
+    use os::consts::freebsd::*;
+
+    #[cfg(target_os = "linux")]
+    use os::consts::linux::*;
+
+    #[cfg(target_os = "win32")]
+    use os::consts::win32::*;
 
-#[cfg(target_arch = "x86_64")]
-pub fn arch() -> ~str { ~"x86_64" }
+    pub mod macos {
+        pub const SYSNAME: &str = "macos";
+        pub const DLL_PREFIX: &str = "lib";
+        pub const DLL_SUFFIX: &str = ".dylib";
+        pub const EXE_SUFFIX: &str = "";
+    }
+
+    pub mod freebsd {
+        pub const SYSNAME: &str = "freebsd";
+        pub const DLL_PREFIX: &str = "lib";
+        pub const DLL_SUFFIX: &str = ".so";
+        pub const EXE_SUFFIX: &str = "";
+    }
+
+    pub mod linux {
+        pub const SYSNAME: &str = "linux";
+        pub const DLL_PREFIX: &str = "lib";
+        pub const DLL_SUFFIX: &str = ".so";
+        pub const EXE_SUFFIX: &str = "";
+    }
 
-#[cfg(target_arch = "arm")]
-pub fn arch() -> str { ~"arm" }
+    pub mod win32 {
+        pub const SYSNAME: &str = "win32";
+        pub const DLL_PREFIX: &str = "";
+        pub const DLL_SUFFIX: &str = ".dll";
+        pub const EXE_SUFFIX: &str = ".exe";
+    }
+
+
+    #[cfg(target_arch = "x86")]
+    use os::consts::x86::*;
+
+    #[cfg(target_arch = "x86_64")]
+    use os::consts::x86_64::*;
+
+    #[cfg(target_arch = "arm")]
+    use os::consts::arm::*;
+
+    pub mod x86 {
+        pub const ARCH: &str = "x86";
+    }
+    pub mod x86_64 {
+        pub const ARCH: &str = "x86_64";
+    }
+    pub mod arm {
+        pub const ARCH: &str = "arm";
+    }
+}
 
 #[cfg(test)]
 #[allow(non_implicitly_copyable_typarams)]
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 17222b7498b..59d9886455a 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -41,6 +41,8 @@ use syntax::ast_map::{path, path_mod, path_name};
 use syntax::attr;
 use syntax::print::pprust;
 
+use core::os::consts::{macos, freebsd, linux, win32};
+
 enum output_type {
     output_type_none,
     output_type_bitcode,
@@ -676,6 +678,19 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
     return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
 }
 
+
+fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
+    let libname = fmt!("%s-%s-%s", lm.name, lm.extras_hash, lm.vers);
+    let (dll_prefix, dll_suffix) = match os {
+        session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
+        session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
+        session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
+        session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
+    };
+    return str::from_slice(dll_prefix) + libname +
+           str::from_slice(dll_suffix);
+}
+
 // If the user wants an exe generated we need to invoke
 // cc to link the object file with some libs
 fn link_binary(sess: Session,
@@ -693,9 +708,7 @@ fn link_binary(sess: Session,
     }
 
     let output = if sess.building_library {
-        let long_libname =
-            os::dll_filename(fmt!("%s-%s-%s",
-                                  lm.name, lm.extras_hash, lm.vers));
+        let long_libname = output_dll_filename(sess.targ_cfg.os, &lm);
         debug!("link_meta.name:  %s", lm.name);
         debug!("long_libname: %s", long_libname);
         debug!("out_filename: %s", out_filename.to_str());
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index b5f57d904bc..3212adf29ac 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -86,9 +86,9 @@ fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
     };
 
     return ~[ // Target bindings.
-         attr::mk_word_item(os::family()),
-         mk(~"target_os", os::sysname()),
-         mk(~"target_family", os::family()),
+         attr::mk_word_item(str::from_slice(os::FAMILY)),
+         mk(~"target_os", str::from_slice(os::SYSNAME)),
+         mk(~"target_family", str::from_slice(os::FAMILY)),
          mk(~"target_arch", arch),
          mk(~"target_word_size", wordsz),
          mk(~"target_libc", libc),
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 818b93545cf..fa858f9e9a3 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -32,6 +32,8 @@ use core::str;
 use core::uint;
 use core::vec;
 
+use core::os::consts::{macos, freebsd, linux, win32};
+
 export os;
 export os_macos, os_win32, os_linux, os_freebsd;
 export ctxt;
@@ -79,11 +81,15 @@ fn find_library_crate(cx: ctxt) -> Option<{ident: ~str, data: @~[u8]}> {
 
 fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
     if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
-    match cx.os {
-      os_win32 => return {prefix: ~"", suffix: ~".dll"},
-      os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
-      os_linux => return {prefix: ~"lib", suffix: ~".so"},
-      os_freebsd => return {prefix: ~"lib", suffix: ~".so"}
+    let (dll_prefix, dll_suffix) = match cx.os {
+        os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
+        os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
+        os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
+        os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
+    };
+    return {
+        prefix: str::from_slice(dll_prefix),
+        suffix: str::from_slice(dll_suffix)
     }
 }