use crate::config::DependencySpec;
use crate::error::{BuildError, Result};
use std::path::{Path, PathBuf};
pub enum SourceLocation {
Path(PathBuf),
Git { url: String, tag: String },
}
pub fn resolve(name: &str, spec: &DependencySpec, project_root: &Path) -> Result<SourceLocation> {
match (&spec.git, &spec.path) {
(None, None) => Err(BuildError::Dependency {
name: name.to_string(),
reason: "no source specified: specify git or path in smidr.toml".to_string(),
}),
(Some(_), Some(_)) => Err(BuildError::Dependency {
name: name.to_string(),
reason: "both git and path specified - ambiguous".to_string(),
}),
(None, Some(local_path)) => {
let full = project_root.join(local_path);
if !full.exists() {
return Err(BuildError::Dependency {
name: name.to_string(),
reason: format!("path not found: {}", full.display()),
});
}
Ok(SourceLocation::Path(full))
}
(Some(_git_url), None) => Err(BuildError::Dependency {
name: name.to_string(),
reason: "git repositories are not supported yet".to_string(),
}),
}
}