Skip to content

Commit db55cd9

Browse files
committed
auto merge of #8681 : mrordinaire/rust/remove-set_args, r=brson
2 parents 5e5e2c7 + 77df8b8 commit db55cd9

File tree

6 files changed

+35
-40
lines changed

6 files changed

+35
-40
lines changed

src/librust/rust.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl ValidUsage {
4545

4646
enum Action {
4747
Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
48-
CallMain(&'static str, extern "Rust" fn()),
48+
CallMain(&'static str, extern "Rust" fn(&[~str])),
4949
}
5050

5151
enum UsageSource<'self> {
@@ -69,7 +69,7 @@ static NUM_OF_COMMANDS: uint = 7;
6969
static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
7070
Command{
7171
cmd: "build",
72-
action: CallMain("rustc", rustc::main),
72+
action: CallMain("rustc", rustc::main_args),
7373
usage_line: "compile rust source files",
7474
usage_full: UsgCall(rustc_help),
7575
},
@@ -95,19 +95,19 @@ static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
9595
},
9696
Command{
9797
cmd: "doc",
98-
action: CallMain("rustdoc", rustdoc::main),
98+
action: CallMain("rustdoc", rustdoc::main_args),
9999
usage_line: "generate documentation from doc comments",
100100
usage_full: UsgCall(rustdoc::config::usage),
101101
},
102102
Command{
103103
cmd: "pkg",
104-
action: CallMain("rustpkg", rustpkg::main),
104+
action: CallMain("rustpkg", rustpkg::main_args),
105105
usage_line: "download, build, install rust packages",
106106
usage_full: UsgCall(rustpkg::usage::general),
107107
},
108108
Command{
109109
cmd: "sketch",
110-
action: CallMain("rusti", rusti::main),
110+
action: CallMain("rusti", rusti::main_args),
111111
usage_line: "run a rust interpreter",
112112
usage_full: UsgStr("\nUsage:\trusti"),
113113
},
@@ -164,7 +164,7 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
164164
[ref filename] => {
165165
let test_exec = Path(*filename).filestem().unwrap() + "test~";
166166
invoke("rustc", &[~"--test", filename.to_owned(),
167-
~"-o", test_exec.to_owned()], rustc::main);
167+
~"-o", test_exec.to_owned()], rustc::main_args);
168168
let exit_code = run::process_status(~"./" + test_exec, []);
169169
Valid(exit_code)
170170
}
@@ -177,19 +177,18 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
177177
[ref filename, ..prog_args] => {
178178
let exec = Path(*filename).filestem().unwrap() + "~";
179179
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
180-
rustc::main);
180+
rustc::main_args);
181181
let exit_code = run::process_status(~"./"+exec, prog_args);
182182
Valid(exit_code)
183183
}
184184
_ => Invalid
185185
}
186186
}
187187

