auto merge of #8681 : mrordinaire/rust/remove-set_args, r=brson
This commit is contained in:
@@ -45,7 +45,7 @@ impl ValidUsage {
|
|||||||
|
|
||||||
enum Action {
|
enum Action {
|
||||||
Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
|
Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
|
||||||
CallMain(&'static str, extern "Rust" fn()),
|
CallMain(&'static str, extern "Rust" fn(&[~str])),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UsageSource<'self> {
|
enum UsageSource<'self> {
|
||||||
@@ -69,7 +69,7 @@ static NUM_OF_COMMANDS: uint = 7;
|
|||||||
static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
|
static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
|
||||||
Command{
|
Command{
|
||||||
cmd: "build",
|
cmd: "build",
|
||||||
action: CallMain("rustc", rustc::main),
|
action: CallMain("rustc", rustc::main_args),
|
||||||
usage_line: "compile rust source files",
|
usage_line: "compile rust source files",
|
||||||
usage_full: UsgCall(rustc_help),
|
usage_full: UsgCall(rustc_help),
|
||||||
},
|
},
|
||||||
@@ -95,19 +95,19 @@ static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
|
|||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
cmd: "doc",
|
cmd: "doc",
|
||||||
action: CallMain("rustdoc", rustdoc::main),
|
action: CallMain("rustdoc", rustdoc::main_args),
|
||||||
usage_line: "generate documentation from doc comments",
|
usage_line: "generate documentation from doc comments",
|
||||||
usage_full: UsgCall(rustdoc::config::usage),
|
usage_full: UsgCall(rustdoc::config::usage),
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
cmd: "pkg",
|
cmd: "pkg",
|
||||||
action: CallMain("rustpkg", rustpkg::main),
|
action: CallMain("rustpkg", rustpkg::main_args),
|
||||||
usage_line: "download, build, install rust packages",
|
usage_line: "download, build, install rust packages",
|
||||||
usage_full: UsgCall(rustpkg::usage::general),
|
usage_full: UsgCall(rustpkg::usage::general),
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
cmd: "sketch",
|
cmd: "sketch",
|
||||||
action: CallMain("rusti", rusti::main),
|
action: CallMain("rusti", rusti::main_args),
|
||||||
usage_line: "run a rust interpreter",
|
usage_line: "run a rust interpreter",
|
||||||
usage_full: UsgStr("\nUsage:\trusti"),
|
usage_full: UsgStr("\nUsage:\trusti"),
|
||||||
},
|
},
|
||||||
@@ -164,7 +164,7 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
|
|||||||
[ref filename] => {
|
[ref filename] => {
|
||||||
let test_exec = Path(*filename).filestem().unwrap() + "test~";
|
let test_exec = Path(*filename).filestem().unwrap() + "test~";
|
||||||
invoke("rustc", &[~"--test", filename.to_owned(),
|
invoke("rustc", &[~"--test", filename.to_owned(),
|
||||||
~"-o", test_exec.to_owned()], rustc::main);
|
~"-o", test_exec.to_owned()], rustc::main_args);
|
||||||
let exit_code = run::process_status(~"./" + test_exec, []);
|
let exit_code = run::process_status(~"./" + test_exec, []);
|
||||||
Valid(exit_code)
|
Valid(exit_code)
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
|
|||||||
[ref filename, ..prog_args] => {
|
[ref filename, ..prog_args] => {
|
||||||
let exec = Path(*filename).filestem().unwrap() + "~";
|
let exec = Path(*filename).filestem().unwrap() + "~";
|
||||||
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
|
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
|
||||||
rustc::main);
|
rustc::main_args);
|
||||||
let exit_code = run::process_status(~"./"+exec, prog_args);
|
let exit_code = run::process_status(~"./"+exec, prog_args);
|
||||||
Valid(exit_code)
|
Valid(exit_code)
|
||||||
}
|
}
|
||||||
@@ -185,11 +185,10 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invoke(prog: &str, args: &[~str], f: &fn()) {
|
fn invoke(prog: &str, args: &[~str], f: &fn(&[~str])) {
|
||||||
let mut osargs = ~[prog.to_owned()];
|
let mut osargs = ~[prog.to_owned()];
|
||||||
osargs.push_all_move(args.to_owned());
|
osargs.push_all_move(args.to_owned());
|
||||||
os::set_args(osargs);
|
f(osargs);
|
||||||
f();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
|
fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
|
||||||
|
|||||||
@@ -191,11 +191,11 @@ pub fn describe_debug_flags() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
|
pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
|
||||||
// Don't display log spew by default. Can override with RUST_LOG.
|
// Don't display log spew by default. Can override with RUST_LOG.
|
||||||
::std::logging::console_off();
|
::std::logging::console_off();
|
||||||
|
|
||||||
let mut args = (*args).clone();
|
let mut args = args.to_owned();
|
||||||
let binary = args.shift().to_managed();
|
let binary = args.shift().to_managed();
|
||||||
|
|
||||||
if args.is_empty() { usage(binary); return; }
|
if args.is_empty() { usage(binary); return; }
|
||||||
@@ -381,7 +381,12 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
|
main_args(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_args(args: &[~str]) {
|
||||||
|
let owned_args = args.to_owned();
|
||||||
do monitor |demitter| {
|
do monitor |demitter| {
|
||||||
run_compiler(&args, demitter);
|
run_compiler(owned_args, demitter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,10 @@ pub mod prune_private_pass;
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
|
main_args(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_args(args: &[~str]) {
|
||||||
if args.iter().any(|x| "-h" == *x) || args.iter().any(|x| "--help" == *x) {
|
if args.iter().any(|x| "-h" == *x) || args.iter().any(|x| "--help" == *x) {
|
||||||
config::usage();
|
config::usage();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -498,9 +498,13 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
let args = os::args();
|
||||||
|
main_args(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_args(args: &[~str]) {
|
||||||
#[fixed_stack_segment]; #[inline(never)];
|
#[fixed_stack_segment]; #[inline(never)];
|
||||||
|
|
||||||
let args = os::args();
|
|
||||||
let input = io::stdin();
|
let input = io::stdin();
|
||||||
let out = io::stdout();
|
let out = io::stdout();
|
||||||
let mut repl = Repl {
|
let mut repl = Repl {
|
||||||
|
|||||||
@@ -466,8 +466,11 @@ impl CtxMethods for Ctx {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
io::println("WARNING: The Rust package manager is experimental and may be unstable");
|
io::println("WARNING: The Rust package manager is experimental and may be unstable");
|
||||||
|
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
|
main_args(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_args(args: &[~str]) {
|
||||||
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
|
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
|
||||||
getopts::optflag("j"), getopts::optflag("json"),
|
getopts::optflag("j"), getopts::optflag("json"),
|
||||||
getopts::optmulti("c"), getopts::optmulti("cfg")];
|
getopts::optmulti("c"), getopts::optmulti("cfg")];
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ use iterator::range;
|
|||||||
use libc;
|
use libc;
|
||||||
use libc::{c_char, c_void, c_int, size_t};
|
use libc::{c_char, c_void, c_int, size_t};
|
||||||
use libc::FILE;
|
use libc::FILE;
|
||||||
use local_data;
|
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
use os;
|
use os;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
@@ -1188,7 +1187,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
|
|||||||
* Returns a list of the command line arguments.
|
* Returns a list of the command line arguments.
|
||||||
*/
|
*/
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn real_args() -> ~[~str] {
|
fn real_args() -> ~[~str] {
|
||||||
#[fixed_stack_segment]; #[inline(never)];
|
#[fixed_stack_segment]; #[inline(never)];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -1201,7 +1200,7 @@ pub fn real_args() -> ~[~str] {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
pub fn real_args() -> ~[~str] {
|
fn real_args() -> ~[~str] {
|
||||||
use rt;
|
use rt;
|
||||||
|
|
||||||
match rt::args::clone() {
|
match rt::args::clone() {
|
||||||
@@ -1211,7 +1210,7 @@ pub fn real_args() -> ~[~str] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn real_args() -> ~[~str] {
|
fn real_args() -> ~[~str] {
|
||||||
#[fixed_stack_segment]; #[inline(never)];
|
#[fixed_stack_segment]; #[inline(never)];
|
||||||
|
|
||||||
let mut nArgs: c_int = 0;
|
let mut nArgs: c_int = 0;
|
||||||
@@ -1261,28 +1260,10 @@ struct OverriddenArgs {
|
|||||||
val: ~[~str]
|
val: ~[~str]
|
||||||
}
|
}
|
||||||
|
|
||||||
static overridden_arg_key: local_data::Key<@OverriddenArgs> = &local_data::Key;
|
|
||||||
|
|
||||||
/// Returns the arguments which this program was started with (normally passed
|
/// Returns the arguments which this program was started with (normally passed
|
||||||
/// via the command line).
|
/// via the command line).
|
||||||
///
|
|
||||||
/// The return value of the function can be changed by invoking the
|
|
||||||
/// `os::set_args` function.
|
|
||||||
pub fn args() -> ~[~str] {
|
pub fn args() -> ~[~str] {
|
||||||
match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
|
real_args()
|
||||||
None => real_args(),
|
|
||||||
Some(args) => args.val.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// For the current task, overrides the task-local cache of the arguments this
|
|
||||||
/// program had when it started. These new arguments are only available to the
|
|
||||||
/// current task via the `os::args` method.
|
|
||||||
pub fn set_args(new_args: ~[~str]) {
|
|
||||||
let overridden_args = @OverriddenArgs {
|
|
||||||
val: new_args.clone()
|
|
||||||
};
|
|
||||||
local_data::set(overridden_arg_key, overridden_args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME #6100 we should really use an internal implementation of this - using
|
// FIXME #6100 we should really use an internal implementation of this - using
|
||||||
@@ -1770,7 +1751,7 @@ mod tests {
|
|||||||
use libc;
|
use libc;
|
||||||
use option::Some;
|
use option::Some;
|
||||||
use option;
|
use option;
|
||||||
use os::{env, getcwd, getenv, make_absolute, real_args};
|
use os::{env, getcwd, getenv, make_absolute, args};
|
||||||
use os::{remove_file, setenv, unsetenv};
|
use os::{remove_file, setenv, unsetenv};
|
||||||
use os;
|
use os;
|
||||||
use path::Path;
|
use path::Path;
|
||||||
@@ -1788,7 +1769,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_args() {
|
pub fn test_args() {
|
||||||
let a = real_args();
|
let a = args();
|
||||||
assert!(a.len() >= 1);
|
assert!(a.len() >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user