From 599bcd93f4f54eb9c9cfe30b9357e41562753aa5 Mon Sep 17 00:00:00 2001 From: Penguin Date: Thu, 23 Dec 2021 13:29:55 -0600 Subject: [PATCH] finishing project generation --- igloo_core/src/.#igloo_action.rs | 1 - igloo_core/src/.#igloo_project.rs | 1 - igloo_core/src/igloo_action.rs | 21 ++++- igloo_core/src/igloo_project.rs | 144 ++++++++++++++++++++++++++---- igloo_core/src/igloo_target.rs | 61 +++++++++++++ igloo_core/src/lib.rs | 15 ++++ 6 files changed, 224 insertions(+), 19 deletions(-) delete mode 120000 igloo_core/src/.#igloo_action.rs delete mode 120000 igloo_core/src/.#igloo_project.rs 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_project.rs b/igloo_core/src/.#igloo_project.rs deleted file mode 120000 index 10026a8..0000000 --- a/igloo_core/src/.#igloo_project.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 bc14eb2..a24d30a 100644 --- a/igloo_core/src/igloo_action.rs +++ b/igloo_core/src/igloo_action.rs @@ -53,6 +53,11 @@ pub fn igloo_subcommand(args: &ArgMatches) -> Result println!("Igloo target was called"); _res_type = IT_TARGET; } + Some("debug") => + { + println!("Igloo debug was called"); + _res_type = IT_DEBUG; + } None => unreachable!(), _ => unreachable!(), } @@ -65,6 +70,8 @@ pub fn igloo_subcommand(args: &ArgMatches) -> Result Ok(_res_type) } +// this will eventually be implemented so that projects can be created without an initial target +// for now it's necessary pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> IglooStatus { let mut ret: IglooStatus = IS_GOOD; @@ -85,7 +92,7 @@ pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> Ig return ret } - let prj = match IglooProject::from_new(igloo, project_name) + let mut prj = match IglooProject::from_new(igloo, project_name) { Ok(v) => v, Err(e) => @@ -95,10 +102,20 @@ pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> Ig } }; + prj.add_new_target(initial_target); + // Now populate - // created_project.populate() + prj.generate(); + + ret +} + +/// Debugging function to make sure projects are being loaded correctly +pub fn ia_debug(igloo: &Igloo) -> IglooStatus +{ + let mut ret = IS_GOOD; ret } diff --git a/igloo_core/src/igloo_project.rs b/igloo_core/src/igloo_project.rs index beacb83..38e77cd 100644 --- a/igloo_core/src/igloo_project.rs +++ b/igloo_core/src/igloo_project.rs @@ -21,7 +21,7 @@ pub struct Settings /// Basic profile settings #[derive(Serialize, Deserialize, Debug)] -struct Profile +pub struct Profile { name: String, targets: Vec:: @@ -72,14 +72,23 @@ impl Settings IglooStatus::IS_GOOD } - pub fn set_profile_name(&mut self, name: String) + pub fn add_target(&mut self, target_name: String) { - self.profile.name = name; + if self.profile.targets.contains(&target_name) + { + return + } + self.profile.targets.push(target_name); } - pub fn add_target(&mut self, target_name: String) + pub fn get_targets(project: IglooProject) -> Vec { - self.profile.targets.push(target_name); + let _targets: Vec = Vec::new(); + for target in project.config.profile.targets.iter() + { + _targets.push(IglooTarget::from(project.igloo, *target).unwrap()); + } + _targets } } @@ -87,6 +96,7 @@ pub struct IglooProject<'a> { igloo: &'a Igloo, config: Settings, + targets: Vec::, } impl<'a> IglooProject<'a> @@ -97,7 +107,7 @@ impl<'a> IglooProject<'a> { igloo: igloo_in, config: Settings::default(), - + targets: Vec::new(), } } /// Used to populate an IglooProject from scratch @@ -105,11 +115,12 @@ impl<'a> IglooProject<'a> pub fn from_new(igloo_in: &'a Igloo, project_name: String) -> Result { let mut settings = Settings::default(); - settings.set_profile_name(project_name); + settings.profile.name = project_name; Ok(IglooProject { igloo: igloo_in, config: settings, + targets: Vec::new(), }) } @@ -118,11 +129,15 @@ impl<'a> IglooProject<'a> /// igloo run, push, pull, erase, etc... are called pub fn from_existing(igloo_in: &'a Igloo) -> Result { - Ok(IglooProject - { - igloo: igloo_in, - config: Settings::default().from_project_file(igloo_in).unwrap(), - }) + let mut ret_project: IglooProject = IglooProject + { + igloo: igloo_in, + config: Settings::default().from_project_file(igloo_in).unwrap(), + targets: Vec::new(), + }; + + ret_project.targets = crate::igloo_project::Settings::get_targets(ret_project); + Ok(ret_project) } pub fn is_igloo_prj(path: &std::path::PathBuf) -> bool @@ -141,15 +156,114 @@ impl<'a> IglooProject<'a> /// creates project files /// including igloo.toml - pub fn generate(self) -> IglooStatus + pub fn generate(&self) -> IglooStatus { - IglooStatus::IS_GOOD + let mut ret: IglooStatus = IS_GOOD; + + // making this root and then cloning to work with active directory + // 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); + // create new project directory + match std::fs::create_dir(&active_dir) + { + Err(e) => + { + println!("{:?}", e); + return IS_BAD + } + _ => (), + } + + // create igloo directory + match std::fs::create_dir(&active_dir.clone().join("inc")) + { + Err(e) => + { + println!("{:?}", e); + return IS_BAD + } + _ => (), + } + + // create src directory + match std::fs::create_dir(&active_dir.clone().join("src")) + { + Err(e) => + { + println!("{:?}", e); + return IS_BAD + } + _ => (), + } + + match std::fs::create_dir(&active_dir.clone().join("cfg")) + { + Err(e) => + { + println!("{:?}", e); + return IS_BAD + } + _ => (), + } + + match std::fs::create_dir(&active_dir.clone().join("esf")) + { + Err(e) => + { + println!("{:?}", e); + return IS_BAD + } + _ => (), + } + + // project folders finished + // now do target folders + ret = self.generate_targets(); + if ret != IS_GOOD + { + return ret + } + + ret = self.generate_igloo_header(); + if ret != IS_GOOD + { + return ret + } + + ret = self.generate_igloo_main(); + if ret != IS_GOOD + { + return ret + } + + return ret } - pub fn add_target(&mut self, target: String) -> IglooStatus + 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 + { + target.generate(self); + } + IS_GOOD + } + + fn generate_igloo_header(&self) -> IglooStatus + { + IS_GOOD + } + + fn generate_igloo_main(&self) -> IglooStatus + { + IS_GOOD + } } diff --git a/igloo_core/src/igloo_target.rs b/igloo_core/src/igloo_target.rs index 5147cf2..0b91ad9 100644 --- a/igloo_core/src/igloo_target.rs +++ b/igloo_core/src/igloo_target.rs @@ -1,3 +1,16 @@ +// Note to self: It makes way more sense for the target bank in our project +// to be a hashmap of type so that every time I want to +// BUT rust deserialization seems to favor these structs which includes the name +// which means I'm storing the name in the target and not outside of it. +// so for now I'm going to do it this way until I do the serialization myself (switch to syncing instead of rwwr), +// which is what I did in 0.1, before the core rewrite +// I'm only doing it this way because serialization seems to be easier this way +// After I get all core features (new, push, pull, erase, etc...) completed, +// I'll revisit this part of the project and change it to a more sensible management method +use crate::Igloo; +use crate::IglooStatus; +use crate::IglooStatus::*; +use crate::IglooProject; struct IglooTargetLinks { common: String, @@ -16,5 +29,53 @@ pub struct IglooTarget impl IglooTarget { + fn default() -> IglooTarget + { + IglooTarget + { + name: String::new(), + links: IglooTargetLinks::default(), + includes: Vec::new(), + scripts: Vec::new(), + } + } + /// takes the targets name and looks up the path + /// deserializes the targets manifest file and creates the target + pub fn from(igloo: &Igloo, name: String) -> Result + { + + Ok(IglooTarget::default()) + } + + /// Creates the target's configuration file from itself + /// the target must be valid at this point or else the file will be junk + pub fn generate(&self, project: &IglooProject) -> IglooStatus + { + let mut ret = IS_GOOD; + + ret + } + + pub fn generate_makefile(&self, project: &IglooProject) -> IglooStatus + { + let mut ret = IS_GOOD; + let prj_root = + + ret + } +} + +impl IglooTargetLinks +{ + pub fn default() -> IglooTargetLinks + { + IglooTargetLinks + { + common: String::new(), + mcu: String::new(), + ld: String::new(), + cfg: String::new(), + } + } } diff --git a/igloo_core/src/lib.rs b/igloo_core/src/lib.rs index 2e8c97a..3eb816c 100644 --- a/igloo_core/src/lib.rs +++ b/igloo_core/src/lib.rs @@ -35,6 +35,7 @@ pub enum IglooType IT_INFO, IT_TARGET, IT_NULL, + IT_DEBUG, } #[derive(Debug)] @@ -63,6 +64,7 @@ use IglooType::*; pub struct Igloo { master_target_manifest: IglooTargetManifest, + master_make_manifest: Config, cli_info: IglooCliInfo, env: IglooEnv, } @@ -76,6 +78,7 @@ impl Igloo cli_info: IglooCliInfo::new(), env: IglooEnv::get_env(), master_target_manifest: IglooTargetManifest::default(), + master_make_manifest: Config::new(), } } @@ -85,6 +88,18 @@ impl Igloo // get master target manifest self.master_target_manifest = IglooTargetManifest::get(self).unwrap(); + + // get master make manifest + // this is a hacky way of doing it until + // i can figure out a proper structure for deserializing + self.master_make_manifest.merge( + config::File::with_name( + self.env + .esfd + .clone() + .join("manifest") + .join("make-manifest.toml") + .to_str().unwrap())).unwrap(); // Assign instance type (new, run, push, etc) igloo_action::igloo_subcommand(&self.cli_info.raw) }