0.2.13 - add env subcommand

parent 41c862cd
[package]
name = "redoxer"
version = "0.2.12"
version = "0.2.13"
description = "Method for quickly running programs inside of Redox from a KVM capable OS."
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......
use std::{env, io, process};
use std::ffi::OsString;
use std::process::Command;
use crate::{status_error, toolchain};
......@@ -9,8 +8,6 @@ fn inner() -> io::Result<()> {
let target = "x86_64-unknown-redox";
let linker = format!("{}-gcc", target);
// PATH must be set first so cargo is sourced from the toolchain path
{
let path = env::var_os("PATH").unwrap_or(OsString::new());
......@@ -43,11 +40,10 @@ fn inner() -> io::Result<()> {
},
"--" if matching => {
matching = false;
arguments.push(arg);
}
},
_ => {
arguments.push(arg);
}
},
}
}
......@@ -58,15 +54,12 @@ fn inner() -> io::Result<()> {
if gui { " --gui" } else { "" }
);
Command::new("cargo")
crate::env::command("cargo")?
.arg(subcommand)
.arg("--target").arg(target)
.args(arguments)
.env("CARGO_TARGET_X86_64_UNKNOWN_REDOX_LINKER", linker)
.env("CARGO_TARGET_X86_64_UNKNOWN_REDOX_RUNNER", runner)
.env("RUSTFLAGS", rustflags)
.env("RUSTUP_TOOLCHAIN", &toolchain_dir)
.env("TARGET", &target)
.status()
.and_then(status_error)?;
......
use std::{env, ffi, io, process};
use crate::{status_error, toolchain};
pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command> {
let toolchain_dir = toolchain()?;
// PATH must be set first so cargo is sourced from the toolchain path
{
let path = env::var_os("PATH").unwrap_or(ffi::OsString::new());
let mut paths = env::split_paths(&path).collect::<Vec<_>>();
paths.insert(0, toolchain_dir.join("bin"));
let new_path = env::join_paths(paths).map_err(|err| io::Error::new(
io::ErrorKind::Other,
err
))?;
env::set_var("PATH", new_path);
}
let target = "x86_64-unknown-redox";
let ar = format!("{}-ar", target);
let cc = format!("{}-gcc", target);
let cxx = format!("{}-g++", target);
let cc_target_var = target.replace("-", "_");
let cargo_target_var = cc_target_var.to_uppercase();
let mut command = process::Command::new(program);
command.env(format!("AR_{}", cc_target_var), &ar);
command.env(format!("CARGO_TARGET_{}_LINKER", cargo_target_var), &cc);
command.env(format!("CC_{}", cc_target_var), &cc);
command.env(format!("CXX_{}", cc_target_var), &cxx);
command.env("RUSTUP_TOOLCHAIN", &toolchain_dir);
command.env("TARGET", &target);
Ok(command)
}
fn inner() -> io::Result<()> {
let mut program_opt = None;
let mut arguments = Vec::new();
for arg in env::args().skip(2) {
if program_opt.is_none() {
program_opt = Some(arg);
} else {
arguments.push(arg);
}
}
//TODO: get user's default shell?
let program = program_opt.unwrap_or("bash".to_string());
command(program)?
.args(arguments)
.status()
.and_then(status_error)?;
Ok(())
}
pub fn main() {
match inner() {
Ok(()) => {
process::exit(0);
},
Err(err) => {
eprintln!("redoxer install: {}", err);
process::exit(1);
}
}
}
use std::{env, io, path, process};
use std::{env::args, io, path, process};
pub (crate) use self::toolchain::toolchain;
mod cargo;
mod env;
mod exec;
mod install;
mod redoxfs;
......@@ -53,6 +54,7 @@ fn usage() {
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 env - execute a command in cross-compilation environment");
eprintln!("redoxer exec - execute a command in Redox VM");
eprintln!("redoxer install - install toolchain");
eprintln!("redoxer run - cargo run with Redox target in Redox VM");
......@@ -62,7 +64,7 @@ fn usage() {
}
fn main() {
match env::args().nth(1) {
match args().nth(1) {
Some(arg) => match arg.as_str() {
"bench" |
"build" |
......@@ -71,6 +73,7 @@ fn main() {
"run" |
"rustc" |
"test" => cargo::main(),
"env" => env::main(),
"exec" => exec::main(),
"install" => install::main(),
_ => usage(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment