unstable
penguin 4 years ago
parent 966e83a395
commit cb86cecfd7

@ -1,175 +1,46 @@
use std::vec::Vec;
use std::string::String;
use std::collections::HashMap;
use config::*;
use std::error::Error;
use clap::{Arg, App};
enum BuildType
{
Release,
Debug,
}
pub struct ProjectManager
{
makeManifest: MakeManifest,
mcuManifest: McuManifest,
}
impl ProjectManager
{
pub fn get_config() -> Self
{
let mut conf = Config::default();
ProjectManager
{
makeManifest: MakeManifest::from_config(&mut conf),
mcuManifest: McuManifest::from_config(&mut conf),
}
}
}
// used for managing cli requests for new and existing igloo projects
pub struct CliManager<'b>
#[derive(Debug)]
pub enum IglooInstType
{
app: clap::App<'b>,
debug_mode: bool,
release_mode: bool,
fresh_mode: bool,
version: &'b str,
name: &'b str,
author: &'b str,
description: &'b str,
IGLOO_NULL = -1,
IGLOO_NEW = 0,
IGLOO_RUN = 1,
IGLOO_FLASH = 2,
IGLOO_DEBUG = 3,
IGLOO_CLEAN = 4,
IGLOO_GENDOC = 5
}
impl<'b> CliManager<'b>
{
pub fn new() -> Self
{
CliManager
{
version: concat!("v", crate_version!()),
name: crate_name!(),
author: crate_authors!(),
description: crate_description!(),
debug_mode: true,
release_mode: false,
fresh_mode: false,
app: clap::App::new(crate_name!())
.author(crate_authors!())
.version(concat!("v", crate_version!())),
}
}
}
// Make Manifest contains default flags, files, and
// include directories. User files, flags, and directories
// can be added via the user yml in the cfg folder. They will be
// appended to these lists which are read from the default make manifest
// section in the mcu series yml file
pub struct MakeManifest
pub struct Igloo
{
linker_script: String,
src_files: Vec<config::Value>,
inc_dirs: Vec<config::Value>,
cflags: Vec<config::Value>,
libs: Vec<config::Value>,
cc: String,
ld: String,
ar: String,
inst_type: IglooInstType,
conf: config::Config,
}
impl MakeManifest
{
fn from_config(conf: &mut config::Config) -> MakeManifest
{
MakeManifest
{
src_files: conf.get_array("MAKEFILE_DEFAULT_SRC_FILES").unwrap_or_default(),
inc_dirs: conf.get_array("MAKEFILE_DEFAULT_INC_DIRS").unwrap_or_default(),
cflags: conf.get_array("CFLAGS").unwrap_or_default(),
libs: conf.get_array("EP_LIBS").unwrap_or_default(),
cc: conf.get_str("CC").unwrap_or_default(),
ld: conf.get_str("LD").unwrap_or_default(),
ar: conf.get_str("AR").unwrap_or_default(),
linker_script: conf.get_str("LINKER_SCRIPT").unwrap_or_default(),
}
}
}
impl std::fmt::Display for MakeManifest
impl Igloo
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
pub fn New() -> Igloo
{
// print src files
for src_file in &self.src_files
Igloo
{
write!(f, "{}\n", src_file).unwrap();
inst_type: IglooInstType::IGLOO_NULL,
conf: config::Config::default(),
}
// print inc dirs
// print cflags
// print cc
// print ld
// print ar
// print default linker script
Ok(())
}
}
// MCU Manifest contains the options for the mcu
// If, for example, a MCU has a USART peripheral,
// it is listed as a driver option here
// The user project manifest's mcu options are compared to the
// available options from the epsf which are stored here once read
struct McuManifest
{
core_deps: HashMap<String, config::Value>,
drivers: Vec<config::Value>,
modules: Vec<config::Value>,
}
impl McuManifest
{
pub fn from_config(conf: &mut config::Config) -> McuManifest
pub fn start(&self) -> Result<IglooInstType, String>
{
McuManifest
{
core_deps: conf.get_table("EP_DEPS").unwrap_or_default(),
drivers: conf.get_array("DRIVERS").unwrap_or_default(),
modules: conf.get_array("MODULES").unwrap_or_default(),
}
let matches = clap::App::new("igloo")
.about(clap::crate_description!())
.version(clap::crate_version!())
.get_matches();
Ok(IglooInstType::IGLOO_NULL)
}
}
impl std::fmt::Display for McuManifest
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
pub fn run(&self) -> Result<String, String>
{
// print ep deps
write!(f, "Printing core dependencies:\n").unwrap();
for dep in &self.core_deps
{
write!(f, "{}: {}\n", &dep.0, &dep.1).unwrap();
}
// Available drivers
write!(f, "\nAvailable drivers:\n").unwrap();
for driver in &self.drivers
{
write!(f, "{}\n", &driver).unwrap();
}
// Available modules
write!(f, "\nAvailable modules:\n").unwrap();
for module in &self.modules
{
write!(f, "{}\n", &module).unwrap();
}
Ok(())
Ok(String::from("Hello, we are running!\n"))
}
}

