use crate::utils::dart_repository::dart_repo::{DartDependencyMode, DartRepository};
use anyhow::bail;
use cargo_metadata::VersionReq;
use lazy_static::lazy_static;
use std::path::Path;
lazy_static! {
pub(crate) static ref FFIGEN_REQUIREMENT: VersionReq = VersionReq::parse(">= 8.0.0").unwrap();
}
pub fn ensure_tools_available(
dart_root: &Path,
enable_deps_check: bool,
needs_ffigen: bool,
) -> anyhow::Result<()> {
let repo = DartRepository::from_path(dart_root)?;
if !repo.toolchain_available() {
bail!("Dart/Flutter toolchain not available");
}
if enable_deps_check && needs_ffigen {
repo.has_specified_and_installed("ffigen", DartDependencyMode::Dev, &FFIGEN_REQUIREMENT)?;
}
Ok(())
}