Expose function for reading the configuration

master
Jos van den Oever 2018-09-30 00:10:22 +02:00
parent fac04fd6d4
commit df91226979
2 changed files with 9 additions and 3 deletions

View File

@ -10,10 +10,15 @@ mod rust;
mod util; mod util;
use std::error::Error; use std::error::Error;
use std::fmt::Display;
use std::path::Path; use std::path::Path;
use configuration::Config; use configuration::Config;
pub fn read_config_file<P: AsRef<Path>>(
config_file: P,
) -> Result<Config, Box<Error>> {
configuration::parse(config_file)
}
pub fn generate_bindings(config: &Config) -> Result<(), Box<Error>> { pub fn generate_bindings(config: &Config) -> Result<(), Box<Error>> {
cpp::write_header(config)?; cpp::write_header(config)?;
cpp::write_cpp(config)?; cpp::write_cpp(config)?;
@ -22,11 +27,11 @@ pub fn generate_bindings(config: &Config) -> Result<(), Box<Error>> {
Ok(()) Ok(())
} }
pub fn generate_bindings_from_config_file<P: AsRef<Path> + Display>( pub fn generate_bindings_from_config_file<P: AsRef<Path>>(
config_file: P, config_file: P,
overwrite_implementation: bool, overwrite_implementation: bool,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<Error>> {
let mut config = configuration::parse(config_file)?; let mut config = read_config_file(config_file)?;
if overwrite_implementation { if overwrite_implementation {
config.overwrite_implementation = true; config.overwrite_implementation = true;
} }

View File

@ -8,6 +8,7 @@ pub fn write_if_different<P: AsRef<Path>>(path: P, contents: &[u8]) -> Result<()
if old_contents.map(|c| c == contents).unwrap_or(false) { if old_contents.map(|c| c == contents).unwrap_or(false) {
Ok(()) Ok(())
} else { } else {
let _ = fs::create_dir_all(path.as_ref().parent().unwrap());
fs::write(path, contents) fs::write(path, contents)
} }
} }