Skip to content

Commit a5b603b

Browse files
committed
Build libbacktrace/jemalloc only when their timestamps are older than sources
1 parent c025330 commit a5b603b

File tree

10 files changed

+94
-71
lines changed

10 files changed

+94
-71
lines changed

src/Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use std::fs::{self, File};
2121
use std::path::{Path, PathBuf};
2222
use std::process::Command;
2323

24-
use build_helper::output;
24+
use build_helper::{output, mtime};
2525
use filetime::FileTime;
2626

27-
use util::{exe, libdir, mtime, is_dylib, copy};
27+
use util::{exe, libdir, is_dylib, copy};
2828
use {Build, Compiler, Mode};
2929

3030
/// Build the standard library.

src/bootstrap/doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use std::io::prelude::*;
2222
use std::process::Command;
2323

2424
use {Build, Compiler, Mode};
25-
use util::{up_to_date, cp_r};
25+
use util::cp_r;
26+
use build_helper::up_to_date;
2627

2728
/// Invoke `rustbook` as compiled in `stage` for `target` for the doc book
2829
/// `name` into the `out` path.

src/bootstrap/lib.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
6767
#![deny(warnings)]
6868

69+
#[macro_use]
6970
extern crate build_helper;
7071
extern crate cmake;
7172
extern crate filetime;
@@ -83,24 +84,9 @@ use std::fs::{self, File};
8384
use std::path::{Component, PathBuf, Path};
8485
use std::process::Command;
8586

86-
use build_helper::{run_silent, output};
87+
use build_helper::{run_silent, output, mtime};
8788

88-
use util::{exe, mtime, libdir, add_lib_path};
89-
90-
/// A helper macro to `unwrap` a result except also print out details like:
91-
///
92-
/// * The file/line of the panic
93-
/// * The expression that failed
94-
/// * The error itself
95-
///
96-
/// This is currently used judiciously throughout the build system rather than
97-
/// using a `Result` with `try!`, but this may change one day...
98-
macro_rules! t {
99-
($e:expr) => (match $e {
100-
Ok(e) => e,
101-
Err(e) => panic!("{} failed with {}", stringify!($e), e),
102-
})
103-
}
89+
use util::{exe, libdir, add_lib_path};
10490

10591
mod cc;
10692
mod channel;

src/bootstrap/native.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use cmake;
2828
use gcc;
2929

3030
use Build;
31-
use util::{self, up_to_date};
31+
use util;
32+
use build_helper::up_to_date;
3233

3334
/// Compile LLVM for `target`.
3435
pub fn llvm(build: &Build, target: &str) {

src/bootstrap/util.rs

-37
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use std::path::{Path, PathBuf};
2020
use std::process::Command;
2121
use std::time::Instant;
2222

23-
use filetime::FileTime;
24-
2523
/// Returns the `name` as the filename of a static library for `target`.
2624
pub fn staticlib(name: &str, target: &str) -> String {
2725
if target.contains("windows") {
@@ -31,13 +29,6 @@ pub fn staticlib(name: &str, target: &str) -> String {
3129
}
3230
}
3331

34-
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
35-
pub fn mtime(path: &Path) -> FileTime {
36-
fs::metadata(path).map(|f| {
37-
FileTime::from_last_modification_time(&f)
38-
}).unwrap_or(FileTime::zero())
39-
}
40-
4132
/// Copies a file from `src` to `dst`, attempting to use hard links and then
4233
/// falling back to an actually filesystem copy if necessary.
4334
pub fn copy(src: &Path, dst: &Path) {
@@ -132,34 +123,6 @@ pub fn add_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
132123
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
133124
}
134125

135-
/// Returns whether `dst` is up to date given that the file or files in `src`
136-
/// are used to generate it.
137-
///
138-
/// Uses last-modified time checks to verify this.
139-
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
140-
let threshold = mtime(dst);
141-
let meta = match fs::metadata(src) {
142-
Ok(meta) => meta,
143-
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
144-
};
145-
if meta.is_dir() {
146-
dir_up_to_date(src, &threshold)
147-
} else {
148-
FileTime::from_last_modification_time(&meta) <= threshold
149-
}
150-
}
151-
152-
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
153-
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
154-
let meta = t!(e.metadata());
155-
if meta.is_dir() {
156-
dir_up_to_date(&e.path(), threshold)
157-
} else {
158-
FileTime::from_last_modification_time(&meta) < *threshold
159-
}
160-
})
161-
}
162-
163126
/// Returns the environment variable which the dynamic library lookup path
164127
/// resides in for this platform.
165128
pub fn dylib_path_var() -> &'static str {

src/build_helper/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ authors = ["The Rust Project Developers"]
66
[lib]
77
name = "build_helper"
88
path = "lib.rs"
9+
10+
[dependencies]
11+
filetime = "0.1"

src/build_helper/lib.rs

+56
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010

1111
#![deny(warnings)]
1212

13+
extern crate filetime;
14+
15+
use std::fs;
1316
use std::process::{Command, Stdio};
1417
use std::path::{Path, PathBuf};
1518

19+
use filetime::FileTime;
20+
21+
/// A helper macro to `unwrap` a result except also print out details like:
22+
///
23+
/// * The file/line of the panic
24+
/// * The expression that failed
25+
/// * The error itself
26+
///
27+
/// This is currently used judiciously throughout the build system rather than
28+
/// using a `Result` with `try!`, but this may change one day...
29+
#[macro_export]
30+
macro_rules! t {
31+
($e:expr) => (match $e {
32+
Ok(e) => e,
33+
Err(e) => panic!("{} failed with {}", stringify!($e), e),
34+
})
35+
}
36+
1637
pub fn run(cmd: &mut Command) {
1738
println!("running: {:?}", cmd);
1839
run_silent(cmd);
@@ -103,6 +124,41 @@ pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
103124
}
104125
}
105126

127+
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
128+
pub fn mtime(path: &Path) -> FileTime {
129+
fs::metadata(path).map(|f| {
130+
FileTime::from_last_modification_time(&f)
131+
}).unwrap_or(FileTime::zero())
132+
}
133+
134+
/// Returns whether `dst` is up to date given that the file or files in `src`
135+
/// are used to generate it.
136+
///
137+
/// Uses last-modified time checks to verify this.
138+
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
139+
let threshold = mtime(dst);
140+
let meta = match fs::metadata(src) {
141+
Ok(meta) => meta,
142+
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
143+
};
144+
if meta.is_dir() {
145+
dir_up_to_date(src, &threshold)
146+
} else {
147+
FileTime::from_last_modification_time(&meta) <= threshold
148+
}
149+
}
150+
151+
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
152+
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
153+
let meta = t!(e.metadata());
154+
if meta.is_dir() {
155+
dir_up_to_date(&e.path(), threshold)
156+
} else {
157+
FileTime::from_last_modification_time(&meta) < *threshold
158+
}
159+
})
160+
}
161+
106162
fn fail(s: &str) -> ! {
107163
println!("\n\n{}\n\n", s);
108164
std::process::exit(1);

src/liballoc_jemalloc/build.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
#![deny(warnings)]
1212

13+
#[macro_use]
1314
extern crate build_helper;
1415
extern crate gcc;
1516

16-
use std::{env, fs};
17-
use std::path::PathBuf;
17+
use std::env;
18+
use std::fs::{self, File};
19+
use std::path::{Path, PathBuf};
1820
use std::process::Command;
19-
use build_helper::{run, rerun_if_changed_anything_in_dir};
21+
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
2022

2123
fn main() {
2224
println!("cargo:rustc-cfg=cargobuild");
@@ -69,12 +71,13 @@ fn main() {
6971
} else if !target.contains("windows") && !target.contains("musl") {
7072
println!("cargo:rustc-link-lib=pthread");
7173
}
72-
if !cfg!(stage0) && target == host {
74+
let src_dir = env::current_dir().unwrap().join("../jemalloc");
75+
rerun_if_changed_anything_in_dir(&src_dir);
76+
let timestamp = build_dir.join("rustbuild.timestamp");
77+
if up_to_date(&Path::new("build.rs"), &timestamp) && up_to_date(&src_dir, &timestamp) {
7378
return
7479
}
7580

76-
let src_dir = env::current_dir().unwrap().join("../jemalloc");
77-
rerun_if_changed_anything_in_dir(&src_dir);
7881
let compiler = gcc::Config::new().get_compiler();
7982
// only msvc returns None for ar so unwrap is okay
8083
let ar = build_helper::cc2ar(compiler.path(), &target).unwrap();
@@ -184,4 +187,6 @@ fn main() {
184187
.file("pthread_atfork_dummy.c")
185188
.compile("libpthread_atfork_dummy.a");
186189
}
190+
191+
t!(File::create(&timestamp));
187192
}

src/libstd/build.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
#![deny(warnings)]
1212

13-
extern crate gcc;
13+
#[macro_use]
1414
extern crate build_helper;
15+
extern crate gcc;
1516

16-
use std::{env, fs};
17-
use std::path::PathBuf;
17+
use std::env;
18+
use std::fs::{self, File};
19+
use std::path::{Path, PathBuf};
1820
use std::process::Command;
19-
use build_helper::{run, rerun_if_changed_anything_in_dir};
21+
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
2022

2123
fn main() {
2224
println!("cargo:rustc-cfg=cargobuild");
@@ -71,12 +73,13 @@ fn build_libbacktrace(host: &str, target: &str) {
7173

7274
println!("cargo:rustc-link-lib=static=backtrace");
7375
println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
74-
if !cfg!(stage0) && target == host {
76+
let src_dir = env::current_dir().unwrap().join("../libbacktrace");
77+
rerun_if_changed_anything_in_dir(&src_dir);
78+
let timestamp = build_dir.join("rustbuild.timestamp");
79+
if up_to_date(&Path::new("build.rs"), &timestamp) && up_to_date(&src_dir, &timestamp) {
7580
return
7681
}
7782

78-
let src_dir = env::current_dir().unwrap().join("../libbacktrace");
79-
rerun_if_changed_anything_in_dir(&src_dir);
8083
let compiler = gcc::Config::new().get_compiler();
8184
// only msvc returns None for ar so unwrap is okay
8285
let ar = build_helper::cc2ar(compiler.path(), target).unwrap();
@@ -103,4 +106,6 @@ fn build_libbacktrace(host: &str, target: &str) {
103106
.current_dir(&build_dir)
104107
.arg(format!("INCDIR={}", src_dir.display()))
105108
.arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
109+
110+
t!(File::create(&timestamp));
106111
}

0 commit comments

Comments
 (0)