Skip to content

removed os::set_args, closing #8325 #8681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/librust/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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),
},
Expand All @@ -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"),
},
Expand Down Expand Up @@ -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)
}
Expand All @@ -177,19 +177,18 @@ 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)
}
_ => Invalid
}
}

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 {
Expand Down
11 changes: 8 additions & 3 deletions src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/librustdoc/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/librusti/rusti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/librustpkg/rustpkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")];
Expand Down
31 changes: 6 additions & 25 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -1788,7 +1769,7 @@ mod tests {

#[test]
pub fn test_args() {
let a = real_args();
let a = args();
assert!(a.len() >= 1);
}

Expand Down