about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-23 01:31:26 -0700
committerbors <bors@rust-lang.org>2013-08-23 01:31:26 -0700
commitdb55cd92dec88c3ff025ecf8b4900aca4520bea6 (patch)
tree4f5c19f1ed56124393012cf73bae99e2e2612e1d /src
parent5e5e2c71e403371ff8a5d5430e7696654214a438 (diff)
parent77df8b809a3927ffcdd2c43d48783c97a25712a8 (diff)
downloadrust-db55cd92dec88c3ff025ecf8b4900aca4520bea6.tar.gz
rust-db55cd92dec88c3ff025ecf8b4900aca4520bea6.zip
auto merge of #8681 : mrordinaire/rust/remove-set_args, r=brson
Diffstat (limited to 'src')
-rw-r--r--src/librust/rust.rs19
-rw-r--r--src/librustc/rustc.rs11
-rw-r--r--src/librustdoc/rustdoc.rs3
-rw-r--r--src/librusti/rusti.rs6
-rw-r--r--src/librustpkg/rustpkg.rs5
-rw-r--r--src/libstd/os.rs31
6 files changed, 35 insertions, 40 deletions
diff --git a/src/librust/rust.rs b/src/librust/rust.rs
index d010f7d52d8..a20e864e292 100644
--- a/src/librust/rust.rs
+++ b/src/librust/rust.rs
@@ -45,7 +45,7 @@ impl ValidUsage {
 
 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 @@ static NUM_OF_COMMANDS: uint = 7;
 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 @@ static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
     },
     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 {
diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs
index f9cbab58211..33407c91bcc 100644
--- a/src/librustc/rustc.rs
+++ b/src/librustc/rustc.rs
@@ -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 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
 
 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);
     }
 }
diff --git a/src/librustdoc/rustdoc.rs b/src/librustdoc/rustdoc.rs
index b738f4a9586..a55fa6bc3f7 100644
--- a/src/librustdoc/rustdoc.rs
+++ b/src/librustdoc/rustdoc.rs
@@ -59,7 +59,10 @@ pub mod prune_private_pass;
 
 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;
diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs
index 91b6be55d40..4e4f6e3682b 100644
--- a/src/librusti/rusti.rs
+++ b/src/librusti/rusti.rs
@@ -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 {
diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs
index 198cad90166..f5dc17851e5 100644
--- a/src/librustpkg/rustpkg.rs
+++ b/src/librustpkg/rustpkg.rs
@@ -466,8 +466,11 @@ impl CtxMethods for Ctx {
 
 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")];
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index f734a59f67f..0b5f53dbf19 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -36,7 +36,6 @@ use iterator::range;
 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 @@ mod tests {
 
     #[test]
     pub fn test_args() {
-        let a = real_args();
+        let a = args();
         assert!(a.len() >= 1);
     }