rename metadata_version to format_version

The new name is more accurate.
This commit is contained in:
Pietro Albini 2023-05-26 15:21:21 +02:00
parent cb68c05151
commit 7040d4102f
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E

View File

@ -19,7 +19,7 @@ use sysinfo::{CpuExt, System, SystemExt};
// Versions: // Versions:
// 0: initial version // 0: initial version
// 1: replaced JsonNode::Test with JsonNode::TestSuite // 1: replaced JsonNode::Test with JsonNode::TestSuite
const CURRENT_METADATA_VERSION: usize = 1; const CURRENT_FORMAT_VERSION: usize = 1;
pub(crate) struct BuildMetrics { pub(crate) struct BuildMetrics {
state: RefCell<MetricsState>, state: RefCell<MetricsState>,
@ -151,15 +151,15 @@ impl BuildMetrics {
// previous invocations are still present in the resulting file. // previous invocations are still present in the resulting file.
let mut invocations = match std::fs::read(&dest) { let mut invocations = match std::fs::read(&dest) {
Ok(contents) => { Ok(contents) => {
// We first parse just the metadata_version field to have the check succeed even if // We first parse just the format_version field to have the check succeed even if
// the rest of the contents are not valid anymore. // the rest of the contents are not valid anymore.
let version: OnlyMetadataVersion = t!(serde_json::from_slice(&contents)); let version: OnlyFormatVersion = t!(serde_json::from_slice(&contents));
if version.metadata_version == CURRENT_METADATA_VERSION { if version.format_version == CURRENT_FORMAT_VERSION {
t!(serde_json::from_slice::<JsonRoot>(&contents)).invocations t!(serde_json::from_slice::<JsonRoot>(&contents)).invocations
} else { } else {
println!( println!(
"warning: overriding existing build/metrics.json, as it's not \ "warning: overriding existing build/metrics.json, as it's not \
compatible with build metrics format version {CURRENT_METADATA_VERSION}." compatible with build metrics format version {CURRENT_FORMAT_VERSION}."
); );
Vec::new() Vec::new()
} }
@ -181,8 +181,7 @@ impl BuildMetrics {
children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(), children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(),
}); });
let json = let json = JsonRoot { format_version: CURRENT_FORMAT_VERSION, system_stats, invocations };
JsonRoot { metadata_version: CURRENT_METADATA_VERSION, system_stats, invocations };
t!(std::fs::create_dir_all(dest.parent().unwrap())); t!(std::fs::create_dir_all(dest.parent().unwrap()));
let mut file = BufWriter::new(t!(File::create(&dest))); let mut file = BufWriter::new(t!(File::create(&dest)));
@ -234,7 +233,7 @@ struct StepMetrics {
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
struct JsonRoot { struct JsonRoot {
#[serde(default)] // For version 0 the field was not present. #[serde(default)] // For version 0 the field was not present.
metadata_version: usize, format_version: usize,
system_stats: JsonInvocationSystemStats, system_stats: JsonInvocationSystemStats,
invocations: Vec<JsonInvocation>, invocations: Vec<JsonInvocation>,
} }
@ -322,7 +321,7 @@ struct JsonStepSystemStats {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
struct OnlyMetadataVersion { struct OnlyFormatVersion {
#[serde(default)] // For version 0 the field was not present. #[serde(default)] // For version 0 the field was not present.
metadata_version: usize, format_version: usize,
} }