|
16 | 16 | //! compiler. This module is also responsible for assembling the sysroot as it
|
17 | 17 | //! goes along from the output of the previous stage.
|
18 | 18 |
|
19 |
| -use std::cmp; |
20 | 19 | use std::collections::HashMap;
|
21 | 20 | use std::fs::{self, File};
|
22 | 21 | use std::path::{Path, PathBuf};
|
@@ -59,7 +58,7 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) {
|
59 | 58 | }
|
60 | 59 |
|
61 | 60 | build.run(&mut cargo);
|
62 |
| - update_mtime(&libstd_stamp(build, &compiler, target)); |
| 61 | + update_mtime(build, &libstd_stamp(build, &compiler, target)); |
63 | 62 | }
|
64 | 63 |
|
65 | 64 | /// Link all libstd rlibs/dylibs into the sysroot location.
|
@@ -145,7 +144,7 @@ pub fn test(build: &Build, target: &str, compiler: &Compiler) {
|
145 | 144 | cargo.arg("--manifest-path")
|
146 | 145 | .arg(build.src.join("src/rustc/test_shim/Cargo.toml"));
|
147 | 146 | build.run(&mut cargo);
|
148 |
| - update_mtime(&libtest_stamp(build, compiler, target)); |
| 147 | + update_mtime(build, &libtest_stamp(build, compiler, target)); |
149 | 148 | }
|
150 | 149 |
|
151 | 150 | /// Same as `std_link`, only for libtest
|
@@ -390,26 +389,39 @@ pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
|
390 | 389 | }
|
391 | 390 |
|
392 | 391 | /// Updates the mtime of a stamp file if necessary, only changing it if it's
|
393 |
| -/// older than some other file in the same directory. |
| 392 | +/// older than some other library file in the same directory. |
394 | 393 | ///
|
395 | 394 | /// We don't know what file Cargo is going to output (because there's a hash in
|
396 | 395 | /// the file name) but we know where it's going to put it. We use this helper to
|
397 | 396 | /// detect changes to that output file by looking at the modification time for
|
398 | 397 | /// all files in a directory and updating the stamp if any are newer.
|
399 |
| -fn update_mtime(path: &Path) { |
400 |
| - let mut max = None; |
401 |
| - if let Ok(entries) = path.parent().unwrap().join("deps").read_dir() { |
402 |
| - for entry in entries.map(|e| t!(e)) { |
403 |
| - if t!(entry.file_type()).is_file() { |
404 |
| - let meta = t!(entry.metadata()); |
405 |
| - let time = FileTime::from_last_modification_time(&meta); |
406 |
| - max = cmp::max(max, Some(time)); |
407 |
| - } |
408 |
| - } |
409 |
| - } |
410 |
| - |
411 |
| - if !max.is_none() && max <= Some(mtime(path)) { |
412 |
| - return |
| 398 | +/// |
| 399 | +/// Note that we only consider Rust libraries as that's what we're interested in |
| 400 | +/// propagating changes from. Files like executables are tracked elsewhere. |
| 401 | +fn update_mtime(build: &Build, path: &Path) { |
| 402 | + let entries = match path.parent().unwrap().join("deps").read_dir() { |
| 403 | + Ok(entries) => entries, |
| 404 | + Err(_) => return, |
| 405 | + }; |
| 406 | + let files = entries.map(|e| t!(e)).filter(|e| t!(e.file_type()).is_file()); |
| 407 | + let files = files.filter(|e| { |
| 408 | + let filename = e.file_name(); |
| 409 | + let filename = filename.to_str().unwrap(); |
| 410 | + filename.ends_with(".rlib") || |
| 411 | + filename.ends_with(".lib") || |
| 412 | + is_dylib(&filename) |
| 413 | + }); |
| 414 | + let max = files.max_by_key(|entry| { |
| 415 | + let meta = t!(entry.metadata()); |
| 416 | + FileTime::from_last_modification_time(&meta) |
| 417 | + }); |
| 418 | + let max = match max { |
| 419 | + Some(max) => max, |
| 420 | + None => return, |
| 421 | + }; |
| 422 | + |
| 423 | + if mtime(&max.path()) > mtime(path) { |
| 424 | + build.verbose(&format!("updating {:?} as {:?} changed", path, max.path())); |
| 425 | + t!(File::create(path)); |
413 | 426 | }
|
414 |
| - t!(File::create(path)); |
415 | 427 | }
|
0 commit comments