Skip to content

Commit 4117bc4

Browse files
committed
Include platform info in metadata
1 parent e559939 commit 4117bc4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/output/metadata.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Code for writing metadata to file
22
use anyhow::Result;
3+
use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI};
34
use serde::Serialize;
45
use std::fs;
56
use std::path::Path;
@@ -29,6 +30,7 @@ fn get_git_hash() -> String {
2930
#[derive(Serialize, Default)]
3031
struct Metadata<'a> {
3132
program: ProgramMetadata<'a>,
33+
platform: PlatformMetadata,
3234
}
3335

3436
/// Information about the version and build of MUSE
@@ -64,6 +66,33 @@ impl Default for ProgramMetadata<'_> {
6466
}
6567
}
6668

69+
/// Information about the platform on which MUSE is running.
70+
///
71+
/// The fields correspond to different data available from the [`PlatformInfo`] struct.
72+
#[derive(Serialize)]
73+
struct PlatformMetadata {
74+
sysname: String,
75+
nodename: String,
76+
release: String,
77+
version: String,
78+
machine: String,
79+
osname: String,
80+
}
81+
82+
impl Default for PlatformMetadata {
83+
fn default() -> Self {
84+
let info = PlatformInfo::new().expect("Unable to determine platform info");
85+
Self {
86+
sysname: info.sysname().to_string_lossy().into(),
87+
nodename: info.nodename().to_string_lossy().into(),
88+
release: info.release().to_string_lossy().into(),
89+
version: info.version().to_string_lossy().into(),
90+
machine: info.machine().to_string_lossy().into(),
91+
osname: info.osname().to_string_lossy().into(),
92+
}
93+
}
94+
}
95+
6796
/// Write metadata to the specified output path in TOML format
6897
pub fn write_metadata(output_path: &Path) -> Result<()> {
6998
let metadata = Metadata::default();

0 commit comments

Comments
 (0)