Commented the current code.

The output directory is now also set at the start.
This commit is contained in:
Jason Travis Smith 2016-04-08 19:59:39 -04:00
parent d38f5c6291
commit 9897d90be9
3 changed files with 74 additions and 19 deletions

View File

@ -17,7 +17,7 @@ to be placed, and what tool should be used to build them. The file should be
placed in the "resources" directory and named "resources.msnr". placed in the "resources" directory and named "resources.msnr".
The format is a simple text file composed of sections seperated by The format is a simple text file composed of sections seperated by
empty lines. Each section defines a resource to comile. The format for empty lines. Each section defines a resource to compile. The format for
each section is as follows. each section is as follows.

View File

@ -5,6 +5,7 @@ extern crate mason;
use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use mason::Processor; use mason::Processor;
@ -48,7 +49,21 @@ pub fn main()
None => None =>
{ {
output_dir = PathBuf::new(); // Try to just get the current directory.
match env::current_dir()
{
Ok(dir) =>
{
output_dir = PathBuf::from(dir);
}
Err(error) =>
{
// Then just default to "".
warn!("{}", error);
output_dir = PathBuf::new();
}
}
} }
} }

View File

@ -1,36 +1,40 @@
use std::env;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
/// /// The default name of the resources directory.
const DEFAULT_RESOURCES_DIR: &'static str = "resources"; const DEFAULT_RESOURCES_DIR: &'static str = "resources";
/// /// The default name to be used for the resource manifest file.
const DEFAULT_MANIFEST_FILENAME: &'static str = "resources.msnr"; const DEFAULT_MANIFEST_FILENAME: &'static str = "resources.msnr";
/// /// Defines a resource to be compiled.
struct Section struct Section
{ {
/// /// A unique name used to reference the
/// resource defined in this Section.
pub name: String, pub name: String,
/// /// A hint for what kind of loader to
/// use for this resource.
pub type_hint: String, pub type_hint: String,
/// /// The path to the resources src information.
pub src_path: String, pub src_path: String,
/// /// The path to place the compiled resource at.
pub dst_path: String, pub dst_path: String,
/// /// The compiler to invoke to compile the
/// resource defined in this Section.
pub compiler: String, pub compiler: String,
/// /// The arguments to pass to the compiler.
pub arguments: String pub arguments: String
} }
@ -59,7 +63,7 @@ pub struct Processor
impl Section impl Section
{ {
/// /// Create a new Section with default values.
pub fn new() -> Section pub fn new() -> Section
{ {
Section Section
@ -76,41 +80,68 @@ impl Section
impl Processor impl Processor
{ {
/// /// Create a new resource manifest Processor.
pub fn new() -> Processor pub fn new() -> Processor
{ {
let out_dir: PathBuf;
// Try to just get the current directory.
match env::current_dir()
{
Ok(dir) =>
{
out_dir = PathBuf::from(dir);
}
Err(error) =>
{
warn!("{}", error);
out_dir = PathBuf::new();
}
}
Processor Processor
{ {
manifest_filename: String::from(DEFAULT_MANIFEST_FILENAME), manifest_filename: String::from(DEFAULT_MANIFEST_FILENAME),
resources_dir: PathBuf::from(DEFAULT_RESOURCES_DIR), resources_dir: PathBuf::from(DEFAULT_RESOURCES_DIR),
output_dir: PathBuf::new(), output_dir: out_dir,
task_count: 1u64, task_count: 1u64,
sections: Vec::new() sections: Vec::new()
} }
} }
/// Change the directory to load the resource manifest file from.
/// This is also the directory used as the root when looking for
/// resources.
/// ///
/// Defaults to "".
pub fn set_resources_dir(&mut self, dir: &Path) pub fn set_resources_dir(&mut self, dir: &Path)
{ {
self.resources_dir = PathBuf::from(dir); self.resources_dir = PathBuf::from(dir);
println!("Resource dir: {}", self.resources_dir.to_str().unwrap()); println!("Resource dir: {}", self.resources_dir.to_str().unwrap());
} }
/// Change the directory to place the compiled resources into.
/// This is also the directory where the loaded manifest file will
/// be placed.
/// ///
/// Defaults to "resources".
pub fn set_output_dir(&mut self, dir: &Path) pub fn set_output_dir(&mut self, dir: &Path)
{ {
self.output_dir = PathBuf::from(dir); self.output_dir = PathBuf::from(dir);
println!("Output dir: {}", self.output_dir.to_str().unwrap()); println!("Output dir: {}", self.output_dir.to_str().unwrap());
} }
/// Sets the amount of tasks to have live to compile the resources.
/// ///
/// Each resource will be compiled on a seperate blocking thread.
pub fn set_task_count(&mut self, count: u64) pub fn set_task_count(&mut self, count: u64)
{ {
self.task_count = count; self.task_count = count;
println!("Task count: {}", self.task_count); println!("Task count: {}", self.task_count);
} }
/// /// Process the resource manifest file.
pub fn process_manifest_file(&mut self) pub fn process_manifest_file(&mut self)
{ {
// Read the manifest file from the resources directory. // Read the manifest file from the resources directory.
@ -120,7 +151,7 @@ impl Processor
self.compile_resources(); self.compile_resources();
} }
/// /// Read the manifest file.
/// ///
/// Reading the manifest file can be a blocking /// Reading the manifest file can be a blocking
/// operation since there is nothing else to do until /// operation since there is nothing else to do until
@ -207,7 +238,7 @@ impl Processor
self.read_manifest_section(&section_buffer); self.read_manifest_section(&section_buffer);
} }
/// /// Read a single manifest section from a given buffer.
fn read_manifest_section(&mut self, buffer: &Vec<String>) fn read_manifest_section(&mut self, buffer: &Vec<String>)
{ {
let mut header: &str; let mut header: &str;
@ -215,14 +246,22 @@ impl Processor
let mut section: Section; let mut section: Section;
let mut values: Vec<&str>; let mut values: Vec<&str>;
// Only do something if there are some
// lines in the buffer to process.
if buffer.len() > 0 if buffer.len() > 0
{ {
// Create a new Section and fill out its information
// by parsing the data in the buffer.
section = Section::new(); section = Section::new();
for line in buffer.iter() for line in buffer.iter()
{ {
// Split each line in the buffer by the '=' character.
// This should be parsed into 2 lines then.
values = line.split("=").collect(); values = line.split("=").collect();
if values.len() == 2 if values.len() == 2
{ {
// Get the header and value to set
// the Sections values.
header = values[0].trim(); header = values[0].trim();
value = values[1].trim(); value = values[1].trim();
if header == "name" if header == "name"
@ -252,16 +291,17 @@ impl Processor
} }
else else
{ {
warn!("Detected a name value entry that is incomplete.\n{}", warn!("Detected a name value entry that is incorrect.\n{}",
line.trim()); line.trim());
} }
} }
// Add the newly created section to the list of sections.
self.sections.push(section); self.sections.push(section);
} }
} }
/// /// Compile all the resources in the Section list.
fn compile_resources(&self) fn compile_resources(&self)
{ {
} }