2016-04-08 19:24:46 -04:00
|
|
|
#[macro_use]
|
|
|
|
extern crate scribe;
|
|
|
|
|
|
|
|
extern crate mason;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-08 19:59:39 -04:00
|
|
|
use std::env;
|
2016-04-08 19:24:46 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use mason::Processor;
|
|
|
|
|
|
|
|
|
2016-04-14 18:40:41 -04:00
|
|
|
|
2016-04-08 19:24:46 -04:00
|
|
|
pub const RESOURCES_DIR: &'static str = "resources";
|
|
|
|
pub const MANIFEST_FILENAME: &'static str = "resources.msnr";
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-28 03:04:35 -04:00
|
|
|
fn determine_resources_dir() -> PathBuf
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
|
|
|
let mut resources_dir: PathBuf;
|
|
|
|
|
|
|
|
// Get the cargo manifest directory and then append the
|
|
|
|
// resource directory name to it.
|
2016-04-28 03:04:35 -04:00
|
|
|
match ::std::env::var_os("CARGO_MANIFEST_DIR")
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
|
|
|
Some(dir) =>
|
|
|
|
{
|
|
|
|
resources_dir = PathBuf::from(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
resources_dir = PathBuf::new();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resources_dir.push(RESOURCES_DIR);
|
|
|
|
|
2016-04-28 03:04:35 -04:00
|
|
|
resources_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
fn determine_output_dir() -> PathBuf
|
|
|
|
{
|
|
|
|
let mut next_parent: bool;
|
|
|
|
let mut output_dir: PathBuf;
|
|
|
|
|
|
|
|
match ::std::env::var_os("OUT_DIR")
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
|
|
|
Some(dir) =>
|
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
// Take the given directory and walk up until
|
|
|
|
// we are at the release or debug directory.
|
2016-04-08 19:24:46 -04:00
|
|
|
output_dir = PathBuf::from(dir);
|
2016-04-28 03:04:35 -04:00
|
|
|
|
|
|
|
next_parent = true;
|
|
|
|
while next_parent == true
|
|
|
|
{
|
|
|
|
match output_dir.file_name()
|
|
|
|
{
|
|
|
|
Some(name) =>
|
|
|
|
{
|
|
|
|
if name == "release" || name == "debug"
|
|
|
|
{
|
|
|
|
next_parent = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
next_parent = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if next_parent == true
|
|
|
|
{
|
|
|
|
output_dir.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
error!("No output directory found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
fn determine_build_file_dir() -> PathBuf
|
|
|
|
{
|
|
|
|
let build_file_dir: PathBuf;
|
|
|
|
|
|
|
|
// Get the output directory for the build.
|
|
|
|
match ::std::env::var_os("OUT_DIR")
|
|
|
|
{
|
|
|
|
Some(dir) =>
|
|
|
|
{
|
|
|
|
build_file_dir = PathBuf::from(dir);
|
2016-04-08 19:24:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
None =>
|
|
|
|
{
|
2016-04-08 19:59:39 -04:00
|
|
|
// Try to just get the current directory.
|
|
|
|
match env::current_dir()
|
|
|
|
{
|
|
|
|
Ok(dir) =>
|
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
build_file_dir = PathBuf::from(dir);
|
2016-04-08 19:59:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
// Then just default to "".
|
|
|
|
warn!("{}", error);
|
2016-04-28 03:04:35 -04:00
|
|
|
build_file_dir = PathBuf::new();
|
2016-04-08 19:59:39 -04:00
|
|
|
}
|
|
|
|
}
|
2016-04-08 19:24:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:35 -04:00
|
|
|
build_file_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
fn determine_task_count() -> u64
|
|
|
|
{
|
|
|
|
let task_count: u64;
|
|
|
|
|
2016-04-08 19:24:46 -04:00
|
|
|
// Get how many compile tasks should be run at one time.
|
2016-04-28 03:04:35 -04:00
|
|
|
match ::std::env::var_os("NUM_JOBS")
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
|
|
|
Some(count) =>
|
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
match count.into_string()
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
Ok(count_string) =>
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
match count_string.parse::<u64>()
|
|
|
|
{
|
|
|
|
Ok(val) =>
|
|
|
|
{
|
|
|
|
task_count = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
error!("{}", error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-08 19:24:46 -04:00
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:35 -04:00
|
|
|
Err(_) =>
|
2016-04-08 19:24:46 -04:00
|
|
|
{
|
2016-04-28 03:04:35 -04:00
|
|
|
error!("Unable to convert task count string from OsString.");
|
2016-04-08 19:24:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
task_count = 1u64;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:35 -04:00
|
|
|
task_count
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn main()
|
|
|
|
{
|
|
|
|
let task_count: u64;
|
|
|
|
let _build_file_dir: PathBuf;
|
|
|
|
let output_dir: PathBuf;
|
|
|
|
let resources_dir: PathBuf;
|
|
|
|
let mut processor: Processor;
|
|
|
|
|
|
|
|
_build_file_dir = determine_build_file_dir();
|
|
|
|
output_dir = determine_output_dir();
|
|
|
|
resources_dir = determine_resources_dir();
|
|
|
|
task_count = determine_task_count();
|
|
|
|
|
2016-04-08 19:24:46 -04:00
|
|
|
processor = Processor::new();
|
|
|
|
processor.set_resources_dir(resources_dir.as_path());
|
|
|
|
processor.set_output_dir(output_dir.as_path());
|
|
|
|
processor.set_task_count(task_count);
|
|
|
|
processor.process_manifest_file();
|
|
|
|
}
|