1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::env;
use std::ffi;
use std::process;
use std::str;
use build::CargoBuild;
pub const CURRENT_TARGET: &str = include_str!(concat!(env!("OUT_DIR"), "/current_target.txt"));
lazy_static! {
static ref CARBO_BIN: ffi::OsString = 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()
}
}