From 99453744371c418f3e372dc28d7bf1babb4f2a45 Mon Sep 17 00:00:00 2001 From: Penguin Date: Tue, 21 Dec 2021 19:55:14 -0600 Subject: [PATCH] configs have been a real pain... added a bunch of stubs for testing --- Cargo.lock | 52 ++++++++++----------- igloo_core/Cargo.toml | 6 ++- igloo_core/src/igloo_env.rs | 55 ++++++++++++---------- igloo_core/src/igloo_manifest.rs | 80 +++++++++++++------------------- igloo_core/src/igloo_project.rs | 16 +++++-- igloo_core/src/lib.rs | 21 +++++---- src/main.rs | 4 +- test/test_target_manifest.toml | 17 +++++++ 8 files changed, 135 insertions(+), 116 deletions(-) create mode 100644 test/test_target_manifest.toml diff --git a/Cargo.lock b/Cargo.lock index 5ef26eb..1e7d9a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,14 +79,14 @@ dependencies = [ [[package]] name = "config" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3" +checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369" dependencies = [ "lazy_static", "nom", "rust-ini", - "serde 1.0.130", + "serde 1.0.132", "serde-hjson", "serde_json", "toml", @@ -170,6 +170,8 @@ dependencies = [ "clap", "config", "directories", + "serde 1.0.132", + "toml", ] [[package]] @@ -213,16 +215,6 @@ version = "0.2.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" -[[package]] -name = "linked-hash-map" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd" -dependencies = [ - "serde 0.8.23", - "serde_test", -] - [[package]] name = "linked-hash-map" version = "0.5.4" @@ -368,9 +360,12 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" [[package]] name = "serde" -version = "1.0.130" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" +dependencies = [ + "serde_derive", +] [[package]] name = "serde-hjson" @@ -379,30 +374,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8" dependencies = [ "lazy_static", - "linked-hash-map 0.3.0", "num-traits 0.1.43", "regex", "serde 0.8.23", ] [[package]] -name = "serde_json" -version = "1.0.68" +name = "serde_derive" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276" dependencies = [ - "itoa", - "ryu", - "serde 1.0.130", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "serde_test" -version = "0.8.23" +name = "serde_json" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ - "serde 0.8.23", + "itoa", + "ryu", + "serde 1.0.132", ] [[package]] @@ -452,7 +448,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "serde 1.0.130", + "serde 1.0.132", ] [[package]] @@ -528,5 +524,5 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ - "linked-hash-map 0.5.4", + "linked-hash-map", ] diff --git a/igloo_core/Cargo.toml b/igloo_core/Cargo.toml index 5d9df72..803b153 100644 --- a/igloo_core/Cargo.toml +++ b/igloo_core/Cargo.toml @@ -7,5 +7,7 @@ edition = "2021" [dependencies] clap = "3.0.0-beta.2" -config = "0.10" -directories = "3.0.1" \ No newline at end of file +config = "0.11" +directories = "3.0.1" +toml = "0.5.8" +serde = { version = "1.0.132", features = ["derive"]} \ No newline at end of file diff --git a/igloo_core/src/igloo_env.rs b/igloo_core/src/igloo_env.rs index 1a7e483..cd1eb19 100644 --- a/igloo_core/src/igloo_env.rs +++ b/igloo_core/src/igloo_env.rs @@ -1,6 +1,6 @@ -#[derive(Debug)] -#[derive(PartialEq)] -#[derive(Clone)] +use crate::{PathBuf, env, UserDirs}; + +#[derive(Debug, PartialEq, Clone)] pub struct IglooEnv { // Current Working Directory @@ -13,32 +13,39 @@ pub struct IglooEnv impl IglooEnv { - pub fn get_env() -> IglooEnvInfo + pub fn get_env() -> IglooEnv { - cwd: env::current_dir().unwrap(), - hd: match UserDirs::new() + IglooEnv { - Some(v) => v.home_dir().to_owned(), - None => + cwd: match env::current_dir() { - println!("Error: Failed to get home directory.\n\ - This should never happen. Exiting..."); - std::process::exit(1); - } - }, - esfd: match std::env::var("ESF_DIR") - { - Ok(v) + Ok(v) => v, + Err(e) => panic!(), + }, + hd: match UserDirs::new() { - std::path::PathBuf::from(&v.to_owned()) - } - Err(e) => + Some(v) => v.home_dir().to_owned(), + None => + { + println!("Error: Failed to get home directory.\n\ + This should never happen. Exiting..."); + std::process::exit(1); + } + }, + esfd: match std::env::var("ESF_DIR") { - // Note : Need to change new to return actual errors - // instead of exiting early - println!("Error: $ESF_DIR not defined as an environment\ - variable -- {:?}", e); - std::process::exit(1); + Ok(v) => + { + std::path::PathBuf::from(&v.to_owned()) + } + Err(e) => + { + // Note : Need to change new to return actual errors + // instead of exiting early + println!("Error: $ESF_DIR not defined as an environment\ + variable -- {:?}", e); + std::process::exit(1); + } } } } diff --git a/igloo_core/src/igloo_manifest.rs b/igloo_core/src/igloo_manifest.rs index 14b006d..dc6b794 100644 --- a/igloo_core/src/igloo_manifest.rs +++ b/igloo_core/src/igloo_manifest.rs @@ -12,62 +12,48 @@ use crate::IglooType::*; use crate::igloo_target::IglooTarget; -/// Igloo Manifest Helper functions -/// USES: environment variables (home dir, esf dir, current dir) -/// DOES: brings target manifest into memory -pub fn imh_get_master_target_manifest(inst: &mut Igloo) -> IglooStatus -{ - let mut ret: IglooStatus = IS_GOOD; +use serde::{Serialize, Deserialize}; +use config::Config; - match inst.master_target_manifest.merge( - config::File::with_name( - inst.env.esfd.join("manifest/target-manifest.toml").to_str.unwrap())) - { - Ok(_v) => (), - Err(e) => - { - println!("Error: {:?}", e); - ret = IS_FAILED_TO_LOAD_MTM; - } - } - ret +#[derive(Serialize, Deserialize, Debug)] +pub struct IglooProjectManifest +{ + name: String, + targets: Vec:: } -pub fn imh_get_project_name(inst: &Igloo) -> String +impl IglooProjectManifest { - let project_config: config::Config = config::Config::new(); - match project_config.merge( - config::File::with_name( - inst.env.cwd.clone().join("igloo.toml").to_str().unwrap())) + pub fn default() -> IglooProjectManifest { - Ok(v) => + IglooProjectManifest { - return v.deserialize::>().unwrap()["Project"] + name: String::from(""), + targets: Vec::default(), + } - Err(e) => panic!(), } -} - -pub fn imh_get_targets(inst: &Igloo) -> Vec -{ - let project_config: config::Config = config::Config::new(); - match project_config.merge( - config::File::with_name( - inst.env.cwd.clone().join("igloo.toml").to_str().unwrap())) + pub fn from_project_file(self, igloo: &Igloo) -> Result { - Ok(v) => - { - match v.get("Targets") - { - Some(v2) => - { - for target in - { + let mut config = config::Config::default(); + config.merge( + config::File::with_name( + igloo.env + .cwd + .clone() + .join("igloo.toml") + .to_str().unwrap())).unwrap(); + + let z = config.deserialize::().unwrap(); + println!("{:?}", z); + + Ok(IglooProjectManifest::default()) + } - } - } - None => panic!(), - } - } + pub fn to_project_file(self, igloo: &Igloo) -> IglooStatus + { + IglooStatus::IS_GOOD } } + + diff --git a/igloo_core/src/igloo_project.rs b/igloo_core/src/igloo_project.rs index 12cd444..d0c50ba 100644 --- a/igloo_core/src/igloo_project.rs +++ b/igloo_core/src/igloo_project.rs @@ -18,6 +18,16 @@ pub struct IglooProject<'a> impl<'a> IglooProject<'a> { + pub fn default(igloo_in: &'a Igloo) -> IglooProject + { + IglooProject + { + igloo: igloo_in, + name: String::new(), + targets: Vec::default(), + + } + } /// Used to populate an IglooProject from scratch /// This means we do not yet have any project in storage /// and we must generate those directories, files, and symlinks @@ -41,10 +51,8 @@ impl<'a> IglooProject<'a> /// igloo run, push, pull, erase, etc... are called pub fn from_existing(igloo: &'a Igloo) -> IglooProject { - IglooProject - { - name: - } + IglooProject::default(igloo) + } pub fn is_igloo_prj(path: &std::path::PathBuf) -> bool diff --git a/igloo_core/src/lib.rs b/igloo_core/src/lib.rs index 0842cd2..f65e1b3 100644 --- a/igloo_core/src/lib.rs +++ b/igloo_core/src/lib.rs @@ -1,6 +1,8 @@ #![allow(warnings)] extern crate clap; extern crate config; +extern crate toml; +extern crate serde; use config::Config; use std::path::PathBuf; @@ -16,6 +18,7 @@ mod igloo_env; use igloo_cli::IglooCliInfo; use igloo_env::IglooEnv; +use igloo_project::IglooProject; #[derive(Debug)] #[derive(PartialEq)] @@ -80,15 +83,15 @@ impl Igloo { let mut res: IglooType = IT_NULL; - match igloo_manifest::get_master_target_manifest(self) - { - IS_GOOD => (), - e => - { - println!("{:?}", e); - return Err(e) - }, - } + // let master_target_manifest = match igloo_manifest::get_master_target_manifest(self) + // { + // IS_GOOD => , + // e => + // { + // println!("{:?}", e); + // return Err(e) + // }, + // } // Assign instance type (new, run, push, etc) igloo_action::igloo_subcommand(&self.cli_info.raw) diff --git a/src/main.rs b/src/main.rs index 72ff5f5..a22cb0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,8 @@ fn main() { match ig.run(it) { - Ok(rt) => println!("{:?}", rt), - Err(e) => println!("Run Error: {:?}", e), + IS_GOOD => println!("success"), + _ => println!("??"), } } Err(e) => println!("Error: {:?}", e), diff --git a/test/test_target_manifest.toml b/test/test_target_manifest.toml new file mode 100644 index 0000000..b13640d --- /dev/null +++ b/test/test_target_manifest.toml @@ -0,0 +1,17 @@ +[esf.links] +common = "arch/arm/common" +mcu = "arch/arm/SAMD21/SAMD21A/mcu" +ld = "arch/arm/SAMD21/SAMD21A/ld" +cfg = "arch/arm/SAMD21/SAMD21A/manifest" +[esf.includes] +IGLOO_INCLUDES = ["sam.h"] + +# These are defaults. Once a project is generated, the .cfg can be freely edited without fear of anything being overwritten. However, I do not recommend editing any of the _cfg variables. +[esf.scripts] +scripts = ["arch/arm/SAMD21/SAMD21A/scripts/${TARGET}.cfg", "scripts"] + +# lineage for this family of mcus +# this is used to evaluate makefile requirements for mcus +# this will be evaluated to "arch.arm.samd21a. +[esf.make] +series = "arch.arm.samd21a.${TARGET}"