main.rs 2.11 KB
Newer Older
1
use std::{env, io, path, process};
Jeremy Soller's avatar
Jeremy Soller committed
2

3
pub (crate) use self::toolchain::toolchain;
Jeremy Soller's avatar
Jeremy Soller committed
4

5 6 7 8 9
mod cargo;
mod exec;
mod install;
mod redoxfs;
mod toolchain;
Jeremy Soller's avatar
Jeremy Soller committed
10 11 12 13

//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn installed(program: &str) -> io::Result<bool> {
14
    process::Command::new("which")
Jeremy Soller's avatar
Jeremy Soller committed
15
        .arg(program)
16
        .stdout(process::Stdio::null())
Jeremy Soller's avatar
Jeremy Soller committed
17 18 19 20
        .status()
        .map(|x| x.success())
}

21 22 23 24 25
fn redoxer_dir() -> path::PathBuf {
    dirs::home_dir().unwrap_or(path::PathBuf::from("."))
        .join(".redoxer")
}

Jeremy Soller's avatar
Jeremy Soller committed
26 27 28
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn running(program: &str) -> io::Result<bool> {
29
    process::Command::new("pgrep")
Jeremy Soller's avatar
Jeremy Soller committed
30
        .arg(program)
31
        .stdout(process::Stdio::null())
Jeremy Soller's avatar
Jeremy Soller committed
32 33 34 35
        .status()
        .map(|x| x.success())
}

36 37 38 39 40
fn status_error(status: process::ExitStatus) -> io::Result<()> {
    if status.success() {
        Ok(())
    } else {
        Err(io::Error::new(
41
            io::ErrorKind::Other,
42 43
            format!("{}", status)
        ))
Jeremy Soller's avatar
Jeremy Soller committed
44 45 46
    }
}

47 48 49 50
fn syscall_error(err: syscall::Error) -> io::Error {
    io::Error::from_raw_os_error(err.errno)
}

51
fn usage() {
Jeremy Soller's avatar
Jeremy Soller committed
52 53 54 55 56
    eprintln!("redoxer bench - cargo bench with Redox target in Redox VM");
    eprintln!("redoxer build - cargo build with Redox target");
    eprintln!("redoxer check - cargo check with Redox target");
    eprintln!("redoxer doc - cargo doc with Redox target");
    eprintln!("redoxer exec - execute a command in Redox VM");
57
    eprintln!("redoxer install - install toolchain");
Jeremy Soller's avatar
Jeremy Soller committed
58 59 60
    eprintln!("redoxer run - cargo run with Redox target in Redox VM");
    eprintln!("redoxer rustc - cargo rustc with Redox target");
    eprintln!("redoxer test - cargo test with Redox target in Redox VM");
61 62 63
    process::exit(1);
}

Jeremy Soller's avatar
Jeremy Soller committed
64
fn main() {
65 66
    match env::args().nth(1) {
        Some(arg) => match arg.as_str() {
Jeremy Soller's avatar
Jeremy Soller committed
67 68 69 70 71 72 73
            "bench" |
            "build" |
            "check" |
            "doc" |
            "run" |
            "rustc" |
            "test" => cargo::main(),
74 75 76
            "exec" => exec::main(),
            "install" => install::main(),
            _ => usage(),
77
        },
78
        None => usage(),
Jeremy Soller's avatar
Jeremy Soller committed
79 80
    }
}