From 5223f12462f67bb052a515ba8d9422e04288c03a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 13 Jan 2021 16:18:24 +0100 Subject: Add compatiblity setting in configuration file This patch adds a compatibility setting in the configuration file, so that butido does not fail late when parsing configuration parameters or package definition files, but early, when the configured compatilibty does not match the version of butido itself. Signed-off-by: Matthias Beyer --- src/config/not_validated.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/config') diff --git a/src/config/not_validated.rs b/src/config/not_validated.rs index 87dbc78..eab7cbc 100644 --- a/src/config/not_validated.rs +++ b/src/config/not_validated.rs @@ -10,6 +10,7 @@ use std::path::PathBuf; use anyhow::anyhow; +use anyhow::Context; use anyhow::Result; use getset::Getters; use serde::Deserialize; @@ -22,6 +23,9 @@ use crate::package::PhaseName; #[derive(Debug, Getters, Deserialize)] pub struct NotValidatedConfiguration { + #[getset(get = "pub")] + compatibility: semver::VersionReq, + #[getset(get = "pub")] log_dir: PathBuf, @@ -99,6 +103,13 @@ pub struct NotValidatedConfiguration { impl NotValidatedConfiguration { pub fn validate(self) -> Result { + let crate_version = semver::Version::parse(env!("CARGO_PKG_VERSION")) + .context("Parsing version of crate (CARGO_PKG_VERSION) into semver::Version object")?; + + if !self.compatibility.matches(&crate_version) { + return Err(anyhow!("Configuration is not compatible to butido {}", crate_version)) + } + if let Some(linter) = self.script_linter.as_ref() { if !linter.is_file() { return Err(anyhow!("Lint script is not a file: {}", linter.display())) -- cgit v1.2.3