188-
fn invoke(prog: &str, args: &[~str], f: &fn()) {
188+
fn invoke(prog: &str, args: &[~str], f: &fn(&[~str])) {
189189
let mut osargs = ~[prog.to_owned()];
190190
osargs.push_all_move(args.to_owned());
191-
os::set_args(osargs);
192-
f();
191+
f(osargs);
193192
}
194193

195194
fn do_command(command: &Command, args: &[~str]) -> ValidUsage {

src/librustc/rustc.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ pub fn describe_debug_flags() {
191191
}
192192
}
193193

194-
pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
194+
pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
195195
// Don't display log spew by default. Can override with RUST_LOG.
196196
::std::logging::console_off();
197197

198-
let mut args = (*args).clone();
198+
let mut args = args.to_owned();
199199
let binary = args.shift().to_managed();
200200

201201
if args.is_empty() { usage(binary); return; }
@@ -381,7 +381,12 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
381381

382382
pub fn main() {
383383
let args = os::args();
384+
main_args(args);
385+
}
386+
387+
pub fn main_args(args: &[~str]) {
388+
let owned_args = args.to_owned();
384389
do monitor |demitter| {
385-
run_compiler(&args, demitter);
390+
run_compiler(owned_args, demitter);
386391
}
387392
}

src/librustdoc/rustdoc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ pub mod prune_private_pass;
5959

6060
pub fn main() {
6161
let args = os::args();
62+
main_args(args);
63+
}
6264

65+
pub fn main_args(args: &[~str]) {
6366
if args.iter().any(|x| "-h" == *x) || args.iter().any(|x| "--help" == *x) {
6467
config::usage();
6568
return;

src/librusti/rusti.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,13 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st
498498
}
499499

500500
pub fn main() {
501+
let args = os::args();
502+
main_args(args);
503+
}
504+
505+
pub fn main_args(args: &[~str]) {
501506
#[fixed_stack_segment]; #[inline(never)];
502507

503-
let args = os::args();
504508
let input = io::stdin();
505509
let out = io::stdout();
506510
let mut repl = Repl {

src/librustpkg/rustpkg.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,11 @@ impl CtxMethods for Ctx {
466466

467467
pub fn main() {
468468
io::println("WARNING: The Rust package manager is experimental and may be unstable");
469-
470469
let args = os::args();
470+
main_args(args);
471+
}
472+
473+
pub fn main_args(args: &[~str]) {
471474
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
472475
getopts::optflag("j"), getopts::optflag("json"),
473476
getopts::optmulti("c"), getopts::optmulti("cfg")];

src/libstd/os.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use iterator::range;
3636
use libc;
3737
use libc::{c_char, c_void, c_int, size_t};
3838
use libc::FILE;
39-
use local_data;
4039
use option::{Some, None};
4140
use os;
4241
use prelude::*;
@@ -1188,7 +1187,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
11881187
* Returns a list of the command line arguments.
11891188
*/
11901189
#[cfg(target_os = "macos")]
1191-
pub fn real_args() -> ~[~str] {
1190+
fn real_args() -> ~[~str] {
11921191
#[fixed_stack_segment]; #[inline(never)];
11931192

11941193
unsafe {
@@ -1201,7 +1200,7 @@ pub fn real_args() -> ~[~str] {
12011200
#[cfg(target_os = "linux")]
12021201
#[cfg(target_os = "android")]
12031202
#[cfg(target_os = "freebsd")]
1204-
pub fn real_args() -> ~[~str] {
1203+
fn real_args() -> ~[~str] {
12051204
use rt;
12061205

12071206
match rt::args::clone() {
@@ -1211,7 +1210,7 @@ pub fn real_args() -> ~[~str] {
12111210
}
12121211

12131212
#[cfg(windows)]
1214-
pub fn real_args() -> ~[~str] {
1213+
fn real_args() -> ~[~str] {
12151214
#[fixed_stack_segment]; #[inline(never)];
12161215

12171216
let mut nArgs: c_int = 0;
@@ -1261,28 +1260,10 @@ struct OverriddenArgs {
12611260
val: ~[~str]
12621261
}
12631262

1264-
static overridden_arg_key: local_data::Key<@OverriddenArgs> = &local_data::Key;
1265-
12661263
/// Returns the arguments which this program was started with (normally passed
12671264
/// via the command line).
1268-
///
1269-
/// The return value of the function can be changed by invoking the
1270-
/// `os::set_args` function.
12711265
pub fn args() -> ~[~str] {
1272-
match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
1273-
None => real_args(),
1274-
Some(args) => args.val.clone()
1275-
}
1276-
}
1277-
1278-
/// For the current task, overrides the task-local cache of the arguments this
1279-
/// program had when it started. These new arguments are only available to the
1280-
/// current task via the `os::args` method.
1281-
pub fn set_args(new_args: ~[~str]) {
1282-
let overridden_args = @OverriddenArgs {
1283-
val: new_args.clone()
1284-
};
1285-
local_data::set(overridden_arg_key, overridden_args);
1266+
real_args()
12861267
}
12871268

12881269
// FIXME #6100 we should really use an internal implementation of this - using
@@ -1770,7 +1751,7 @@ mod tests {
17701751
use libc;
17711752
use option::Some;
17721753
use option;
1773-
use os::{env, getcwd, getenv, make_absolute, real_args};
1754+
use os::{env, getcwd, getenv, make_absolute, args};
17741755
use os::{remove_file, setenv, unsetenv};
17751756
use os;
17761757
use path::Path;
@@ -1788,7 +1769,7 @@ mod tests {
17881769
17891770
#[test]
17901771
pub fn test_args() {
1791-
let a = real_args();
1772+
let a = args();
17921773
assert!(a.len() >= 1);
17931774
}
17941775

0 commit comments

Comments
 (0)