@@ -14,12 +14,12 @@ use std::fs;
1414use std:: fs:: File ;
1515use std:: path:: { Path , PathBuf } ;
1616
17+ pub mod metadata;
18+ use metadata:: write_metadata;
19+
1720/// The root folder in which model-specific output folders will be created
1821const OUTPUT_DIRECTORY_ROOT : & str = "muse2_results" ;
1922
20- /// The output file name for metadata
21- const METADATA_FILE_NAME : & str = "metadata.toml" ;
22-
2323/// The output file name for commodity flows
2424const COMMODITY_FLOWS_FILE_NAME : & str = "commodity_flows.csv" ;
2525
@@ -66,72 +66,6 @@ pub fn create_output_directory(output_dir: &Path) -> Result<()> {
6666 Ok ( ( ) )
6767}
6868
69- #[ derive( Serialize , Default ) ]
70- struct Metadata < ' a > {
71- program : ProgramMetadata < ' a > ,
72- }
73-
74- /// Information about the version and build of MUSE
75- #[ derive( Serialize ) ]
76- struct ProgramMetadata < ' a > {
77- /// The program name
78- name : & ' a str ,
79- /// The program version as specified in Cargo.toml
80- version : & ' a str ,
81- /// The target architecture for the build (e.g. x86_64-unknown-linux-gnu)
82- target : & ' a str ,
83- /// Whether it is a debug build
84- is_debug : bool ,
85- /// The version of rustc used to compile MUSE
86- rustc_version : & ' a str ,
87- /// When MUSE was built
88- build_time_utc : & ' a str ,
89- /// The git commit hash for the version of MUSE (if known)
90- git_commit_hash : String ,
91- }
92-
93- /// Information about the program build via `built` crate
94- mod built_info {
95- // The file has been placed there by the build script.
96- include ! ( concat!( env!( "OUT_DIR" ) , "/built.rs" ) ) ;
97- }
98-
99- /// Get information about program version from git
100- fn get_git_hash ( ) -> String {
101- let Some ( hash) = built_info:: GIT_COMMIT_HASH_SHORT else {
102- return "unknown" . into ( ) ;
103- } ;
104-
105- if built_info:: GIT_DIRTY == Some ( true ) {
106- format ! ( "{hash}-dirty" )
107- } else {
108- hash. into ( )
109- }
110- }
111-
112- impl Default for ProgramMetadata < ' _ > {
113- fn default ( ) -> Self {
114- Self {
115- name : built_info:: PKG_NAME ,
116- version : built_info:: PKG_VERSION ,
117- target : built_info:: TARGET ,
118- is_debug : built_info:: DEBUG ,
119- rustc_version : built_info:: RUSTC_VERSION ,
120- build_time_utc : built_info:: BUILT_TIME_UTC ,
121- git_commit_hash : get_git_hash ( ) ,
122- }
123- }
124- }
125-
126- /// Write metadata to the specified output path in TOML format
127- fn write_metadata ( output_path : & Path ) -> Result < ( ) > {
128- let metadata = Metadata :: default ( ) ;
129- let file_path = output_path. join ( METADATA_FILE_NAME ) ;
130- fs:: write ( & file_path, toml:: to_string ( & metadata) ?) ?;
131-
132- Ok ( ( ) )
133- }
134-
13569/// Used to represent assets in assets output CSV file and other output files.
13670///
13771/// NB: It may be better to represent assets in these other files with IDs instead, see
0 commit comments