diff --git a/.gdb_history b/.gdb_history new file mode 100644 index 0000000..bca70f3 --- /dev/null +++ b/.gdb_history @@ -0,0 +1 @@ +q diff --git a/src/igloo.rs b/src/igloo.rs index 9fe0c2b..1d07d34 100644 --- a/src/igloo.rs +++ b/src/igloo.rs @@ -1,4 +1,5 @@ use crate::igloo_action::IglooAction; +use crate::igloo_prj::IglooPrj; #[derive(Debug)] #[derive(PartialEq)] pub enum IglooInstType @@ -24,6 +25,9 @@ pub enum IglooErrType IGLOO_UNKNOWN_INST_TYPE = 4, IGLOO_NEW_CALLED_INSIDE_PRJ = 5, IGLOO_FOLDER_ALREADY_EXISTS = 6, + IGLOO_INVALID_PROJECT_NAME = 7, + IGLOO_ENV_INFO_INVALID = 8, + IGLOO_INVALID_TARGET = 9, } #[derive(Debug)] @@ -46,9 +50,10 @@ use IglooErrType::*; /// things happen. pub struct Igloo { - conf: config::Config, cli_conf: clap::ArgMatches, - env_info: IglooEnvInfo, + pub env_info: IglooEnvInfo, + pub make_manifest: config::Config, + pub target_manifest: config::Config, } impl Igloo @@ -63,31 +68,9 @@ impl Igloo { Igloo { - conf: config::Config::default(), - env_info: - { - IglooEnvInfo - { - cwd: std::env::current_dir().unwrap(), - hd: std::env::home_dir().unwrap(), - esfd: match std::env::var("ESF_DIR") - { - Ok(v) => - { - std::path::PathBuf::from(v.to_owned() - + "/ePenguin-Software-Framework") - } - Err(e) => - { - // Note: Need to change new to return errors - // instead of exiting early - println!("Error: $ESF_DIR not defined as an environment\ - variable -- {:?}", e); - std::process::exit(1); - } - } - } - }, + env_info: IglooEnvInfo::info(), + make_manifest: config::Config::new(), + target_manifest: config::Config::new(), cli_conf: clap::App::new("igloo") .about(clap::crate_description!()) .version(clap::crate_version!()) @@ -150,9 +133,19 @@ impl Igloo { let mut res_error = IGLOO_ERR_NONE; let mut res_type = IGLOO_NULL; - println!("Current Directory: {:?}", self.env_info.cwd.display()); - println!("ESF Directory: {:?}", self.env_info.esfd.display()); - println!("Home Directory: {:?}", self.env_info.hd.display()); + // Load manifests first + self.make_manifest.clone().merge( + config::File::with_name( + IglooEnvInfo::info().esfd.join("manifest/make-manifest.toml") + .to_str() + .unwrap())) + .unwrap(); + self.target_manifest.clone().merge( + config::File::with_name( + IglooEnvInfo::info().esfd.join("manifest/target-manifest.toml") + .to_str() + .unwrap())) + .unwrap(); match self.cli_conf.subcommand_name() { Some("new") => @@ -194,6 +187,7 @@ impl Igloo pub fn run(&self, inst_type: IglooInstType) -> Result { let mut res_err = IGLOO_ERR_NONE; + let mut prj: IglooPrj; loop { match inst_type { IGLOO_NULL => res_err = IGLOO_ERR_UNKNOWN, @@ -207,10 +201,11 @@ impl Igloo let target: &str = new_matches.unwrap() .value_of("target") .unwrap(); - IglooAction::new(&self.env_info, prj_name, target); + IglooAction::new(prj_name, target); } else { + println!("HELLOOOO"); panic!("Unknown error?"); } @@ -236,3 +231,29 @@ impl Igloo } } +impl IglooEnvInfo +{ + pub fn info() -> IglooEnvInfo + { + IglooEnvInfo + { + cwd: std::env::current_dir().unwrap(), + hd: std::env::home_dir().unwrap(), + esfd: match std::env::var("ESF_DIR") + { + Ok(v) => + { + std::path::PathBuf::from(&v.to_owned()) + } + Err(e) => + { + // Note: Need to change new to return errors + // instead of exiting early + println!("Error: $ESF_DIR not defined as an environment\ + variable -- {:?}", e); + std::process::exit(1); + } + } + } + } +} diff --git a/src/igloo_action.rs b/src/igloo_action.rs index 78a8b7c..d0957fa 100644 --- a/src/igloo_action.rs +++ b/src/igloo_action.rs @@ -8,7 +8,7 @@ pub mod IglooAction res_err } - pub fn new(env_info: &IglooEnvInfo, prj_name: &str, target: &str) + pub fn new(prj_name: &str, target: &str) -> IglooErrType { let mut res_err: IglooErrType = IglooErrType::IGLOO_ERR_NONE; @@ -28,7 +28,7 @@ pub mod IglooAction return res_err } // Create new directory - let mut active_dir = env_info.cwd.clone(); + let mut active_dir = IglooEnvInfo::info().cwd; println!("Active Directory: {:?}", active_dir.display()); active_dir.push(prj_name); match std::fs::create_dir(&active_dir) diff --git a/src/igloo_manifest.rs b/src/igloo_manifest.rs new file mode 100644 index 0000000..d0fac13 --- /dev/null +++ b/src/igloo_manifest.rs @@ -0,0 +1,51 @@ +/// Igloo Manifest -- Responsible for all lookups in manifest files +pub mod IglooManifest +{ + use crate::igloo::{Igloo, IglooErrType, IglooEnvInfo}; + pub fn target_exists(inst: &Igloo, name: &str) -> bool + { + let mut ret: bool = false; + loop + { + if name.is_empty() + { + ret = false; + break; + } + + let make_table = inst.target_manifest.get_table("target.make").unwrap(); + let manifest_table = inst.target_manifest.get_table("target.manifest").unwrap(); + + match make_table.get(name) + { + Some(v) => + { + println!("target.make entry for \"{}\" exists!", name); + ret = true; + } + None => + { + ret = false; + } + } + + if !ret + { + break; + } + + match manifest_table.get(name) + { + Some(v) => + { + println!("target.manifest entry for \"{}\" exists!", name); + } + None => + { + ret = false; + } + } + break; } + ret + } +} diff --git a/src/igloo_prj.rs b/src/igloo_prj.rs index 8c20713..af6d059 100644 --- a/src/igloo_prj.rs +++ b/src/igloo_prj.rs @@ -1,3 +1,6 @@ +use crate::igloo::{Igloo, IglooEnvInfo, IglooErrType}; +use crate::igloo_manifest::{IglooManifest}; +use std::collections::HashMap; // New Project // --- Verify location // --- Populate base folders @@ -6,16 +9,83 @@ // --- Read Default Targets manifest toml // --- generate projects core manifest toml // --- Spawn user manifest config -pub mod IglooPrj +pub struct IglooPrj { - pub struct IglooPrj + name: String, + target_bank: Vec, + env_info: IglooEnvInfo, +} + +pub struct IglooTarget +{ + name: String, + make_manifest: HashMap, + target_manifest: HashMap, +} + +impl IglooPrj +{ + pub fn default() -> IglooPrj + { + IglooPrj + { + name: String::from(""), + target_bank: Vec::default(), + env_info: IglooEnvInfo::info(), + } + } + + pub fn new(nameIn: &str, targetIn: &str, env_infoIn: &IglooEnvInfo) + -> Result + { + let mut res_err = IglooErrType::IGLOO_ERR_NONE; + loop + { + if String::from(nameIn).is_empty() + { + res_err = IglooErrType::IGLOO_INVALID_PROJECT_NAME; + break; + } + + + break; } + + if res_err != IglooErrType::IGLOO_ERR_NONE + { + return Err(res_err) + } + + Ok(IglooPrj + { + name: String::from(nameIn), + target_bank: Vec::new(), + env_info: IglooEnvInfo::info(), + }) + } +} + +impl IglooTarget +{ + pub fn default() -> IglooTarget { - target: IglooTarget, + IglooTarget + { + name: String::from(""), + make_manifest: HashMap::default(), + target_manifest: HashMap::default(), + } } - pub struct IglooTarget + pub fn from(inst: &Igloo, nameIn: &str) -> Result { + if !IglooManifest::target_exists(inst, nameIn) + { + return Err(IglooErrType::IGLOO_INVALID_TARGET) + } + + Ok(IglooTarget::default()) } } + diff --git a/src/main.rs b/src/main.rs index 9212a2e..0a9292a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,13 @@ extern crate clap; extern crate config; mod igloo; mod igloo_action; +mod igloo_prj; +mod igloo_manifest; use clap::{crate_version, crate_description, crate_authors, App, Arg, AppSettings, ArgMatches}; use config::*; use std::collections::HashMap; use std::path::{Path, PathBuf}; -use std::os::unix::fs;