use std::env;
use std::ffi;
use std::process;
use std::str;
use crate::build::CargoBuild;
pub const CURRENT_TARGET: &str = include_str!(concat!(env!("OUT_DIR"), "/current_target.txt"));
static CARBO_BIN: once_cell::sync::Lazy<ffi::OsString> =
once_cell::sync::Lazy::new(|| env::var_os("CARGO").unwrap_or_else(|| "cargo".into()));
#[derive(Debug)]
pub struct Cargo {
cmd: process::Command,
}
impl Cargo {
pub fn new() -> Self {
Self {
cmd: process::Command::new(CARBO_BIN.as_os_str()),
}
}
pub fn arg<S: AsRef<ffi::OsStr>>(mut self, arg: S) -> Self {
self.cmd.arg(arg);
self
}
pub fn build(self) -> CargoBuild {
self.build_with("build")
}
pub fn build_with<S: AsRef<ffi::OsStr>>(mut self, name: S) -> CargoBuild {
self.cmd.arg(name).arg("--message-format=json");
CargoBuild::with_command(self.cmd)
}
}
impl Default for Cargo {
fn default() -> Self {
Self::new()
}
}