Support `min_version` field in `objdiff.json`

This commit is contained in:
Luke Street 2023-09-09 23:54:25 -04:00
parent 192a06bc0b
commit 26932b2e44
3 changed files with 12 additions and 1 deletions

1
Cargo.lock generated
View File

@ -2485,6 +2485,7 @@ dependencies = [
"rfd", "rfd",
"ron", "ron",
"self_update", "self_update",
"semver",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",

View File

@ -43,6 +43,7 @@ ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d7
rabbitizer = "1.7.4" rabbitizer = "1.7.4"
rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal'] rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal']
ron = "0.8.0" ron = "0.8.0"
semver = "1.0.17"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1.0.104" serde_json = "1.0.104"
serde_yaml = "0.9.25" serde_yaml = "0.9.25"

View File

@ -3,7 +3,7 @@ use std::{
path::{Component, Path, PathBuf}, path::{Component, Path, PathBuf},
}; };
use anyhow::{Context, Result}; use anyhow::{bail, Context, Result};
use globset::{Glob, GlobSet, GlobSetBuilder}; use globset::{Glob, GlobSet, GlobSetBuilder};
use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS}; use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
@ -11,6 +11,7 @@ use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
#[derive(Default, Clone, serde::Deserialize)] #[derive(Default, Clone, serde::Deserialize)]
#[serde(default)] #[serde(default)]
pub struct ProjectConfig { pub struct ProjectConfig {
pub min_version: Option<String>,
pub custom_make: Option<String>, pub custom_make: Option<String>,
pub target_dir: Option<PathBuf>, pub target_dir: Option<PathBuf>,
pub base_dir: Option<PathBuf>, pub base_dir: Option<PathBuf>,
@ -121,6 +122,14 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
}; };
if let Some(result) = try_project_config(project_dir) { if let Some(result) = try_project_config(project_dir) {
let project_config = result?; let project_config = result?;
if let Some(min_version) = &project_config.min_version {
let version_str = env!("CARGO_PKG_VERSION");
let version = semver::Version::parse(version_str).unwrap();
let version_req = semver::VersionReq::parse(&format!(">={min_version}"))?;
if !version_req.matches(&version) {
bail!("Project requires objdiff version {} or higher", min_version);
}
}
config.custom_make = project_config.custom_make; config.custom_make = project_config.custom_make;
config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p)); config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p));
config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p)); config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p));