diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-13 16:18:24 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-15 23:16:04 +0100 |
commit | 5223f12462f67bb052a515ba8d9422e04288c03a (patch) | |
tree | 313e6384d1c89ddd454c1140ba3423d451d152d7 | |
parent | 952fa0bee9f57e8650cafd94ff7da0cd2cbd6cb1 (diff) |
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 <matthias.beyer@atos.net>
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | config.toml | 2 | ||||
-rw-r--r-- | src/config/not_validated.rs | 11 |
3 files changed, 14 insertions, 0 deletions
@@ -38,6 +38,7 @@ regex = "1" reqwest = { version = "0.10", features = [ "stream" ] } resiter = "0.4" result-inspect = "0.1" +semver = { version = "0.11", features = [ "serde" ] } serde = "1" serde_json = "1" sha1 = { version = "0.6", features = ["std"] } diff --git a/config.toml b/config.toml index 388d461..e9242ea 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,7 @@ # Example configuration file for butido +# Configuration and package definition compatibility +compatibility = "0.1.0" # Format of the progress bars used. # See https://docs.rs/indicatif/0.15.0/indicatif/#templates 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; @@ -23,6 +24,9 @@ use crate::package::PhaseName; #[derive(Debug, Getters, Deserialize)] pub struct NotValidatedConfiguration { #[getset(get = "pub")] + compatibility: semver::VersionReq, + + #[getset(get = "pub")] log_dir: PathBuf, #[serde(default = "default_strict_script_interpolation")] @@ -99,6 +103,13 @@ pub struct NotValidatedConfiguration { impl NotValidatedConfiguration { pub fn validate(self) -> Result<Configuration> { + 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())) |