use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectComponent {
pub build_dir_path: PathBuf,
pub source_root_path: PathBuf,
pub compilation_database_path: PathBuf,
pub provider_type: String,
pub generator: String,
pub build_type: String,
pub build_options: HashMap<String, String>,
}
impl ProjectComponent {
pub fn new(
build_dir_path: PathBuf,
source_root_path: PathBuf,
compilation_database_path: PathBuf,
provider_type: String,
generator: String,
build_type: String,
build_options: HashMap<String, String>,
) -> Result<Self, crate::project::ProjectError> {
use crate::project::ProjectError;
if !build_dir_path.exists() || !build_dir_path.is_dir() {
return Err(ProjectError::BuildDirectoryNotReadable {
path: build_dir_path.to_string_lossy().to_string(),
});
}
if !source_root_path.exists() || !source_root_path.is_dir() {
return Err(ProjectError::SourceRootNotFound {
path: source_root_path.to_string_lossy().to_string(),
});
}
if !compilation_database_path.exists() {
return Err(ProjectError::CompilationDatabaseNotFound {
path: compilation_database_path.to_string_lossy().to_string(),
});
}
Ok(Self {
build_dir_path,
source_root_path,
compilation_database_path,
provider_type,
generator,
build_type,
build_options,
})
}
}