trying to fix things
parent
a8433c6541
commit
3e754c166c
@ -0,0 +1,168 @@
|
|||||||
|
|
||||||
|
|
||||||
|
use std::vec::Vec;
|
||||||
|
use std::string::String;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use config::*;
|
||||||
|
|
||||||
|
use clap::{Arg, App};
|
||||||
|
enum BuildType
|
||||||
|
{
|
||||||
|
Release,
|
||||||
|
Debug,
|
||||||
|
}
|
||||||
|
// used for managing existing igloo projects
|
||||||
|
// Igloo Project Manager - A struct for holding all
|
||||||
|
// information pertaining to the current Igloo Project
|
||||||
|
// An igloo project uses the .igloo folder to maintain
|
||||||
|
// knowledge of its existence.
|
||||||
|
pub struct ProjectManager
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// used for managing cli requests for new and existing igloo projects
|
||||||
|
pub struct CliManager<'b>
|
||||||
|
{
|
||||||
|
app: clap::App<'b>,
|
||||||
|
debug_mode: bool,
|
||||||
|
release_mode: bool,
|
||||||
|
fresh_mode: bool,
|
||||||
|
version: String,
|
||||||
|
name: String,
|
||||||
|
author: &'b str,
|
||||||
|
description: &'b str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'b> CliManager<'b>
|
||||||
|
{
|
||||||
|
pub fn new(this: &'b Self) -> Self
|
||||||
|
{
|
||||||
|
let _version = "v".to_owned() + crate_version!();
|
||||||
|
CliManager
|
||||||
|
{
|
||||||
|
version: _version.to_owned(),
|
||||||
|
name: crate_name!().to_owned(),
|
||||||
|
author: crate_authors!(),
|
||||||
|
description: crate_description!(),
|
||||||
|
debug_mode: true,
|
||||||
|
release_mode: false,
|
||||||
|
fresh_mode: false,
|
||||||
|
app: clap::App::new(this.name)
|
||||||
|
.author(this.author)
|
||||||
|
.version(&*this.version)
|
||||||
|
.about(this.description),
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
|
||||||
|
{
|
||||||
|
// print src files
|
||||||
|
for src_file in &self.src_files
|
||||||
|
{
|
||||||
|
write!(f, "{}\n", src_file).unwrap();
|
||||||
|
}
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for McuManifest
|
||||||
|
{
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
|
||||||
|
{
|
||||||
|
// 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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,214 +1,194 @@
|
|||||||
|
mod igloo;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
use clap::{Arg, App, ArgGroup};
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::process;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::fs;
|
|
||||||
use std::fs::{File, OpenOptions};
|
|
||||||
use std::os::unix;
|
|
||||||
enum BuildTypes
|
|
||||||
{
|
|
||||||
Release,
|
|
||||||
Debug,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Igloo
|
|
||||||
{
|
|
||||||
debug_mode: bool,
|
|
||||||
release_mode: bool,
|
|
||||||
fresh_mode: bool,
|
|
||||||
version: String,
|
|
||||||
name: String,
|
|
||||||
author: String,
|
|
||||||
description: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
let mut _igloo: Igloo = Igloo
|
println!("Hi");
|
||||||
{
|
let _igloo = igloo::CliManager::new();
|
||||||
debug_mode: true,
|
// let mut _igloo: Igloo = Igloo
|
||||||
release_mode: false,
|
// {
|
||||||
fresh_mode: false,
|
// debug_mode: true,
|
||||||
version: "v".to_owned() + crate_version!(),
|
// release_mode: false,
|
||||||
name: String::from("Igloo"),
|
// fresh_mode: false,
|
||||||
author: crate_authors!().to_owned(),
|
// version: "v".to_owned() + crate_version!(),
|
||||||
description: crate_description!().to_owned(),
|
// name: String::from("Igloo"),
|
||||||
};
|
// author: crate_authors!().to_owned(),
|
||||||
let matches = App::new(&*_igloo.name)
|
// description: crate_description!().to_owned(),
|
||||||
.version(&*_igloo.version)
|
// };
|
||||||
.author(&*_igloo.author)
|
// let matches = App::new(&*_igloo.name)
|
||||||
.about(&*_igloo.description)
|
// .version(&*_igloo.version)
|
||||||
.arg(Arg::with_name("VERSION")
|
// .author(&*_igloo.author)
|
||||||
.short('v')
|
// .about(&*_igloo.description)
|
||||||
.multiple(true)
|
// .arg(Arg::with_name("VERSION")
|
||||||
.about("Sets the level of verbosity"))
|
// .short('v')
|
||||||
.subcommand(App::new("new")
|
// .multiple(true)
|
||||||
.about("Creates a new igloo project")
|
// .about("Sets the level of verbosity"))
|
||||||
.arg(
|
// .subcommand(App::new("new")
|
||||||
Arg::new("NAME")
|
// .about("Creates a new igloo project")
|
||||||
.required(true)
|
// .arg(
|
||||||
.about("The name of your new project")))
|
// Arg::new("NAME")
|
||||||
.subcommand(App::new("run")
|
// .required(true)
|
||||||
.about("Builds project on target selected in config file")
|
// .about("The name of your new project")))
|
||||||
.arg(Arg::new("RELEASE")
|
// .subcommand(App::new("run")
|
||||||
.short('R')
|
// .about("Builds project on target selected in config file")
|
||||||
.long("release")
|
// .arg(Arg::new("RELEASE")
|
||||||
.about("builds in release mode"))
|
// .short('R')
|
||||||
.arg(Arg::new("DEBUG")
|
// .long("release")
|
||||||
.short('D')
|
// .about("builds in release mode"))
|
||||||
.long("debug")
|
// .arg(Arg::new("DEBUG")
|
||||||
.about("builds in debug mode"))
|
// .short('D')
|
||||||
.arg(Arg::new("FRESH")
|
// .long("debug")
|
||||||
.short('F')
|
// .about("builds in debug mode"))
|
||||||
.long("fresh")
|
// .arg(Arg::new("FRESH")
|
||||||
.about("Clean project, then builds project")))
|
// .short('F')
|
||||||
.subcommand(App::new("build")
|
// .long("fresh")
|
||||||
.about("Builds project on target selected in config file")
|
// .about("Clean project, then builds project")))
|
||||||
.arg(Arg::new("RELEASE")
|
// .subcommand(App::new("build")
|
||||||
.short('R')
|
// .about("Builds project on target selected in config file")
|
||||||
.long("release")
|
// .arg(Arg::new("RELEASE")
|
||||||
.about("builds in release mode"))
|
// .short('R')
|
||||||
.arg(Arg::new("DEBUG")
|
// .long("release")
|
||||||
.short('D')
|
// .about("builds in release mode"))
|
||||||
.long("debug")
|
// .arg(Arg::new("DEBUG")
|
||||||
.about("builds in debug mode"))
|
// .short('D')
|
||||||
.arg(Arg::new("FRESH")
|
// .long("debug")
|
||||||
.short('F')
|
// .about("builds in debug mode"))
|
||||||
.long("fresh")
|
// .arg(Arg::new("FRESH")
|
||||||
.about("Clean project, then builds project")))
|
// .short('F')
|
||||||
.subcommand(App::new("clean")
|
// .long("fresh")
|
||||||
.about("Cleans project")
|
// .about("Clean project, then builds project")))
|
||||||
.version("0.0")
|
// .subcommand(App::new("clean")
|
||||||
.arg(Arg::new("verbose")
|
// .about("Cleans project")
|
||||||
.short('v')
|
// .version("0.0")
|
||||||
.about("cleans project and prints extra info")))
|
// .arg(Arg::new("verbose")
|
||||||
.get_matches();
|
// .short('v')
|
||||||
|
// .about("cleans project and prints extra info")))
|
||||||
|
// .get_matches();
|
||||||
match matches.subcommand()
|
|
||||||
{
|
|
||||||
("new", Some(new_matches)) =>
|
// match matches.subcommand()
|
||||||
{
|
// {
|
||||||
igloo_new(&_igloo, new_matches.value_of("NAME").unwrap());
|
// ("new", Some(new_matches)) =>
|
||||||
}
|
// {
|
||||||
|
// igloo_new(&_igloo, new_matches.value_of("NAME").unwrap());
|
||||||
("run", Some(run_matches)) =>
|
// }
|
||||||
{
|
|
||||||
|
// ("run", Some(run_matches)) =>
|
||||||
if run_matches.is_present("FRESH")
|
// {
|
||||||
{
|
|
||||||
println!("Building fresh project");
|
// if run_matches.is_present("FRESH")
|
||||||
_igloo.fresh_mode = true;
|
// {
|
||||||
}
|
// 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...");
|
// if run_matches.is_present("RELEASE") && run_matches.is_present("DEBUG")
|
||||||
process::exit(1);
|
// {
|
||||||
}
|
// println!("Can't run in debug and release mode...");
|
||||||
else if run_matches.is_present("DEBUG")
|
// process::exit(1);
|
||||||
{
|
// }
|
||||||
_igloo.debug_mode = true;
|
// else if run_matches.is_present("DEBUG")
|
||||||
}
|
// {
|
||||||
else if run_matches.is_present("RELEASE")
|
// _igloo.debug_mode = true;
|
||||||
{
|
// }
|
||||||
_igloo.release_mode = true;
|
// else if run_matches.is_present("RELEASE")
|
||||||
_igloo.debug_mode = false;
|
// {
|
||||||
}
|
// _igloo.release_mode = true;
|
||||||
|
// _igloo.debug_mode = false;
|
||||||
igloo_run(&_igloo);
|
// }
|
||||||
|
|
||||||
|
// igloo_run(&_igloo);
|
||||||
}
|
|
||||||
("build", Some(build_matches)) =>
|
|
||||||
{
|
// }
|
||||||
if build_matches.is_present("FRESH")
|
// ("build", Some(build_matches)) =>
|
||||||
{
|
// {
|
||||||
println!("Building fresh project");
|
// if build_matches.is_present("FRESH")
|
||||||
_igloo.fresh_mode = true;
|
// {
|
||||||
}
|
// 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...");
|
// if build_matches.is_present("RELEASE") && build_matches.is_present("DEBUG")
|
||||||
process::exit(1);
|
// {
|
||||||
}
|
// println!("Can't run in debug and release mode...");
|
||||||
else if build_matches.is_present("DEBUG")
|
// process::exit(1);
|
||||||
{
|
// }
|
||||||
_igloo.debug_mode = true;
|
// else if build_matches.is_present("DEBUG")
|
||||||
}
|
// {
|
||||||
else if build_matches.is_present("RELEASE")
|
// _igloo.debug_mode = true;
|
||||||
{
|
// }
|
||||||
_igloo.release_mode = true;
|
// else if build_matches.is_present("RELEASE")
|
||||||
_igloo.debug_mode = false;
|
// {
|
||||||
}
|
// _igloo.release_mode = true;
|
||||||
}
|
// _igloo.debug_mode = false;
|
||||||
("", None) => println!("No subcommand was used"),
|
// }
|
||||||
_ => unreachable!(),
|
// }
|
||||||
}
|
// ("", 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)
|
// fn igloo_new_with_dir(igloo_inst: &Igloo, prj_name: &str, prj_dir: &str)
|
||||||
{
|
// {
|
||||||
let path = Path::new(prj_name);
|
// // WIP
|
||||||
if path.exists()
|
// }
|
||||||
{
|
// fn igloo_new(igloo_inst: &Igloo, prj_name: &str)
|
||||||
println!("Project already exists. Exiting...");
|
// {
|
||||||
process::exit(1);
|
// let path = Path::new(prj_name);
|
||||||
}
|
// if path.exists()
|
||||||
|
// {
|
||||||
println!("Making new project named {}", path.display());
|
// println!("Project already exists. Exiting...");
|
||||||
match fs::create_dir(prj_name)
|
// process::exit(1);
|
||||||
{
|
// }
|
||||||
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
// println!("Making new project named {}", path.display());
|
||||||
|
// match fs::create_dir(prj_name)
|
||||||
|
// {
|
||||||
|
// Err(why) => println!("! {:?}", why.kind()),
|
||||||
|
// Ok(_) => {},
|
||||||
|
// }
|
||||||
|
|
||||||
fn igloo_build(igloo_inst: &Igloo)
|
// 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_clean(igloo_inst: &Igloo)
|
// fn igloo_build(igloo_inst: &Igloo)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn igloo_init(igloo_inst: &Igloo)
|
// fn igloo_clean(igloo_inst: &Igloo)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn igloo_search(igloo_inst: &Igloo)
|
// fn igloo_init(igloo_inst: &Igloo)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn igloo_test(igloo_inst: &Igloo)
|
// fn igloo_search(igloo_inst: &Igloo)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn igloo_doc(igloo_inst: &Igloo)
|
// fn igloo_test(igloo_inst: &Igloo)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// fn igloo_doc(igloo_inst: &Igloo)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
use std::vec::Vec;
|
|
||||||
use std::string::String;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt::Display;
|
|
||||||
use config::*;
|
|
||||||
|
|
||||||
struct McuManifest
|
|
||||||
{
|
|
||||||
ep_deps: HashMap<String, config::Value>,
|
|
||||||
makefile_default_src_files: Vec<config::Value>,
|
|
||||||
makefile_default_inc_dirs: Vec<config::Value>,
|
|
||||||
drivers: Vec<config::Value>,
|
|
||||||
modules: Vec<config::Value>,
|
|
||||||
}
|
|
||||||
impl Display for McuManifest
|
|
||||||
{
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
|
|
||||||
{
|
|
||||||
// print ep deps
|
|
||||||
write!(f, "Printing EP DEPS:\n").unwrap();
|
|
||||||
for dep in &self.ep_deps
|
|
||||||
{
|
|
||||||
write!(f, "{}: {}\n", &dep.0, &dep.1).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// print makefile default src files
|
|
||||||
write!(f, "\nDefault makefile sources:\n").unwrap();
|
|
||||||
for src_file in &self.makefile_default_src_files
|
|
||||||
{
|
|
||||||
write!(f, "{}\n", &src_file).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// print makefile default inc dirs
|
|
||||||
for inc_dir in &self.makefile_default_inc_dirs
|
|
||||||
{
|
|
||||||
write!(f, "{}\n", &inc_dir).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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn yml_to_mcu_manifest(conf: &mut config::Config) -> McuManifest
|
|
||||||
{
|
|
||||||
McuManifest
|
|
||||||
{
|
|
||||||
ep_deps: conf.get_table("EP_DEPS").unwrap_or_default(),
|
|
||||||
makefile_default_inc_dirs: conf.get_array("MAKEFILE_DEFAULT_INC_DIRS").unwrap_or_default(),
|
|
||||||
makefile_default_src_files: conf.get_array("MAKEFILE_DEFAULT_SRC_FILES").unwrap_or_default(),
|
|
||||||
drivers: conf.get_array("DRIVERS").unwrap_or_default(),
|
|
||||||
modules: conf.get_array("MODULES").unwrap_or_default(),
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue