From 1d4447a64a99a01e77158f3092db8767965ec346 Mon Sep 17 00:00:00 2001 From: Penguin Date: Thu, 30 Dec 2021 20:07:44 -0600 Subject: [PATCH] igloo is back to where it was before the rewrite but it is much easier to sift through and can now be expanded on... still much work to be done as far as config files and serialization go though --- igloo_core/src/igloo_env.rs | 12 +++- igloo_core/src/igloo_manifest.rs | 1 + igloo_core/src/igloo_project.rs | 4 +- igloo_core/src/igloo_target.rs | 95 ++++++++++++++++++++++++++++---- igloo_core/src/lib.rs | 6 +- igloo_util/src/lib.rs | 23 ++++---- 6 files changed, 116 insertions(+), 25 deletions(-) diff --git a/igloo_core/src/igloo_env.rs b/igloo_core/src/igloo_env.rs index 1cd2a80..f1bfe74 100644 --- a/igloo_core/src/igloo_env.rs +++ b/igloo_core/src/igloo_env.rs @@ -1,5 +1,8 @@ use crate::{PathBuf, env, UserDirs}; +use igloo_util::IglooDebugSeverity::*; +use igloo_util::IglooStatus::*; +use igloo_util::TRACE_LEVEL; // static PROJECT_CONFIG_FILE_NAME: &str = "igloo.toml"; #[derive(Debug, PartialEq, Clone)] @@ -22,7 +25,14 @@ impl IglooEnv cwd: match env::current_dir() { Ok(v) => v, - Err(e) => panic!(), + Err(e) => + { + igloo_debug!(ERROR, + IS_MISSING_ENV_VARIABLES, + "Failed to get current working directory... {}", + e); + panic!(); + } }, hd: match UserDirs::new() { diff --git a/igloo_core/src/igloo_manifest.rs b/igloo_core/src/igloo_manifest.rs index 92d047e..95a731c 100644 --- a/igloo_core/src/igloo_manifest.rs +++ b/igloo_core/src/igloo_manifest.rs @@ -27,6 +27,7 @@ impl IglooTargetManifest targets: HashMap::new(), } } + pub fn get(igloo: &Igloo) -> Result { igloo_debug!(TRACE, diff --git a/igloo_core/src/igloo_project.rs b/igloo_core/src/igloo_project.rs index 95aadf1..793ce29 100644 --- a/igloo_core/src/igloo_project.rs +++ b/igloo_core/src/igloo_project.rs @@ -91,8 +91,8 @@ impl Settings self.profile.targets.push(target_name); } - /// This function is labeled .._from_config, but the project contains - /// the environment vars (from &Igloo) and config already + // This function is labeled .._from_config, but the project contains + // the environment vars (from &Igloo) and config already pub fn get_targets_from_config(prj: &IglooProject) -> Vec { let mut _targets: Vec = Vec::new(); diff --git a/igloo_core/src/igloo_target.rs b/igloo_core/src/igloo_target.rs index 2f8d3dc..5e291e4 100644 --- a/igloo_core/src/igloo_target.rs +++ b/igloo_core/src/igloo_target.rs @@ -28,10 +28,7 @@ use std::io::prelude::*; pub struct IglooTargetConfig { name: String, - common: String, - mcu: String, - ld: String, - cfg: String, + links: Vec, includes: Vec, scripts: Vec, series: String, @@ -52,10 +49,7 @@ impl IglooTargetConfig IglooTargetConfig { name: String::new(), - common: String::new(), - mcu: String::new(), - ld: String::new(), - cfg: String::new(), + links: Vec::new(), includes: Vec::new(), scripts: Vec::new(), series: String::new(), @@ -172,13 +166,73 @@ impl IglooTarget } } + // Create symlinks for esf scripts ret = self.gather_esf_gdb_scripts(project); if ret != IS_GOOD { return ret } + // Create symlinks required by the target + // these links need to be formatted like so + // arch/...guts.../link_name + // igloo will use the guts to create the directories needed to make the symlinks + // also need to handle these unwraps + for link in &self.config.links + { + // name of the link is the final name in the path, i.e. arch/arm/"common" + let link_name = String::from(&link[link.rfind('/').unwrap() + 1..link.len()]); + let guts = String::from(&link[link.find('/').unwrap() + 1..link.rfind('/').unwrap()]); + let guts_path = project.root.join("esf").join(std::path::PathBuf::from(&guts)); + // paths for the symlink creation + let from_path = project.igloo.env.esfd.join(&link); + let to_path = guts_path.join(&link_name); + match std::fs::create_dir_all(&guts_path) + { + Ok(_v) => + { + match std::os::unix::fs::symlink(&from_path, &to_path) + { + Ok(__v) => (), + Err(e) => + { + ret = IS_FAILED_TO_CREATE_SYMLINK; + igloo_debug!(ERROR, + ret, + "Failed to create symlink from {} to {} -- {}", + &from_path.to_str().unwrap(), + &to_path.to_str().unwrap(), + e); + } + } + } + Err(e) => + { + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, + ret, + "Failed to create dir {} -- {}", + &guts_path.to_str().unwrap(), + e); + return ret; + } + } + } + + // Write out our targets config to its config file located at its root + // ex. project/igloo/targets//.toml + ret = self.generate_config(project); + if ret != IS_GOOD + { + igloo_debug!(ERROR, ret, "Failed to create target config..."); + return ret; + } + ret = self.generate_makefile(project); + if ret != IS_GOOD + { + igloo_debug!(ERROR, ret, "Failed to generate makefile..."); + } ret } @@ -482,10 +536,10 @@ impl IglooTarget write!(makefile, "{}", element).unwrap(); } } - Err(e) => + Err(_e) => { // not an array - write!(makefile, "{}", v.clone().into_str().unwrap()); + write!(makefile, "{}", v.clone().into_str().unwrap()).unwrap(); } } }, @@ -980,6 +1034,7 @@ endif\n").unwrap(); // 1.) readability and // 2.) to prevent "temporary value dropped while borrowed" ?? // I should revisit this to make sure there are no shenanigans + // Only commenting this because I don't get it. They look exactly the same. ?? // original: /* - let absolute_script_path = std::path::PathBuf::from(&_script); @@ -1061,4 +1116,24 @@ endif\n").unwrap(); ret } + // this needs to be changed to convert the esf table contents into an actual table + // named esf + // right now im just writing [esf]\n + // the drawback of this is user configurations will be overwritten every time a target + // config needs to be regenerated + pub fn generate_config(&self, project: &IglooProject) -> IglooStatus + { + let mut ret = IS_GOOD; + let cfg_path = self.root.join( + String::from( + &self.config.name) + ".toml"); + + + let esf_table_contents = toml::to_string(&self.config).unwrap(); + let mut target_cfg_file = std::fs::File::create(&cfg_path).unwrap(); + target_cfg_file.write("[esf]\n".as_bytes()).unwrap(); + target_cfg_file.write_all(esf_table_contents.as_bytes()).unwrap(); + target_cfg_file.write("\n[user]\n".as_bytes()).unwrap(); + ret + } } diff --git a/igloo_core/src/lib.rs b/igloo_core/src/lib.rs index 965dc3b..92333ad 100644 --- a/igloo_core/src/lib.rs +++ b/igloo_core/src/lib.rs @@ -94,7 +94,6 @@ impl Igloo res_err = igloo_action::ia_new(self, igloo_cli::ich_new_get_project_name(self), igloo_cli::ich_new_get_target_name(self)); - println!("Value of res_err is: {:?}", res_err); } IT_RUN => { @@ -137,6 +136,11 @@ impl Igloo } } + + if res_err != IS_GOOD + { + igloo_debug!(ERROR, res_err, "Igloo action failed..."); + } res_err } } diff --git a/igloo_util/src/lib.rs b/igloo_util/src/lib.rs index c274a02..15c207c 100644 --- a/igloo_util/src/lib.rs +++ b/igloo_util/src/lib.rs @@ -53,17 +53,18 @@ pub static TRACE_LEVEL: IglooDebugSeverity = IglooDebugSeverity::TRACE; pub enum IglooStatus { IS_GOOD = 0x00, - IS_BAD = 0x01, - IS_UNKNOWN = 0x02, - IS_FAILED_TO_LOAD_MTM = 0x03, - IS_NEW_CALLED_IN_EXISTING_PRJ = 0x04, - IS_NEW_DIR_ALREADY_EXISTS = 0x05, - IS_FAILED_TO_CREATE_PRJ_CFG_FILE = 0x06, - IS_FAILED_TO_CREATE_DIR = 0x07, - IS_FAILED_TO_EXTRACT_MF_VAR = 0x08, - IS_FAILED_TO_WRITE_MF_VAR = 0x09, - IS_FAILED_TO_CREATE_SYMLINK = 0x0A, - IS_NONE = 0xFF, + IS_BAD, + IS_UNKNOWN, + IS_MISSING_ENV_VARIABLES, + IS_FAILED_TO_LOAD_MTM, + IS_NEW_CALLED_IN_EXISTING_PRJ, + IS_NEW_DIR_ALREADY_EXISTS, + IS_FAILED_TO_CREATE_PRJ_CFG_FILE, + IS_FAILED_TO_CREATE_DIR, + IS_FAILED_TO_EXTRACT_MF_VAR, + IS_FAILED_TO_WRITE_MF_VAR, + IS_FAILED_TO_CREATE_SYMLINK, + IS_NONE, }