1 // Copyright 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.
12 use std
::path
::{Path, PathBuf}
;
14 use std
::process
::Command
;
16 use bootstrap
::{dylib_path, dylib_path_var}
;
17 use filetime
::FileTime
;
19 pub fn staticlib(name
: &str, target
: &str) -> String
{
20 if target
.contains("windows-msvc") {
21 format
!("{}.lib", name
)
23 format
!("lib{}.a", name
)
27 pub fn mtime(path
: &Path
) -> FileTime
{
28 fs
::metadata(path
).map(|f
| {
29 FileTime
::from_last_modification_time(&f
)
30 }).unwrap_or(FileTime
::zero())
33 pub fn copy(src
: &Path
, dst
: &Path
) {
34 let res
= fs
::hard_link(src
, dst
);
35 let res
= res
.or_else(|_
| fs
::copy(src
, dst
).map(|_
| ()));
37 panic
!("failed to copy `{}` to `{}`: {}", src
.display(),
42 pub fn cp_r(src
: &Path
, dst
: &Path
) {
43 for f
in t
!(fs
::read_dir(src
)) {
46 let name
= path
.file_name().unwrap();
47 let dst
= dst
.join(name
);
48 if t
!(f
.file_type()).is_dir() {
49 let _
= fs
::remove_dir_all(&dst
);
50 t
!(fs
::create_dir(&dst
));
53 let _
= fs
::remove_file(&dst
);
59 /// Given an executable called `name`, return the filename for the
60 /// executable for a particular target.
61 pub fn exe(name
: &str, target
: &str) -> String
{
62 if target
.contains("windows") {
63 format
!("{}.exe", name
)
69 pub fn is_dylib(name
: &str) -> bool
{
70 name
.ends_with(".dylib") || name
.ends_with(".so") || name
.ends_with(".dll")
73 pub fn libdir(target
: &str) -> &'
static str {
74 if target
.contains("windows") {"bin"}
else {"lib"}
77 pub fn add_lib_path(path
: Vec
<PathBuf
>, cmd
: &mut Command
) {
78 let mut list
= dylib_path();
82 cmd
.env(dylib_path_var(), t
!(env
::join_paths(list
)));
85 #[allow(dead_code)] // this will be used soon
86 pub fn up_to_date(src
: &Path
, dst
: &Path
) -> bool
{
87 let threshold
= mtime(dst
);
88 let meta
= t
!(fs
::metadata(src
));
90 dir_up_to_date(src
, &threshold
)
92 FileTime
::from_last_modification_time(&meta
) <= threshold
96 fn dir_up_to_date(src
: &Path
, threshold
: &FileTime
) -> bool
{
97 t
!(fs
::read_dir(src
)).map(|e
| t
!(e
)).all(|e
| {
98 let meta
= t
!(e
.metadata());
100 dir_up_to_date(&e
.path(), threshold
)
102 FileTime
::from_last_modification_time(&meta
) < *threshold