A fancy new build script example.
This uses the correct method of getting the environment variables and now correctly find the output directory. It needs more comments though.
This commit is contained in:
parent
3a9802d301
commit
d500c86d68
@ -17,16 +17,13 @@ pub const MANIFEST_FILENAME: &'static str = "resources.msnr";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn main()
|
fn determine_resources_dir() -> PathBuf
|
||||||
{
|
{
|
||||||
let task_count: u64;
|
|
||||||
let output_dir: PathBuf;
|
|
||||||
let mut resources_dir: PathBuf;
|
let mut resources_dir: PathBuf;
|
||||||
let mut processor: Processor;
|
|
||||||
|
|
||||||
// Get the cargo manifest directory and then append the
|
// Get the cargo manifest directory and then append the
|
||||||
// resource directory name to it.
|
// resource directory name to it.
|
||||||
match option_env!("CARGO_MANIFEST_DIR")
|
match ::std::env::var_os("CARGO_MANIFEST_DIR")
|
||||||
{
|
{
|
||||||
Some(dir) =>
|
Some(dir) =>
|
||||||
{
|
{
|
||||||
@ -40,12 +37,67 @@ pub fn main()
|
|||||||
}
|
}
|
||||||
resources_dir.push(RESOURCES_DIR);
|
resources_dir.push(RESOURCES_DIR);
|
||||||
|
|
||||||
// Get the output directory for the build.
|
resources_dir
|
||||||
match option_env!("OUT_DIR")
|
}
|
||||||
|
|
||||||
|
fn determine_output_dir() -> PathBuf
|
||||||
|
{
|
||||||
|
let mut next_parent: bool;
|
||||||
|
let mut output_dir: PathBuf;
|
||||||
|
|
||||||
|
match ::std::env::var_os("OUT_DIR")
|
||||||
{
|
{
|
||||||
Some(dir) =>
|
Some(dir) =>
|
||||||
{
|
{
|
||||||
|
// Take the given directory and walk up until
|
||||||
|
// we are at the release or debug directory.
|
||||||
output_dir = PathBuf::from(dir);
|
output_dir = PathBuf::from(dir);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
None =>
|
None =>
|
||||||
@ -55,34 +107,52 @@ pub fn main()
|
|||||||
{
|
{
|
||||||
Ok(dir) =>
|
Ok(dir) =>
|
||||||
{
|
{
|
||||||
output_dir = PathBuf::from(dir);
|
build_file_dir = PathBuf::from(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(error) =>
|
Err(error) =>
|
||||||
{
|
{
|
||||||
// Then just default to "".
|
// Then just default to "".
|
||||||
warn!("{}", error);
|
warn!("{}", error);
|
||||||
output_dir = PathBuf::new();
|
build_file_dir = PathBuf::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_file_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
fn determine_task_count() -> u64
|
||||||
|
{
|
||||||
|
let task_count: u64;
|
||||||
|
|
||||||
// Get how many compile tasks should be run at one time.
|
// Get how many compile tasks should be run at one time.
|
||||||
match option_env!("NUM_JOBS")
|
match ::std::env::var_os("NUM_JOBS")
|
||||||
{
|
{
|
||||||
Some(count) =>
|
Some(count) =>
|
||||||
{
|
{
|
||||||
match count.parse::<u64>()
|
match count.into_string()
|
||||||
{
|
{
|
||||||
Ok(val) =>
|
Ok(count_string) =>
|
||||||
{
|
{
|
||||||
task_count = val;
|
match count_string.parse::<u64>()
|
||||||
|
{
|
||||||
|
Ok(val) =>
|
||||||
|
{
|
||||||
|
task_count = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(error) =>
|
||||||
|
{
|
||||||
|
error!("{}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(error) =>
|
Err(_) =>
|
||||||
{
|
{
|
||||||
error!("{}", error);
|
error!("Unable to convert task count string from OsString.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +163,23 @@ pub fn main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
processor = Processor::new();
|
processor = Processor::new();
|
||||||
processor.set_resources_dir(resources_dir.as_path());
|
processor.set_resources_dir(resources_dir.as_path());
|
||||||
processor.set_output_dir(output_dir.as_path());
|
processor.set_output_dir(output_dir.as_path());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user