Put final touches
This commit is contained in:
@@ -44,65 +44,58 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_timestamp(build: &Builder<'_>) -> bool {
|
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, PathBuf)> {
|
||||||
let stamp_file = {
|
let stamp_file = build.out.join("rustfmt.stamp");
|
||||||
let mut s = build.out.clone();
|
|
||||||
s.push("rustfmt.stamp");
|
|
||||||
s
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut cmd = Command::new(match build.initial_rustfmt() {
|
let mut cmd = Command::new(match build.initial_rustfmt() {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => return false,
|
None => return None,
|
||||||
});
|
});
|
||||||
cmd.arg("--version");
|
cmd.arg("--version");
|
||||||
let output = match cmd.output() {
|
let output = match cmd.output() {
|
||||||
Ok(status) => status,
|
Ok(status) => status,
|
||||||
Err(_) => return false,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return false;
|
return None;
|
||||||
}
|
}
|
||||||
let version = String::from_utf8(output.stdout).unwrap();
|
Some((String::from_utf8(output.stdout).unwrap(), stamp_file))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return whether the format cache can be reused.
|
||||||
|
fn verify_rustfmt_version(build: &Builder<'_>) -> bool {
|
||||||
|
let Some((version, stamp_file)) = get_rustfmt_version(build) else {return false;};
|
||||||
!program_out_of_date(&stamp_file, &version)
|
!program_out_of_date(&stamp_file, &version)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_timestamp(build: &Builder<'_>) {
|
/// Updates the last rustfmt version used
|
||||||
let stamp_file = {
|
fn update_rustfmt_version(build: &Builder<'_>) {
|
||||||
let mut s = build.out.clone();
|
let Some((version, stamp_file)) = get_rustfmt_version(build) else {return;};
|
||||||
s.push("rustfmt.stamp");
|
|
||||||
s
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut cmd = Command::new(match build.initial_rustfmt() {
|
|
||||||
Some(p) => p,
|
|
||||||
None => return,
|
|
||||||
});
|
|
||||||
cmd.arg("--version");
|
|
||||||
let output = match cmd.output() {
|
|
||||||
Ok(status) => status,
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
if !output.status.success() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let version = String::from_utf8(output.stdout).unwrap();
|
|
||||||
|
|
||||||
t!(std::fs::write(stamp_file, version))
|
t!(std::fs::write(stamp_file, version))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the files modified between the `merge-base` of HEAD and
|
||||||
|
/// rust-lang/master and what is now on the disk.
|
||||||
|
///
|
||||||
|
/// Returns `None` if all files should be formatted.
|
||||||
fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
|
fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
|
||||||
let Ok(remote) = get_rust_lang_rust_remote() else {return None;};
|
let Ok(remote) = get_rust_lang_rust_remote() else {return None;};
|
||||||
if !verify_timestamp(build) {
|
if !verify_rustfmt_version(build) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let base =
|
|
||||||
output(build.config.git().arg("merge-base").arg("HEAD").arg(format!("{remote}/master")));
|
|
||||||
Some(
|
Some(
|
||||||
output(build.config.git().arg("diff").arg("--name-only").arg(base.trim()))
|
output(
|
||||||
.lines()
|
build
|
||||||
.map(|s| s.trim().to_owned())
|
.config
|
||||||
.collect(),
|
.git()
|
||||||
|
.arg("diff-index")
|
||||||
|
.arg("--name-only")
|
||||||
|
.arg("--merge-base")
|
||||||
|
.arg(&format!("{remote}/master")),
|
||||||
|
)
|
||||||
|
.lines()
|
||||||
|
.map(|s| s.trim().to_owned())
|
||||||
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +279,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
|||||||
drop(tx);
|
drop(tx);
|
||||||
|
|
||||||
thread.join().unwrap();
|
thread.join().unwrap();
|
||||||
|
if !check {
|
||||||
update_timestamp(build);
|
update_rustfmt_version(build);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user