From ff5a3535db69cfe4e14bf251171ed0924441201e Mon Sep 17 00:00:00 2001 From: Penguin Date: Fri, 24 Dec 2021 18:36:02 -0600 Subject: [PATCH] actual last commit til after christmas. rust + macros + workspaces = disaster... Moved igloo util into its own workspace member (subcrate?) rust building and dependencies are kinda a disaster. --- .gdb_history | 33 ++++++++ Cargo.lock | 6 ++ Cargo.toml | 3 +- igloo_core/Cargo.toml | 3 +- igloo_core/src/.#igloo_action.rs | 1 - igloo_core/src/igloo_action.rs | 32 ++++---- igloo_core/src/igloo_cli.rs | 9 +-- igloo_core/src/igloo_env.rs | 2 +- igloo_core/src/igloo_manifest.rs | 12 +-- igloo_core/src/igloo_project.rs | 134 ++++++++++++++++++------------- igloo_core/src/igloo_target.rs | 63 ++++++++++----- igloo_core/src/igloo_util.rs | 41 ---------- igloo_core/src/lib.rs | 78 ++++-------------- igloo_util/Cargo.toml | 8 ++ igloo_util/src/lib.rs | 101 +++++++++++++++++++++++ projecttest/igloo/igloo.toml | 0 src/main.rs | 14 +++- 17 files changed, 327 insertions(+), 213 deletions(-) delete mode 120000 igloo_core/src/.#igloo_action.rs delete mode 100644 igloo_core/src/igloo_util.rs create mode 100644 igloo_util/Cargo.toml create mode 100644 igloo_util/src/lib.rs create mode 100644 projecttest/igloo/igloo.toml diff --git a/.gdb_history b/.gdb_history index 0ddbe36..17cfdbd 100644 --- a/.gdb_history +++ b/.gdb_history @@ -36,3 +36,36 @@ set listsize 30 s q q +b igloo::main +r +n +q +b igloo::main +r +n +n +s +s +s +n +s +s +n +n +s +n +n +s +s +n +s +b +n +n +n +n +n +n +n +n +q diff --git a/Cargo.lock b/Cargo.lock index 1e7d9a6..bdbaf4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,7 @@ version = "0.1.0" dependencies = [ "igloo_agent", "igloo_core", + "igloo_util", ] [[package]] @@ -170,10 +171,15 @@ dependencies = [ "clap", "config", "directories", + "igloo_util", "serde 1.0.132", "toml", ] +[[package]] +name = "igloo_util" +version = "0.1.0" + [[package]] name = "indexmap" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index c9acc03..53e275a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ license="GPL-2.0" [dependencies] igloo_core = { path = "./igloo_core" } igloo_agent = { path = "./igloo_agent" } +igloo_util = { path = "./igloo_util" } [workspace] -members = ["igloo_core", "igloo_agent"] +members = ["igloo_core", "igloo_agent", "igloo_util"] diff --git a/igloo_core/Cargo.toml b/igloo_core/Cargo.toml index 803b153..c78fa95 100644 --- a/igloo_core/Cargo.toml +++ b/igloo_core/Cargo.toml @@ -10,4 +10,5 @@ clap = "3.0.0-beta.2" config = "0.11" directories = "3.0.1" toml = "0.5.8" -serde = { version = "1.0.132", features = ["derive"]} \ No newline at end of file +serde = { version = "1.0.132", features = ["derive"]} +igloo_util = { path="../igloo_util" } \ No newline at end of file diff --git a/igloo_core/src/.#igloo_action.rs b/igloo_core/src/.#igloo_action.rs deleted file mode 120000 index 10026a8..0000000 --- a/igloo_core/src/.#igloo_action.rs +++ /dev/null @@ -1 +0,0 @@ -penguin@gpenguin.2954:1640039390 \ No newline at end of file diff --git a/igloo_core/src/igloo_action.rs b/igloo_core/src/igloo_action.rs index e285d8b..2ab5c77 100644 --- a/igloo_core/src/igloo_action.rs +++ b/igloo_core/src/igloo_action.rs @@ -1,11 +1,13 @@ use clap::ArgMatches; -use crate::IglooType::{self, *}; -use crate::IglooStatus::{self, *}; -use crate::IglooDebugSeverity::{self, *}; +use igloo_util::IglooDebugSeverity::*; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::IglooType::{self, *}; +use igloo_util::TRACE_LEVEL; use crate::Igloo; use crate::igloo_project::IglooProject; -use crate::igloo_util::*; +use crate::igloo_project::Settings; + pub fn igloo_subcommand(args: &ArgMatches) -> Result { @@ -92,22 +94,21 @@ pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> Ig return ret } + igloo_debug!(TRACE, IS_NONE, "Creating new igloo project..."); let mut prj = match IglooProject::from_new(igloo, project_name) { Ok(v) => v, Err(e) => { - igloo_debug!(ERROR, e); - return e + ret = e; + igloo_debug!(ERROR, ret); + return ret } }; - ret = prj.add_target_to_config(initial_target); - if ret != IS_GOOD - { - igloo_debug!(ERROR, ret); - return ret - } + // add initial target to config + prj.config.add_target(initial_target); + prj.targets = Settings::get_targets_from_config(&prj); // Now populate ret = prj.generate(); @@ -130,8 +131,11 @@ pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> Ig igloo_debug!(ERROR, ret); } - - + ret = prj.generate_project_config(); + if ret != IS_GOOD + { + igloo_debug!(ERROR, ret); + } ret } diff --git a/igloo_core/src/igloo_cli.rs b/igloo_core/src/igloo_cli.rs index 84317df..2b6d17a 100644 --- a/igloo_core/src/igloo_cli.rs +++ b/igloo_core/src/igloo_cli.rs @@ -1,10 +1,9 @@ -use clap::{App, Arg, ArgMatches}; +use clap::{App, Arg}; use crate::Igloo; -use crate::IglooType; -use crate::IglooType::*; -use crate::IglooStatus; -use crate::IglooStatus::*; +// use igloo_util::IglooDebugSeverity::*; +// use igloo_util::IglooStatus::{self, *}; +// use igloo_util::TRACE_LEVEL; /// Information input via cli will be stored here for the lifetime of the process pub struct IglooCliInfo diff --git a/igloo_core/src/igloo_env.rs b/igloo_core/src/igloo_env.rs index 1700a71..1cd2a80 100644 --- a/igloo_core/src/igloo_env.rs +++ b/igloo_core/src/igloo_env.rs @@ -1,6 +1,6 @@ use crate::{PathBuf, env, UserDirs}; -static PROJECT_CONFIG_FILE_NAME: &str = "igloo.toml"; +// static PROJECT_CONFIG_FILE_NAME: &str = "igloo.toml"; #[derive(Debug, PartialEq, Clone)] pub struct IglooEnv diff --git a/igloo_core/src/igloo_manifest.rs b/igloo_core/src/igloo_manifest.rs index 03df546..92d047e 100644 --- a/igloo_core/src/igloo_manifest.rs +++ b/igloo_core/src/igloo_manifest.rs @@ -1,17 +1,13 @@ // igloo_manifest is a simple collection of functions that work with configs use std::collections::HashMap; -use std::vec::Vec; use crate::Igloo; -use crate::IglooStatus::{self, *}; -use crate::IglooType::{self, *}; -use crate::IglooDebugSeverity::{self, *}; - -use crate::igloo_target::IglooTarget; -use crate::igloo_util::*; use serde::{Serialize, Deserialize}; -use config::Config; + +use igloo_util::IglooDebugSeverity::*; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::TRACE_LEVEL; /// IglooTargetManifest - a manifest file locations which contain each target's /// settings and configuration properties diff --git a/igloo_core/src/igloo_project.rs b/igloo_core/src/igloo_project.rs index bda60f1..0f373f2 100644 --- a/igloo_core/src/igloo_project.rs +++ b/igloo_core/src/igloo_project.rs @@ -1,21 +1,17 @@ use crate::Igloo; -use crate::igloo_cli::*; -use crate::IglooType::{self, *}; -use crate::IglooStatus::{self, *}; -use crate::IglooDebugSeverity::{self, *}; - -use crate::igloo_util::*; -use crate::igloo_project; use crate::igloo_target::IglooTarget; use serde::{Serialize, Deserialize}; -use config::Config; +use std::fs::{OpenOptions}; +use igloo_util::IglooDebugSeverity::*; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::TRACE_LEVEL; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Settings { - pub testvar: String, + pub testvar: Option, pub profile: Profile, } @@ -46,16 +42,16 @@ impl Settings { Settings { - testvar: String::new(), + testvar: Option::default(), profile: Profile::default(), } } - pub fn from_project_file(self, igloo: &Igloo) -> Result + pub fn from_project_file(prj: &IglooProject) -> Result { let mut config = config::Config::default(); config.merge( config::File::with_name( - igloo.env + prj.igloo.env .cwd .clone() .join("test") @@ -67,8 +63,23 @@ impl Settings } - pub fn to_project_file(self, igloo: &Igloo) -> IglooStatus + pub fn to_project_file(prj: &IglooProject) -> IglooStatus { + let prj_cfg_path = prj + .root + .clone() + .join("igloo") + .join("igloo.toml"); + std::fs::File::create(&prj_cfg_path).unwrap(); + let mut prj_cfg_file = OpenOptions::new() + .write(true) + .append(true) + .open(&prj_cfg_path) + .unwrap(); + + let contents = toml::to_string(&prj.config).unwrap(); + igloo_debug!(TRACE, IS_NONE, "{}", contents); + println!("PRINTING THIS ON ITS OWN: {}", contents); IglooStatus::IS_GOOD } @@ -81,12 +92,14 @@ impl Settings self.profile.targets.push(target_name); } - pub fn get_targets_from_config(igloo: &Igloo, config: &Settings) -> Vec + /// 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(); - for target in config.profile.targets.iter() + for target in prj.config.profile.targets.iter() { - _targets.push(IglooTarget::target_from_name(igloo, String::from(target)).unwrap()); + _targets.push(IglooTarget::target_from_name(prj.igloo, String::from(target)).unwrap()); } _targets } @@ -96,7 +109,7 @@ pub struct IglooProject<'a> { pub igloo: &'a Igloo, pub config: Settings, - targets: Vec::, + pub targets: Vec::, pub root: std::path::PathBuf, } @@ -133,17 +146,15 @@ impl<'a> IglooProject<'a> /// igloo run, push, pull, erase, etc... are called pub fn from_existing(igloo_in: &'a Igloo) -> Result { - let _config = Settings::default().from_project_file(igloo_in).unwrap(); - let _targets = Settings::get_targets_from_config(igloo_in, &_config); - let _root = igloo_in.env.cwd.join(&_config.profile.name); - let ret_project = IglooProject - { - igloo: igloo_in, - config: _config, - targets: _targets, - root: _root, - }; - Ok(IglooProject::default(igloo_in)) + // These vars need to be acquired in this order when creating a project from an existing project + // The config requires the &Igloo + // targets requires config and &Igloo + // root just requires the project name, but its best to do it last to make sure everything else is valid + let mut ret_project = IglooProject::default(igloo_in); + ret_project.config = Settings::from_project_file(&ret_project).unwrap(); + ret_project.targets = Settings::get_targets_from_config(&ret_project); + ret_project.root = igloo_in.env.cwd.join(&ret_project.config.profile.name); + Ok(ret_project) } pub fn is_igloo_prj(path: &std::path::PathBuf) -> bool @@ -170,25 +181,37 @@ impl<'a> IglooProject<'a> // so i can make changes to active dir and still have my project root if i need it // so far i havent needed it so i may just remove this - let active_dir = std::path::PathBuf::new().join(&self.config.profile.name); + let active_dir = self.root.clone(); // create new project directory match std::fs::create_dir(&active_dir) { Err(e) => { - println!("{:?}", e); - return IS_BAD + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir, e); + return ret } _ => (), } // create igloo directory + match std::fs::create_dir(&active_dir.clone().join("igloo")) + { + Err(e) => + { + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir.clone().join("igloo"), e); + return ret + } + _ => (), + } match std::fs::create_dir(&active_dir.clone().join("inc")) { Err(e) => { - println!("{:?}", e); - return IS_BAD + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir.clone().join("inc"), e); + return ret } _ => (), } @@ -198,8 +221,9 @@ impl<'a> IglooProject<'a> { Err(e) => { - println!("{:?}", e); - return IS_BAD + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir.clone().join("src"), e); + return ret } _ => (), } @@ -208,8 +232,9 @@ impl<'a> IglooProject<'a> { Err(e) => { - println!("{:?}", e); - return IS_BAD + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir.clone().join("cfg"), e); + return ret } _ => (), } @@ -218,42 +243,34 @@ impl<'a> IglooProject<'a> { Err(e) => { - println!("{:?}", e); - return IS_BAD + ret = IS_FAILED_TO_CREATE_DIR; + igloo_debug!(ERROR, ret, "Failed to create dir: {:?} | {:?}", &active_dir.clone().join("esf"), e); + return ret } _ => (), } // project folders finished - // now do target folders - ret = self.generate_targets(); + // create project settings file (igloo.toml) + ret = self.generate_project_config(); if ret != IS_GOOD { + igloo_debug!(WARNING, ret); return ret } - ret = self.generate_igloo_header(); + // now do target folders + ret = self.generate_targets(); if ret != IS_GOOD { + igloo_debug!(WARNING, ret); return ret } - ret = self.generate_igloo_main(); - if ret != IS_GOOD - { - return ret - } return ret } - pub fn add_target_to_config(&mut self, target: String) -> IglooStatus - { - let mut ret = IS_GOOD; - self.config.add_target(target); - ret - } - fn generate_targets(&self) -> IglooStatus { for target in &self.targets @@ -265,11 +282,18 @@ impl<'a> IglooProject<'a> pub fn generate_igloo_header(&self) -> IglooStatus { - IS_BAD + IS_GOOD } pub fn generate_igloo_main(&self) -> IglooStatus { IS_GOOD } + + pub fn generate_project_config(&self) -> IglooStatus + { + let mut ret = IS_GOOD; + Settings::to_project_file(self); + ret + } } diff --git a/igloo_core/src/igloo_target.rs b/igloo_core/src/igloo_target.rs index 0858172..db512a4 100644 --- a/igloo_core/src/igloo_target.rs +++ b/igloo_core/src/igloo_target.rs @@ -13,17 +13,14 @@ // I could make the deserialization work by default by adding a billion different // structs, but this is honestly just a trash way of doing it and I think the idea // of doing it that way is only an ideal solution. It isn't very practical. +use igloo_util::*; use crate::Igloo; -use crate::IglooStatus; -use crate::IglooStatus::*; use crate::IglooProject; use serde::{Serialize, Deserialize}; -use config::Config; -use std::fs::{OpenOptions, File}; use std::vec::Vec; -use std::io::prelude::*; -use std::path::PathBuf; -use std::collections::HashMap; +use igloo_util::IglooDebugSeverity::*; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::TRACE_LEVEL; #[derive(Serialize, Deserialize, Debug)] pub struct IglooTarget @@ -40,7 +37,7 @@ pub struct IglooTarget impl IglooTarget { - fn default() -> IglooTarget + fn _default() -> IglooTarget { IglooTarget { @@ -59,20 +56,46 @@ impl IglooTarget /// deserializes the targets manifest file and creates the target pub fn target_from_name(igloo: &Igloo, name: String) -> Result { - let target_path = &igloo.master_target_manifest.targets[&name]; - let mut target_config = config::Config::default(); + let target_path = igloo + .env + .esfd + .clone() + .join(&igloo.master_target_manifest.targets[&name]); + + // We have to read in the file first so we can replace all variables with values + let targ_templ = match std::fs::read_to_string(&target_path) + { + Ok(v) => v, + Err(e) => + { + igloo_debug!(ERROR, + IS_BAD, + "Failed to read {} | Error: {:?}", + &target_path.to_str().unwrap(), + e); + return Err(IS_BAD) + } + }; + + // replace all variables + // this will be expanded on later and more variables will be added + let final_targ_str = targ_templ.replace("${TARGET}", &name); + + // create config from our string + let mut target_config: config::Config = config::Config::default(); target_config.merge( - config::File::with_name( - igloo.env - .esfd - .clone() - .join(&target_path) - .to_str().unwrap() - )).unwrap(); - - let mut target_table: config::Value = target_config.get("esf").unwrap(); + config::File::from_str( + &final_targ_str, config::FileFormat::Toml)).unwrap(); + + // get [esf] (which is technically a table...) from our config + let target_table: config::Value = target_config.get("esf").unwrap(); + + // turn it into an IglooTarget let ret_target = target_table.try_into::().unwrap(); - println!("{:?}", ret_target); + igloo_debug!(INFO, + IS_NONE, + "Found Igloo target and deserialized it: {:?}", + ret_target); Ok(ret_target) diff --git a/igloo_core/src/igloo_util.rs b/igloo_core/src/igloo_util.rs deleted file mode 100644 index fab3bf3..0000000 --- a/igloo_core/src/igloo_util.rs +++ /dev/null @@ -1,41 +0,0 @@ -use crate::IglooStatus::{self, *}; -use crate::IglooType::{self, *}; -use crate::IglooDebugSeverity::{self, *}; -pub static TRACE_LEVEL: IglooDebugSeverity = TRACE; - -macro_rules! igloo_debug -{ - ($severity:expr, $status:expr) => - { - if cfg!(debug_assertions) - { - if $severity as u8 <= TRACE_LEVEL.clone() as u8 - { - println!("[{:?}]: Line {:?} in {:?} | {:?}", - $severity, - line!(), - file!(), - $status); - } - } - }; - - ($severity:expr, $status:expr, $($message:tt)*) => - { - if cfg!(debug_assertions) - { - if $severity as u8 <= TRACE_LEVEL.clone() as u8 - { - println!("[{:?}]: Line {:?} in {} | {} -- STATUS: {:?}", - $severity, - line!(), - file!(), - format_args!($($message)*), - $status - ); - } - } - }; -} - -pub(crate) use igloo_debug; diff --git a/igloo_core/src/lib.rs b/igloo_core/src/lib.rs index 0c4900d..aa4f293 100644 --- a/igloo_core/src/lib.rs +++ b/igloo_core/src/lib.rs @@ -1,8 +1,10 @@ -#![allow(warnings)] -extern crate clap; -extern crate config; -extern crate toml; -extern crate serde; +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +pub extern crate clap; +pub extern crate config; +pub extern crate toml; +pub extern crate serde; use config::Config; use std::path::PathBuf; @@ -15,69 +17,18 @@ pub mod igloo_project; pub mod igloo_manifest; pub mod igloo_cli; pub mod igloo_env; -pub mod igloo_util; use igloo_cli::IglooCliInfo; use igloo_env::IglooEnv; use igloo_project::IglooProject; use igloo_manifest::IglooTargetManifest; -use igloo_util::*; - - - -#[derive(Debug)] -#[derive(PartialEq)] -/// * IT_NEW: Create a new igloo project -/// * IT_RUN: build the project if needed, then run the project, defaults to default target set in your project's profile -/// * IT_PUSH: build the project if needed, then upload your binary to your target -/// * IT_PULL: extracts binary from mcu (if possible) and saves it -/// * IT_HELP: gets help -/// * IT_BUILD: builds the project for all targets unless otherwise specified -/// * IT_ERASE: erases the flash for the specified target -/// * IT_INFO: Gets information about igloo and your project. -/// * IT_NULL: Default type... used for debugging and development. More on this later -/// * IT_DEBUG: this state is useful for debugging project failures. Only to be used in debug build of igloo. More on this later -pub enum IglooType -{ - IT_NEW = 0, - IT_RUN, - IT_PUSH, - IT_PULL, - IT_HELP, - IT_BUILD, - IT_ERASE, - IT_INFO, - IT_TARGET, - IT_NULL, - IT_DEBUG, -} - -#[derive(Debug, PartialEq, Clone)] -pub enum IglooDebugSeverity -{ - ERROR = 0, - WARNING = 1, - LOG = 2, - TRACE = 3, - INFO = 4, -} -#[derive(Debug)] -#[derive(PartialEq)] -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_NONE = 0xFF, -} +#[macro_use] extern crate igloo_util; +use igloo_util::IglooDebugSeverity::{self, *}; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::IglooType::{self, *}; +use igloo_util::TRACE_LEVEL; -use IglooStatus::*; -use IglooType::*; -use IglooDebugSeverity::*; pub struct Igloo { @@ -142,9 +93,10 @@ impl Igloo { IT_NEW => { - return igloo_action::ia_new(self, + res_err = igloo_action::ia_new(self, igloo_cli::ich_new_get_project_name(self), - igloo_cli::ich_new_get_target_name(self)) + igloo_cli::ich_new_get_target_name(self)); + println!("Value of res_err is: {:?}", res_err); } IT_RUN => { diff --git a/igloo_util/Cargo.toml b/igloo_util/Cargo.toml new file mode 100644 index 0000000..ac90493 --- /dev/null +++ b/igloo_util/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "igloo_util" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/igloo_util/src/lib.rs b/igloo_util/src/lib.rs new file mode 100644 index 0000000..ad0f220 --- /dev/null +++ b/igloo_util/src/lib.rs @@ -0,0 +1,101 @@ +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} + +#[derive(Debug)] +#[derive(PartialEq)] +/// * IT_NEW: Create a new igloo project +/// * IT_RUN: build the project if needed, then run the project, defaults to default target set in your project's profile +/// * IT_PUSH: build the project if needed, then upload your binary to your target +/// * IT_PULL: extracts binary from mcu (if possible) and saves it +/// * IT_HELP: gets help +/// * IT_BUILD: builds the project for all targets unless otherwise specified +/// * IT_ERASE: erases the flash for the specified target +/// * IT_INFO: Gets information about igloo and your project. +/// * IT_NULL: Default type... used for debugging and development. More on this later +/// * IT_DEBUG: this state is useful for debugging project failures. Only to be used in debug build of igloo. More on this later +pub enum IglooType +{ + IT_NEW = 0, + IT_RUN, + IT_PUSH, + IT_PULL, + IT_HELP, + IT_BUILD, + IT_ERASE, + IT_INFO, + IT_TARGET, + IT_NULL, + IT_DEBUG, +} + +#[derive(Debug, PartialEq, Clone)] +pub enum IglooDebugSeverity +{ + ERROR = 0, + WARNING = 1, + LOG = 2, + TRACE = 3, + INFO = 4, +} + +#[derive(Debug)] +#[derive(PartialEq)] +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_NONE = 0xFF, +} + +pub static TRACE_LEVEL: IglooDebugSeverity = IglooDebugSeverity::TRACE; + +#[macro_export] +macro_rules! igloo_debug +{ + ($severity:expr, $status:expr) => + { + if cfg!(debug_assertions) + { + if $severity as u8 <= TRACE_LEVEL.clone() as u8 + { + println!("[{:?}]: Line {:?} in {:?} | {:?}", + $severity, + line!(), + file!(), + $status); + } + } + }; + + ($severity:expr, $status:expr, $($message:tt)*) => + { + if cfg!(debug_assertions) + { + if $severity as u8 <= TRACE_LEVEL.clone() as u8 + { + println!("[{:?}]: Line {:?} in {} | {} -- STATUS: {:?}", + $severity, + line!(), + file!(), + format_args!($($message)*), + $status + ); + } + } + }; +} diff --git a/projecttest/igloo/igloo.toml b/projecttest/igloo/igloo.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index a22cb0a..eefcb28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,14 @@ -#![allow(warnings)] +// #![allow(warnings)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] use igloo_core::Igloo; +#[macro_use] extern crate igloo_util; +use igloo_util::IglooDebugSeverity::{self, *}; +use igloo_util::IglooStatus::{self, *}; +use igloo_util::IglooType::{self, *}; +use igloo_util::TRACE_LEVEL; fn main() { let mut ig = Igloo::new(); @@ -11,8 +18,9 @@ fn main() { match ig.run(it) { - IS_GOOD => println!("success"), - _ => println!("??"), + IS_GOOD => (), + // this is actually so dumb and should not exist in any language + ANYTHING_ELSE => igloo_debug!(ERROR, ANYTHING_ELSE), } } Err(e) => println!("Error: {:?}", e),