Skip to content

Commit 2d3c22a

Browse files
ILyoangraydon
authored andcommitted
arrange core::os::consts
1 parent 9f7dc1c commit 2d3c22a

File tree

7 files changed

+105
-55
lines changed

7 files changed

+105
-55
lines changed

src/compiletest/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool {
8282
return found;
8383

8484
fn xfail_target() -> ~str {
85-
~"xfail-" + os::sysname()
85+
~"xfail-" + str::from_slice(os::SYSNAME)
8686
}
8787
}
8888

src/compiletest/runtest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path {
501501
}
502502

503503
fn make_exe_name(config: config, testfile: &Path) -> Path {
504-
Path(output_base_name(config, testfile).to_str() + os::exe_suffix())
504+
Path(output_base_name(config, testfile).to_str() +
505+
str::from_slice(os::EXE_SUFFIX))
505506
}
506507

507508
fn make_run_args(config: config, _props: test_props, testfile: &Path) ->

src/libcargo/cargo.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ fn install_one_crate(c: &Cargo, path: &Path, cf: &Path) {
805805
Some(bp) => bp
806806
};
807807
let newv = os::list_dir_path(&buildpath);
808-
let exec_suffix = os::exe_suffix();
808+
let exec_suffix = str::from_slice(os::EXE_SUFFIX);
809809
for newv.each |ct| {
810810
if (exec_suffix != ~"" && str::ends_with(ct.to_str(),
811811
exec_suffix)) ||

src/libcore/os.rs

+71-41
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,8 @@ fn dup2(src: c_int, dst: c_int) -> c_int {
382382

383383

384384
pub fn dll_filename(base: &str) -> ~str {
385-
return pre() + str::from_slice(base) + dll_suffix();
386-
387-
#[cfg(unix)]
388-
fn pre() -> ~str { ~"lib" }
389-
390-
#[cfg(windows)]
391-
fn pre() -> ~str { ~"" }
385+
return str::from_slice(DLL_PREFIX) + str::from_slice(base) +
386+
str::from_slice(DLL_SUFFIX)
392387
}
393388

394389

@@ -878,48 +873,83 @@ extern {
878873
pub fn _NSGetArgv() -> ***c_char;
879874
}
880875

881-
#[cfg(unix)]
882-
pub fn family() -> ~str { ~"unix" }
876+
mod consts {
883877

884-
#[cfg(windows)]
885-
pub fn family() -> ~str { ~"windows" }
878+
#[cfg(unix)]
879+
use os::consts::unix::*;
886880

887-
#[cfg(target_os = "macos")]
888-
mod consts {
889-
pub fn sysname() -> ~str { ~"macos" }
890-
pub fn exe_suffix() -> ~str { ~"" }
891-
pub fn dll_suffix() -> ~str { ~".dylib" }
892-
}
881+
#[cfg(windows)]
882+
use os::consts::windows::*;
893883

894-
#[cfg(target_os = "freebsd")]
895-
mod consts {
896-
pub fn sysname() -> ~str { ~"freebsd" }
897-
pub fn exe_suffix() -> ~str { ~"" }
898-
pub fn dll_suffix() -> ~str { ~".so" }
899-
}
884+
pub mod unix {
885+
pub const FAMILY: &str = "unix";
886+
}
900887

901-
#[cfg(target_os = "linux")]
902-
mod consts {
903-
pub fn sysname() -> ~str { ~"linux" }
904-
pub fn exe_suffix() -> ~str { ~"" }
905-
pub fn dll_suffix() -> ~str { ~".so" }
906-
}
888+
pub mod windows {
889+
pub const FAMILY: &str = "windows";
890+
}
907891

908-
#[cfg(target_os = "win32")]
909-
mod consts {
910-
pub fn sysname() -> ~str { ~"win32" }
911-
pub fn exe_suffix() -> ~str { ~".exe" }
912-
pub fn dll_suffix() -> ~str { ~".dll" }
913-
}
914892

915-
#[cfg(target_arch = "x86")]
916-
pub fn arch() -> ~str { ~"x86" }
893+
#[cfg(target_os = "macos")]
894+
use os::consts::macos::*;
895+
896+
#[cfg(target_os = "freebsd")]
897+
use os::consts::freebsd::*;
898+
899+
#[cfg(target_os = "linux")]
900+
use os::consts::linux::*;
901+
902+
#[cfg(target_os = "win32")]
903+
use os::consts::win32::*;
917904

918-
#[cfg(target_arch = "x86_64")]
919-
pub fn arch() -> ~str { ~"x86_64" }
905+
pub mod macos {
906+
pub const SYSNAME: &str = "macos";
907+
pub const DLL_PREFIX: &str = "lib";
908+
pub const DLL_SUFFIX: &str = ".dylib";
909+
pub const EXE_SUFFIX: &str = "";
910+
}
911+
912+
pub mod freebsd {
913+
pub const SYSNAME: &str = "freebsd";
914+
pub const DLL_PREFIX: &str = "lib";
915+
pub const DLL_SUFFIX: &str = ".so";
916+
pub const EXE_SUFFIX: &str = "";
917+
}
918+
919+
pub mod linux {
920+
pub const SYSNAME: &str = "linux";
921+
pub const DLL_PREFIX: &str = "lib";
922+
pub const DLL_SUFFIX: &str = ".so";
923+
pub const EXE_SUFFIX: &str = "";
924+
}
920925

921-
#[cfg(target_arch = "arm")]
922-
pub fn arch() -> str { ~"arm" }
926+
pub mod win32 {
927+
pub const SYSNAME: &str = "win32";
928+
pub const DLL_PREFIX: &str = "";
929+
pub const DLL_SUFFIX: &str = ".dll";
930+
pub const EXE_SUFFIX: &str = ".exe";
931+
}
932+
933+
934+
#[cfg(target_arch = "x86")]
935+
use os::consts::x86::*;
936+
937+
#[cfg(target_arch = "x86_64")]
938+
use os::consts::x86_64::*;
939+
940+
#[cfg(target_arch = "arm")]
941+
use os::consts::arm::*;
942+
943+
pub mod x86 {
944+
pub const ARCH: &str = "x86";
945+
}
946+
pub mod x86_64 {
947+
pub const ARCH: &str = "x86_64";
948+
}
949+
pub mod arm {
950+
pub const ARCH: &str = "arm";
951+
}
952+
}
923953

924954
#[cfg(test)]
925955
#[allow(non_implicitly_copyable_typarams)]

src/librustc/back/link.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ use syntax::ast_map::{path, path_mod, path_name};
4141
use syntax::attr;
4242
use syntax::print::pprust;
4343

44+
use core::os::consts::{macos, freebsd, linux, win32};
45+
4446
enum output_type {
4547
output_type_none,
4648
output_type_bitcode,
@@ -676,6 +678,19 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
676678
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
677679
}
678680

681+
682+
fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
683+
let libname = fmt!("%s-%s-%s", lm.name, lm.extras_hash, lm.vers);
684+
let (dll_prefix, dll_suffix) = match os {
685+
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
686+
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
687+
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
688+
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
689+
};
690+
return str::from_slice(dll_prefix) + libname +
691+
str::from_slice(dll_suffix);
692+
}
693+
679694
// If the user wants an exe generated we need to invoke
680695
// cc to link the object file with some libs
681696
fn link_binary(sess: Session,
@@ -693,9 +708,7 @@ fn link_binary(sess: Session,
693708
}
694709

695710
let output = if sess.building_library {
696-
let long_libname =
697-
os::dll_filename(fmt!("%s-%s-%s",
698-
lm.name, lm.extras_hash, lm.vers));
711+
let long_libname = output_dll_filename(sess.targ_cfg.os, &lm);
699712
debug!("link_meta.name: %s", lm.name);
700713
debug!("long_libname: %s", long_libname);
701714
debug!("out_filename: %s", out_filename.to_str());

src/librustc/driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
8686
};
8787

8888
return ~[ // Target bindings.
89-
attr::mk_word_item(os::family()),
90-
mk(~"target_os", os::sysname()),
91-
mk(~"target_family", os::family()),
89+
attr::mk_word_item(str::from_slice(os::FAMILY)),
90+
mk(~"target_os", str::from_slice(os::SYSNAME)),
91+
mk(~"target_family", str::from_slice(os::FAMILY)),
9292
mk(~"target_arch", arch),
9393
mk(~"target_word_size", wordsz),
9494
mk(~"target_libc", libc),

src/librustc/metadata/loader.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use core::str;
3232
use core::uint;
3333
use core::vec;
3434

35+
use core::os::consts::{macos, freebsd, linux, win32};
36+
3537
export os;
3638
export os_macos, os_win32, os_linux, os_freebsd;
3739
export ctxt;
@@ -79,11 +81,15 @@ fn find_library_crate(cx: ctxt) -> Option<{ident: ~str, data: @~[u8]}> {
7981

8082
fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
8183
if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
82-
match cx.os {
83-
os_win32 => return {prefix: ~"", suffix: ~".dll"},
84-
os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
85-
os_linux => return {prefix: ~"lib", suffix: ~".so"},
86-
os_freebsd => return {prefix: ~"lib", suffix: ~".so"}
84+
let (dll_prefix, dll_suffix) = match cx.os {
85+
os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
86+
os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
87+
os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
88+
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
89+
};
90+
return {
91+
prefix: str::from_slice(dll_prefix),
92+
suffix: str::from_slice(dll_suffix)
8793
}
8894
}
8995

0 commit comments

Comments
 (0)