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]
|
||||
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()
|
||||
{
|
||||
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
|
||||
println!("Hi");
|
||||
let _igloo = igloo::CliManager::new();
|
||||
// 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(igloo_inst: &Igloo, prj_name: &str)
|
||||
{
|
||||
let path = Path::new(prj_name);
|
||||
if path.exists()
|
||||
{
|
||||
println!("Project already exists. Exiting...");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
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_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);
|
||||
// }
|
||||
|
||||
}
|
||||
// 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