Moved more code from igloo_project to igloo_target

unstable
penguin 4 years ago
parent 6d0008843c
commit 84a556fe8e

@ -4,12 +4,11 @@ use igloo_manifest::*;
use crate::Igloo; use crate::Igloo;
use crate::igloo_target::IglooTarget; use crate::igloo_target::IglooTarget;
use std::vec::Vec;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::fs::File; use std::fs::File;
use std::vec::Vec;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::PathBuf;
// New Project // New Project
// --- Verify location // --- Verify location
// --- Populate base folders // --- Populate base folders
@ -23,6 +22,7 @@ pub struct IglooPrj
name: String, name: String,
target_bank: Vec<IglooTarget>, target_bank: Vec<IglooTarget>,
pub project_dir: std::path::PathBuf, pub project_dir: std::path::PathBuf,
root: PathBuf,
} }
@ -35,6 +35,7 @@ impl IglooPrj
name: String::from(""), name: String::from(""),
target_bank: Vec::default(), target_bank: Vec::default(),
project_dir: std::path::PathBuf::default(), project_dir: std::path::PathBuf::default(),
root: PathBuf::default(),
} }
} }
@ -52,7 +53,8 @@ impl IglooPrj
{ {
return Err(res_err) return Err(res_err)
} }
match target_exists(&inst.master_make_man, &inst.master_target_man, target_in)
match target_is_valid(&inst.master_make_man, &inst.master_target_man, target_in)
{ {
Ok(v) => Ok(v) =>
{ {
@ -96,6 +98,8 @@ impl IglooPrj
name: String::from(name_in), name: String::from(name_in),
target_bank: temp, target_bank: temp,
project_dir: IglooEnvInfo::get_env_info().cwd.join(name_in), project_dir: IglooEnvInfo::get_env_info().cwd.join(name_in),
root: PathBuf::from(
IglooEnvInfo::get_env_info().cwd.join(name_in)),
}) })
} }
@ -103,17 +107,14 @@ impl IglooPrj
{ {
// Create new directory // Create new directory
let mut active_dir = IglooEnvInfo::get_env_info().cwd; let mut active_dir = self.root.clone();
//println!("Active Directory: {:?}", active_dir.display());
println!("NAME: {}", self.name);
active_dir.push(&self.name);
match std::fs::create_dir(&active_dir) match std::fs::create_dir(&active_dir)
{ {
Err(e) => println!("{:?}", e), Err(e) => println!("{:?}", e),
_ => (), _ => (),
} }
//println!("Active Directory: {:?}", active_dir.display());
println!("Creating .igloo dir..."); // Create .igloo directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join(".igloo")) .join(".igloo"))
@ -122,6 +123,7 @@ impl IglooPrj
_ => (), _ => (),
} }
// Create target directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join(".igloo/target")) .join(".igloo/target"))
@ -130,6 +132,7 @@ impl IglooPrj
_ => (), _ => (),
} }
// Create src directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join("src")) .join("src"))
@ -137,6 +140,8 @@ impl IglooPrj
Err(e) => println!("{:?}", e), Err(e) => println!("{:?}", e),
_ => (), _ => (),
} }
// Create inc directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join("inc")) .join("inc"))
@ -144,6 +149,8 @@ impl IglooPrj
Err(e) => println!("{:?}", e), Err(e) => println!("{:?}", e),
_ => (), _ => (),
} }
// Create cfg directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join("cfg")) .join("cfg"))
@ -151,6 +158,8 @@ impl IglooPrj
Err(e) => println!("{:?}", e), Err(e) => println!("{:?}", e),
_ => (), _ => (),
} }
// Create ESF directory
match std::fs::create_dir( match std::fs::create_dir(
std::path::Path::new(&active_dir) std::path::Path::new(&active_dir)
.join("ESF")) .join("ESF"))
@ -159,12 +168,15 @@ impl IglooPrj
_ => (), _ => (),
} }
// Generate Targets
self.gen_targets(); self.gen_targets();
// Generate igloo.h
self.gen_igloo_header(); self.gen_igloo_header();
// Generate main.c
self.gen_igloo_main(); self.gen_igloo_main();
//self.debugManifests();
ErrNone ErrNone
} }
@ -188,117 +200,16 @@ impl IglooPrj
/// Generates the target directories for all targets /// Generates the target directories for all targets
pub fn gen_targets(&self) -> IglooErrType pub fn gen_targets(&self) -> IglooErrType
{ {
let prj_root = self.project_dir.join(".igloo");
for target in &self.target_bank for target in &self.target_bank
{ {
let target_root = prj_root.join(&("target/".to_owned() + &target.name)); target.generate();
println!("{:?}", target_root.display()); target.populate();
match std::fs::create_dir(&target_root) target.generate_openocd_config();
{
Err(e) => println!("{:?}", e),
_ => (),
}
// create project scripts dir
let scripts_dir = target_root.join("scripts");
match std::fs::create_dir(&scripts_dir)
{
Err(e) => println!("{:?}", e),
_ => (),
}
// populate scripts dir
//sym link gdb scripts
let gdb_scripts_paths = std::fs::read_dir(
&(String::from(
IglooEnvInfo::get_env_info()
.esfd.to_str()
.unwrap()) + "/scripts"))
.unwrap();
let mut gdb_scripts: std::vec::Vec<std::path::PathBuf>
= std::vec::Vec::new();
for entry in gdb_scripts_paths
{
match &entry
{
Ok(v) => if !v.path().is_dir() {
gdb_scripts.push(v.path()) },
Err(e) => println!("{:?}", e),
}
}
for file in gdb_scripts
{
println!("Project Scripts Dir: {:?}", scripts_dir);
println!("ePenguin Scripts Dir: {:?}", file);
std::os::unix::fs::symlink(
&file, &scripts_dir.join(&file.file_name().unwrap())).unwrap();
}
let prj_esf_dir = self.project_dir.join("ESF");
for (sym_dir, loc_in_esf) in &target.links
{
let link_to_dir = IglooEnvInfo::get_env_info()
.esfd
.join(&loc_in_esf.clone().into_str().unwrap());
std::os::unix::fs::symlink(link_to_dir, prj_esf_dir.join(sym_dir)).unwrap();
}
self.gen_openocd_config(&target);
self.gen_makefile(&target); self.gen_makefile(&target);
} }
ErrNone ErrNone
} }
pub fn gen_openocd_config(&self, target: &IglooTarget) -> IglooErrType
{
let mut openocd_cfg = self.project_dir.join(".igloo/target");
openocd_cfg.push(&target.name);
openocd_cfg.push("scripts");
openocd_cfg.push(&self.name);
if openocd_cfg.with_extension("cfg").exists()
{
std::fs::remove_file(openocd_cfg.with_extension("cfg")).unwrap();
}
std::fs::File::create(
openocd_cfg.with_extension("cfg")).unwrap();
let mut ocfg_file = OpenOptions::new()
.write(true)
.append(true)
.open(openocd_cfg.with_extension("cfg"))
.unwrap();
writeln!(ocfg_file, "#\n# ePenguin Generated OpenOCD \
Config Script\n#\n").unwrap();
writeln!(ocfg_file, "\n# Transport Select").unwrap();
writeln!(ocfg_file, "source [find interface//{}.cfg]", target
.openocd.get("transport_cfg")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
writeln!(ocfg_file, "transport select {}", target
.openocd.get("transport")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
writeln!(ocfg_file, "\n# Chip Information").unwrap();
writeln!(ocfg_file, "set CHIPNAME {}", target.name).unwrap();
writeln!(ocfg_file, "source [find target//{}.cfg]", target
.openocd.get("chip_name_cfg")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
ErrNone
}
/// Generates a makefile for a target /// Generates a makefile for a target
pub fn gen_makefile(&self, target: &IglooTarget) -> IglooErrType pub fn gen_makefile(&self, target: &IglooTarget) -> IglooErrType
{ {

@ -7,6 +7,9 @@ use crate::Igloo;
use crate::config::Config; use crate::config::Config;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::fs::OpenOptions;
use std::fs::File;
use std::io::prelude::*;
pub struct IglooTarget pub struct IglooTarget
{ {
@ -106,6 +109,19 @@ impl IglooTarget
/// generate all folders needed for the target /// generate all folders needed for the target
pub fn generate(&self) -> IglooErrType pub fn generate(&self) -> IglooErrType
{ {
// Create target root directory
match std::fs::create_dir(&self.root)
{
Err(e) => println!("{:?}", e),
_ => (),
}
// Create target scripts directory
match std::fs::create_dir(&self.root.join("scripts"))
{
Err(e) => println!("{:?}", e),
_ => (),
}
ErrNone ErrNone
} }
@ -113,6 +129,53 @@ impl IglooTarget
/// populates all folders needed for the target /// populates all folders needed for the target
pub fn populate(&self) -> IglooErrType pub fn populate(&self) -> IglooErrType
{ {
let mut target_scripts_dir: PathBuf = PathBuf::from(
self.root.join("scripts"));
// Read the gdb scripts directory in ESF
let esf_target_scripts_dir = std::fs::read_dir(
&(String::from(
IglooEnvInfo::get_env_info()
.esfd.to_str()
.unwrap()) + "/scripts"))
.unwrap();
// Creating a vector to hold our gdb script file names
let mut gdb_scripts: std::vec::Vec<std::path::PathBuf>
= std::vec::Vec::new();
// Grab the files only
for entry in esf_target_scripts_dir
{
match &entry
{
Ok(v) => if !v.path().is_dir() {
gdb_scripts.push(v.path()) },
Err(e) => println!("{:?}", e),
}
}
// Generate each GDB script
for file in gdb_scripts
{
std::os::unix::fs::symlink(
&file, &target_scripts_dir.join(&file.file_name().unwrap())).unwrap();
}
// Populate the project ESF folder with our targets relevant files
let mut prj_esf_dir = self.root
.parent().unwrap()
.parent().unwrap()
.parent().unwrap().join("ESF");
println!("PRINTING {:?}", prj_esf_dir);
for (sym_dir, loc_in_esf) in &self.links
{
let link_to_dir = IglooEnvInfo::get_env_info()
.esfd
.join(&loc_in_esf.clone().into_str().unwrap());
std::os::unix::fs::symlink(link_to_dir, prj_esf_dir.join(sym_dir)).unwrap();
}
ErrNone ErrNone
} }
@ -122,4 +185,53 @@ impl IglooTarget
{ {
ErrNone ErrNone
} }
/// generates the openocd config for a target
/// this will be updated as the user edits their project toml
pub fn generate_openocd_config(&self) -> IglooErrType
{
let mut openocd_cfg = PathBuf::from(&self.root);
openocd_cfg.push("scripts");
openocd_cfg.push(&self.name);
if openocd_cfg.with_extension("cfg").exists()
{
std::fs::remove_file(openocd_cfg.with_extension("cfg")).unwrap();
}
std::fs::File::create(
openocd_cfg.with_extension("cfg")).unwrap();
let mut ocfg_file = OpenOptions::new()
.write(true)
.append(true)
.open(openocd_cfg.with_extension("cfg"))
.unwrap();
writeln!(ocfg_file, "#\n# ePenguin Generated OpenOCD \
Config Script\n#\n").unwrap();
writeln!(ocfg_file, "\n# Transport Select").unwrap();
writeln!(ocfg_file, "source [find interface//{}.cfg]", self
.openocd.get("transport_cfg")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
writeln!(ocfg_file, "transport select {}", self
.openocd.get("transport")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
writeln!(ocfg_file, "\n# Chip Information").unwrap();
writeln!(ocfg_file, "set CHIPNAME {}", self.name).unwrap();
writeln!(ocfg_file, "source [find target//{}.cfg]", self
.openocd.get("chip_name_cfg")
.unwrap()
.clone()
.into_str()
.unwrap()).unwrap();
ErrNone
}
} }

@ -55,7 +55,7 @@ pub fn get_master_target_manifest(man: &mut Config) -> IglooErrType
/// master_mm -- Master Make Manifest /// master_mm -- Master Make Manifest
/// master_tm -- Master Target Manifest /// master_tm -- Master Target Manifest
/// name -- name of target /// name -- name of target
pub fn target_exists(master_mm: &Config, master_tm: &Config, name: &str) pub fn target_is_valid(master_mm: &Config, master_tm: &Config, name: &str)
-> Result<bool, IglooErrType> -> Result<bool, IglooErrType>
{ {
let mut ret: bool = true; let mut ret: bool = true;

Loading…
Cancel
Save