|
1 | 1 | //! Code for writing metadata to file |
2 | 2 | use anyhow::Result; |
| 3 | +use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI}; |
3 | 4 | use serde::Serialize; |
4 | 5 | use std::fs; |
5 | 6 | use std::path::Path; |
@@ -29,6 +30,7 @@ fn get_git_hash() -> String { |
29 | 30 | #[derive(Serialize, Default)] |
30 | 31 | struct Metadata<'a> { |
31 | 32 | program: ProgramMetadata<'a>, |
| 33 | + platform: PlatformMetadata, |
32 | 34 | } |
33 | 35 |
|
34 | 36 | /// Information about the version and build of MUSE |
@@ -64,6 +66,33 @@ impl Default for ProgramMetadata<'_> { |
64 | 66 | } |
65 | 67 | } |
66 | 68 |
|
| 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 | + |
67 | 96 | /// Write metadata to the specified output path in TOML format |
68 | 97 | pub fn write_metadata(output_path: &Path) -> Result<()> { |
69 | 98 | let metadata = Metadata::default(); |
|
0 commit comments