mirror of https://github.com/astral-sh/uv
fix recompiling every time in uv-python (#16214)
Cargo is currently recompiling uv-python on every invocation because the minified JSON output file is getting a mod time newer than the last run. Instead, set the mod time of the output file to the same as the input file.
This commit is contained in:
parent
9887ef5bd7
commit
ea5a09215b
|
|
@ -1,3 +1,6 @@
|
||||||
|
#[allow(clippy::disallowed_types)]
|
||||||
|
use std::fs::{File, FileTimes};
|
||||||
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
|
|
@ -36,16 +39,37 @@ fn main() {
|
||||||
|
|
||||||
let json_data: serde_json::Value = serde_json::from_str(
|
let json_data: serde_json::Value = serde_json::from_str(
|
||||||
#[allow(clippy::disallowed_methods)]
|
#[allow(clippy::disallowed_methods)]
|
||||||
&fs::read_to_string(version_metadata).expect("Failed to read download-metadata.json"),
|
&fs::read_to_string(&version_metadata).expect("Failed to read download-metadata.json"),
|
||||||
)
|
)
|
||||||
.expect("Failed to parse JSON");
|
.expect("Failed to parse JSON");
|
||||||
|
|
||||||
let filtered_data = process_json(&json_data);
|
let filtered_data = process_json(&json_data);
|
||||||
|
|
||||||
|
#[allow(clippy::disallowed_types)]
|
||||||
|
let mut out_file = File::create(version_metadata_minified)
|
||||||
|
.expect("failed to open download-metadata-minified.json");
|
||||||
|
|
||||||
#[allow(clippy::disallowed_methods)]
|
#[allow(clippy::disallowed_methods)]
|
||||||
fs::write(
|
out_file
|
||||||
version_metadata_minified,
|
.write_all(
|
||||||
serde_json::to_string(&filtered_data).expect("Failed to serialize JSON"),
|
serde_json::to_string(&filtered_data)
|
||||||
)
|
.expect("Failed to serialize JSON")
|
||||||
.expect("Failed to write minified JSON");
|
.as_bytes(),
|
||||||
|
)
|
||||||
|
.expect("Failed to write minified JSON");
|
||||||
|
|
||||||
|
// Cargo uses the modified times of the paths specified in
|
||||||
|
// `rerun-if-changed`, so fetch the current file times and set them the same
|
||||||
|
// on the output file.
|
||||||
|
#[allow(clippy::disallowed_methods)]
|
||||||
|
let meta =
|
||||||
|
fs::metadata(version_metadata).expect("failed to read metadata for download-metadata.json");
|
||||||
|
|
||||||
|
out_file
|
||||||
|
.set_times(
|
||||||
|
FileTimes::new()
|
||||||
|
.set_accessed(meta.accessed().unwrap())
|
||||||
|
.set_modified(meta.modified().unwrap()),
|
||||||
|
)
|
||||||
|
.expect("failed to write file times to download-metadata-minified.json");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue