Skip to content

Commit 652b257

Browse files
committed
Reimplement touch_all() to be xplat
1 parent 736d3c1 commit 652b257

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobserver = "0.1.21"
3030
crossbeam-utils = "0.7"
3131
snap = "1"
3232
filetime = "0.2.14"
33+
walkdir = "2"
3334

3435
[target.'cfg(windows)'.dependencies]
3536
miow = "0.3"

collector/src/execute.rs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use collector::{command_output, robocopy};
66
use database::{PatchName, QueryLabel};
77
use futures::stream::FuturesUnordered;
88
use futures::stream::StreamExt;
9-
use std::cmp;
9+
use std::{cmp, ffi::OsStr, path::Component};
1010
use std::collections::HashMap;
1111
use std::env;
1212
use std::fmt;
@@ -58,29 +58,48 @@ fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<()>
5858
Ok(())
5959
}
6060

61-
fn touch(root: &Path, path: &Path) -> anyhow::Result<()> {
62-
let joined = root.join(path);
61+
fn touch(path: &Path) -> anyhow::Result<()> {
62+
log::info!("touching file {:?}", path);
6363

64-
log::info!("touching file {:?}", joined);
65-
66-
filetime::set_file_mtime(&joined, filetime::FileTime::now()).with_context(|| format!("touching file {:?}", joined))?;
64+
filetime::set_file_mtime(path, filetime::FileTime::now()).with_context(|| format!("touching file {:?}", path))?;
6765

6866
Ok(())
6967
}
7068

7169
fn touch_all(path: &Path) -> anyhow::Result<()> {
72-
let mut cmd = Command::new("bash");
73-
// Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
74-
// Don't touch build scripts, which confuses the wrapped rustc.
75-
cmd.current_dir(path)
76-
.args(&["-c", "find . -path ./target -prune -false -o -name '*.rs' | grep -v '^./build.rs$' | xargs touch"]);
77-
command_output(&mut cmd).with_context(|| format!("touching all .rs in {:?}", path))?;
78-
// We also delete the cmake caches to avoid errors when moving directories around.
79-
// This might be a bit slower but at least things build
80-
let mut cmd = Command::new("bash");
81-
cmd.current_dir(path)
82-
.args(&["-c", "find . -name 'CMakeCache.txt' -delete"]);
83-
command_output(&mut cmd).with_context(|| format!("deleting cmake caches in {:?}", path))?;
70+
fn is_valid(path: &Path) -> bool {
71+
let target_dir = Component::Normal(OsStr::new("target"));
72+
73+
// Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
74+
if path.components().any(|component| component == target_dir) {
75+
return false;
76+
}
77+
78+
if let Some(extn) = path.extension() {
79+
if extn.to_str() == Some("rs") {
80+
// Don't touch build scripts, which confuses the wrapped rustc.
81+
return path.file_name() != Some(OsStr::new("build.rs"));
82+
}
83+
}
84+
85+
false
86+
}
87+
88+
for entry in walkdir::WalkDir::new(path) {
89+
let entry = entry?;
90+
let path = entry.path();
91+
92+
// We also delete the cmake caches to avoid errors when moving directories around.
93+
// This might be a bit slower but at least things build
94+
if path.file_name() == Some(OsStr::new("CMakeCache.txt")) {
95+
fs::remove_file(path).with_context(|| format!("deleting cmake caches in {:?}", path))?;
96+
}
97+
98+
if is_valid(path) {
99+
touch(path)?;
100+
}
101+
}
102+
84103
Ok(())
85104
}
86105

@@ -397,7 +416,7 @@ impl<'a> CargoProcess<'a> {
397416
// in-tree (e.g., in the case of the servo crates there are a lot of
398417
// other components).
399418
if let Some(file) = &self.touch_file {
400-
touch(&self.cwd, Path::new(&file))?;
419+
touch(&self.cwd.join(Path::new(&file)))?;
401420
} else {
402421
touch_all(
403422
&self.cwd.join(

0 commit comments

Comments
 (0)