@ -1,196 +1,19 @@
mod igloo;
#[macro_use]
extern crate clap;
extern crate config;
mod igloo;
use clap::{crate_version, crate_description, crate_authors, App, Arg};
use config::*;
use std::collections::HashMap;
fn main()
{
println!("Hi");
let _igloo = igloo::CliManager::new();
let pm = igloo::ProjectManager::get_config();
// let mut _igloo: Igloo = Igloo
// {
// debug_mode: true,
// release_mode: false,
// fresh_mode: false,
// version: "v".to_owned() + crate_version!(),
// name: String::from("Igloo"),
// author: crate_authors!().to_owned(),
// description: crate_description!().to_owned(),
// };
// let matches = App::new(&*_igloo.name)
// .version(&*_igloo.version)
// .author(&*_igloo.author)
// .about(&*_igloo.description)
// .arg(Arg::with_name("VERSION")
// .short('v')
// .multiple(true)
// .about("Sets the level of verbosity"))
// .subcommand(App::new("new")
// .about("Creates a new igloo project")
// .arg(
// Arg::new("NAME")
// .required(true)
// .about("The name of your new project")))
// .subcommand(App::new("run")
// .about("Builds project on target selected in config file")
// .arg(Arg::new("RELEASE")
// .short('R')
// .long("release")
// .about("builds in release mode"))
// .arg(Arg::new("DEBUG")
// .short('D')
// .long("debug")
// .about("builds in debug mode"))
// .arg(Arg::new("FRESH")
// .short('F')
// .long("fresh")
// .about("Clean project, then builds project")))
// .subcommand(App::new("build")
// .about("Builds project on target selected in config file")
// .arg(Arg::new("RELEASE")
// .short('R')
// .long("release")
// .about("builds in release mode"))
// .arg(Arg::new("DEBUG")
// .short('D')
// .long("debug")
// .about("builds in debug mode"))
// .arg(Arg::new("FRESH")
// .short('F')
// .long("fresh")
// .about("Clean project, then builds project")))
// .subcommand(App::new("clean")
// .about("Cleans project")
// .version("0.0")
// .arg(Arg::new("verbose")
// .short('v')
// .about("cleans project and prints extra info")))
// .get_matches();
// match matches.subcommand()
// {
// ("new", Some(new_matches)) =>
// {
// igloo_new(&_igloo, new_matches.value_of("NAME").unwrap());
// }
// ("run", Some(run_matches)) =>
// {
// if run_matches.is_present("FRESH")
// {
// println!("Building fresh project");
// _igloo.fresh_mode = true;
// }
// if run_matches.is_present("RELEASE") && run_matches.is_present("DEBUG")
// {
// println!("Can't run in debug and release mode...");
// process::exit(1);
// }
// else if run_matches.is_present("DEBUG")
// {
// _igloo.debug_mode = true;
// }
// else if run_matches.is_present("RELEASE")
// {
// _igloo.release_mode = true;
// _igloo.debug_mode = false;
// }
// igloo_run(&_igloo);
// }
// ("build", Some(build_matches)) =>
// {
// if build_matches.is_present("FRESH")
// {
// println!("Building fresh project");
// _igloo.fresh_mode = true;
// }
// if build_matches.is_present("RELEASE") && build_matches.is_present("DEBUG")
// {
// println!("Can't run in debug and release mode...");
// process::exit(1);
// }
// else if build_matches.is_present("DEBUG")
// {
// _igloo.debug_mode = true;
// }
// else if build_matches.is_present("RELEASE")
// {
// _igloo.release_mode = true;
// _igloo.debug_mode = false;
// }
// }
// ("", None) => println!("No subcommand was used"),
// _ => unreachable!(),
// }
}
// fn igloo_new_with_dir(igloo_inst: &Igloo, prj_name: &str, prj_dir: &str)
// {
// // WIP
// }
// fn igloo_new(igloo_inst: &Igloo, prj_name: &str)
// {
// let path = Path::new(prj_name);
// if path.exists()
// {
// println!("Project already exists. Exiting...");
// process::exit(1);
// }
let ig = igloo::Igloo::New();
match ig.start()
{
Ok(d) => println!("{:?}", d),
Err(_) => panic!("FUCK"),
}
// println!("Making new project named {}", path.display());
// match fs::create_dir(prj_name)
// {
// Err(why) => println!("! {:?}", why.kind()),
// Ok(_) => {},
// }
// if cfg!(target_family = "unix")
// {
// println!("You are on unix!\n");
// }
// else
// {
// println!("only unix is currently supported!");
// }
// }
// fn igloo_run(igloo_inst: &Igloo)
// {
// }
// fn igloo_build(igloo_inst: &Igloo)
// {
// }
// fn igloo_clean(igloo_inst: &Igloo)
// {
// }
// fn igloo_init(igloo_inst: &Igloo)
// {
// }
// fn igloo_search(igloo_inst: &Igloo)
// {
// }
// fn igloo_test(igloo_inst: &Igloo)
// {
// }
// fn igloo_doc(igloo_inst: &Igloo)
// {
// }
}

Loading…
Cancel
Save