use config;
use failure::{err_msg, Error};
use std::env;
use std::process::{self, Command};
pub fn build(config: &config::Root, release: bool) -> Result<(), Error> {
let mut command = Command::new("xargo");
command.arg("build");
if release {
command.arg("--release");
}
command.arg("--target").arg(&config.target);
let status = command.spawn()?.wait()?;
if !status.success() {
process::exit(status.code().unwrap_or(1));
}
Ok(())
}
pub fn binary_path(
config: &config::Root,
release: bool,
) -> Result<String, Error> {
Ok(format!(
"target/{}/{}/{}",
config.target,
if release { "release" } else { "debug" },
crate_name()?,
))
}
pub fn crate_name() -> Result<String, Error> {
Ok(
env::current_dir()?
.file_name()
.ok_or_else(|| err_msg("Current directory is invalid"))?
.to_str()
.ok_or_else(|| err_msg("Current directory path is not valid UTF-8"))?
.to_string(),
)
}