提交 77df8b80 编写于 作者: D Do Nhat Minh

removed os::set_args, closing #8325

removed pub on real_args, changed test to use args
上级 f8584523
......@@ -45,7 +45,7 @@ fn is_valid(&self) -> bool {
enum Action {
Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
CallMain(&'static str, extern "Rust" fn()),
CallMain(&'static str, extern "Rust" fn(&[~str])),
}
enum UsageSource<'self> {
......@@ -69,7 +69,7 @@ struct Command<'self> {
static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
Command{
cmd: "build",
action: CallMain("rustc", rustc::main),
action: CallMain("rustc", rustc::main_args),
usage_line: "compile rust source files",
usage_full: UsgCall(rustc_help),
},
......@@ -95,19 +95,19 @@ struct Command<'self> {
},
Command{
cmd: "doc",
action: CallMain("rustdoc", rustdoc::main),
action: CallMain("rustdoc", rustdoc::main_args),
usage_line: "generate documentation from doc comments",
usage_full: UsgCall(rustdoc::config::usage),
},
Command{
cmd: "pkg",
action: CallMain("rustpkg", rustpkg::main),
action: CallMain("rustpkg", rustpkg::main_args),
usage_line: "download, build, install rust packages",
usage_full: UsgCall(rustpkg::usage::general),
},
Command{
cmd: "sketch",
action: CallMain("rusti", rusti::main),
action: CallMain("rusti", rusti::main_args),
usage_line: "run a rust interpreter",
usage_full: UsgStr("\nUsage:\trusti"),
},
......@@ -164,7 +164,7 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
[ref filename] => {
let test_exec = Path(*filename).filestem().unwrap() + "test~";
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, []);
Valid(exit_code)
}
......@@ -177,7 +177,7 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
[ref filename, ..prog_args] => {
let exec = Path(*filename).filestem().unwrap() + "~";
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
rustc::main);
rustc::main_args);
let exit_code = run::process_status(~"./"+exec, prog_args);
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()];
osargs.push_all_move(args.to_owned());
os::set_args(osargs);
f();
f(osargs);
}
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.
::std::logging::console_off();
let mut args = (*args).clone();
let mut args = args.to_owned();
let binary = args.shift().to_managed();
if args.is_empty() { usage(binary); return; }
......@@ -381,7 +381,12 @@ impl Drop for finally {
pub fn main() {
let args = os::args();
main_args(args);
}
pub fn main_args(args: &[~str]) {
let owned_args = args.to_owned();
do monitor |demitter| {
run_compiler(&args, demitter);
run_compiler(owned_args, demitter);
}
}
......@@ -59,7 +59,10 @@
pub fn main() {
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) {
config::usage();
return;
......
......@@ -498,9 +498,13 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st
}
pub fn main() {
let args = os::args();
main_args(args);
}
pub fn main_args(args: &[~str]) {
#[fixed_stack_segment]; #[inline(never)];
let args = os::args();
let input = io::stdin();
let out = io::stdout();
let mut repl = Repl {
......
......@@ -466,8 +466,11 @@ fn unprefer(&self, _id: &str, _vers: Option<~str>) {
pub fn main() {
io::println("WARNING: The Rust package manager is experimental and may be unstable");
let args = os::args();
main_args(args);
}
pub fn main_args(args: &[~str]) {
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
getopts::optflag("j"), getopts::optflag("json"),
getopts::optmulti("c"), getopts::optmulti("cfg")];
......
......@@ -36,7 +36,6 @@
use libc;
use libc::{c_char, c_void, c_int, size_t};
use libc::FILE;
use local_data;
use option::{Some, None};
use os;
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.
*/
#[cfg(target_os = "macos")]
pub fn real_args() -> ~[~str] {
fn real_args() -> ~[~str] {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
......@@ -1201,7 +1200,7 @@ pub fn real_args() -> ~[~str] {
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
pub fn real_args() -> ~[~str] {
fn real_args() -> ~[~str] {
use rt;
match rt::args::clone() {
......@@ -1211,7 +1210,7 @@ pub fn real_args() -> ~[~str] {
}
#[cfg(windows)]
pub fn real_args() -> ~[~str] {
fn real_args() -> ~[~str] {
#[fixed_stack_segment]; #[inline(never)];
let mut nArgs: c_int = 0;
......@@ -1261,28 +1260,10 @@ struct OverriddenArgs {
val: ~[~str]
}
static overridden_arg_key: local_data::Key<@OverriddenArgs> = &local_data::Key;
/// Returns the arguments which this program was started with (normally passed
/// via the command line).
///
/// The return value of the function can be changed by invoking the
/// `os::set_args` function.
pub fn args() -> ~[~str] {
match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
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);
real_args()
}
// FIXME #6100 we should really use an internal implementation of this - using
......@@ -1770,7 +1751,7 @@ mod tests {
use libc;
use option::Some;
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;
use path::Path;
......@@ -1788,7 +1769,7 @@ pub fn last_os_error() {
#[test]
pub fn test_args() {
let a = real_args();
let a = args();
assert!(a.len() >= 1);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册