arrange core::os::consts

This commit is contained in:
ILyoan 2012-12-20 18:26:27 +09:00 committed by Graydon Hoare
parent 9f7dc1cb33
commit 2d3c22ae59
7 changed files with 111 additions and 61 deletions

View File

@ -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)
}
}

View File

@ -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) ->

View File

@ -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)) ||

View File

@ -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,49 +873,84 @@ extern {
pub fn _NSGetArgv() -> ***c_char;
}
#[cfg(unix)]
pub fn family() -> ~str { ~"unix" }
#[cfg(windows)]
pub fn family() -> ~str { ~"windows" }
#[cfg(target_os = "macos")]
mod consts {
pub fn sysname() -> ~str { ~"macos" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".dylib" }
#[cfg(unix)]
use os::consts::unix::*;
#[cfg(windows)]
use os::consts::windows::*;
pub mod unix {
pub const FAMILY: &str = "unix";
}
pub mod windows {
pub const FAMILY: &str = "windows";
}
#[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::*;
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 = "";
}
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(target_os = "freebsd")]
mod consts {
pub fn sysname() -> ~str { ~"freebsd" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".so" }
}
#[cfg(target_os = "linux")]
mod consts {
pub fn sysname() -> ~str { ~"linux" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".so" }
}
#[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_arch = "x86_64")]
pub fn arch() -> ~str { ~"x86_64" }
#[cfg(target_arch = "arm")]
pub fn arch() -> str { ~"arm" }
#[cfg(test)]
#[allow(non_implicitly_copyable_typarams)]
mod tests {

View File

@ -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());

View File

@ -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),

View File

@ -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)
}
}