libgetopts: Remove all uses of ~str from libgetopts

This commit is contained in:
Patrick Walton 2014-05-14 21:39:11 -07:00
parent 28bcef85e4
commit 1fb08f11b7
8 changed files with 275 additions and 248 deletions

View File

@ -101,11 +101,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
} }
let matches = let matches =
&match getopts::getopts(args_.iter() &match getopts::getopts(args_.as_slice(), groups.as_slice()) {
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
groups.as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg()) Err(f) => fail!("{}", f.to_err_msg())
}; };
@ -146,7 +142,9 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
build_base: opt_path(matches, "build-base"), build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"), aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(), stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"), mode: FromStr::from_str(matches.opt_str("mode")
.unwrap()
.as_slice()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"), run_ignored: matches.opt_present("ignored"),
filter: filter, filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)), logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
@ -154,7 +152,8 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
ratchet_metrics: ratchet_metrics:
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)), matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
ratchet_noise_percent: ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)), matches.opt_str("ratchet-noise-percent")
.and_then(|s| from_str::<f64>(s.as_slice())),
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()), runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
host_rustcflags: matches.opt_str("host-rustcflags") host_rustcflags: matches.opt_str("host-rustcflags")
.map(|x| x.to_strbuf()), .map(|x| x.to_strbuf()),

File diff suppressed because it is too large Load Diff

View File

@ -319,7 +319,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
{ {
let mut cg = basic_codegen_options(); let mut cg = basic_codegen_options();
for option in matches.opt_strs("C").move_iter() { for option in matches.opt_strs("C").move_iter() {
let mut iter = option.splitn('=', 1); let mut iter = option.as_slice().splitn('=', 1);
let key = iter.next().unwrap(); let key = iter.next().unwrap();
let value = iter.next(); let value = iter.next();
let option_to_lookup = key.replace("-", "_"); let option_to_lookup = key.replace("-", "_");
@ -563,7 +563,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut crate_types: Vec<CrateType> = Vec::new(); let mut crate_types: Vec<CrateType> = Vec::new();
let unparsed_crate_types = matches.opt_strs("crate-type"); let unparsed_crate_types = matches.opt_strs("crate-type");
for unparsed_crate_type in unparsed_crate_types.iter() { for unparsed_crate_type in unparsed_crate_types.iter() {
for part in unparsed_crate_type.split(',') { for part in unparsed_crate_type.as_slice().split(',') {
let new_part = match part { let new_part = match part {
"lib" => default_lib_output(), "lib" => default_lib_output(),
"rlib" => CrateTypeRlib, "rlib" => CrateTypeRlib,
@ -612,7 +612,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut this_bit = 0; let mut this_bit = 0;
for tuple in debug_map.iter() { for tuple in debug_map.iter() {
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) }; let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
if *name == *debug_flag { this_bit = bit; break; } if *name == debug_flag.as_slice() {
this_bit = bit;
break;
}
} }
if this_bit == 0 { if this_bit == 0 {
early_error(format!("unknown debug flag: {}", *debug_flag)) early_error(format!("unknown debug flag: {}", *debug_flag))
@ -628,7 +631,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
if !parse_only && !no_trans { if !parse_only && !no_trans {
let unparsed_output_types = matches.opt_strs("emit"); let unparsed_output_types = matches.opt_strs("emit");
for unparsed_output_type in unparsed_output_types.iter() { for unparsed_output_type in unparsed_output_types.iter() {
for part in unparsed_output_type.split(',') { for part in unparsed_output_type.as_slice().split(',') {
let output_type = match part.as_slice() { let output_type = match part.as_slice() {
"asm" => link::OutputTypeAssembly, "asm" => link::OutputTypeAssembly,
"ir" => link::OutputTypeLlvmAssembly, "ir" => link::OutputTypeLlvmAssembly,
@ -765,7 +768,7 @@ mod test {
#[test] #[test]
fn test_switch_implies_cfg_test() { fn test_switch_implies_cfg_test() {
let matches = let matches =
&match getopts(["--test".to_owned()], optgroups().as_slice()) { &match getopts(["--test".to_strbuf()], optgroups().as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg()) Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
}; };
@ -780,7 +783,7 @@ mod test {
#[test] #[test]
fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches = let matches =
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()], &match getopts(["--test".to_strbuf(), "--cfg=test".to_strbuf()],
optgroups().as_slice()) { optgroups().as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {

View File

@ -35,7 +35,7 @@ pub mod session;
pub mod config; pub mod config;
pub fn main_args(args: &[~str]) -> int { pub fn main_args(args: &[StrBuf]) -> int {
let owned_args = args.to_owned(); let owned_args = args.to_owned();
monitor(proc() run_compiler(owned_args)); monitor(proc() run_compiler(owned_args));
0 0
@ -44,7 +44,7 @@ pub fn main_args(args: &[~str]) -> int {
static BUG_REPORT_URL: &'static str = static BUG_REPORT_URL: &'static str =
"http://static.rust-lang.org/doc/master/complement-bugreport.html"; "http://static.rust-lang.org/doc/master/complement-bugreport.html";
fn run_compiler(args: &[~str]) { fn run_compiler(args: &[StrBuf]) {
let matches = match handle_options(Vec::from_slice(args)) { let matches = match handle_options(Vec::from_slice(args)) {
Some(matches) => matches, Some(matches) => matches,
None => return None => return
@ -73,7 +73,7 @@ fn run_compiler(args: &[~str]) {
let ofile = matches.opt_str("o").map(|o| Path::new(o)); let ofile = matches.opt_str("o").map(|o| Path::new(o));
let pretty = matches.opt_default("pretty", "normal").map(|a| { let pretty = matches.opt_default("pretty", "normal").map(|a| {
parse_pretty(&sess, a) parse_pretty(&sess, a.as_slice())
}); });
match pretty { match pretty {
Some::<PpMode>(ppm) => { Some::<PpMode>(ppm) => {
@ -84,7 +84,7 @@ fn run_compiler(args: &[~str]) {
} }
let r = matches.opt_strs("Z"); let r = matches.opt_strs("Z");
if r.contains(&("ls".to_owned())) { if r.contains(&("ls".to_strbuf())) {
match input { match input {
FileInput(ref ifile) => { FileInput(ref ifile) => {
let mut stdout = io::stdout(); let mut stdout = io::stdout();
@ -191,17 +191,20 @@ fn describe_codegen_flags() {
/// Process command line options. Emits messages as appropirate.If compilation /// Process command line options. Emits messages as appropirate.If compilation
/// should continue, returns a getopts::Matches object parsed from args, otherwise /// should continue, returns a getopts::Matches object parsed from args, otherwise
/// returns None. /// returns None.
pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> { pub fn handle_options(mut args: Vec<StrBuf>) -> Option<getopts::Matches> {
// Throw away the first argument, the name of the binary // Throw away the first argument, the name of the binary
let _binary = args.shift().unwrap(); let _binary = args.shift().unwrap();
if args.is_empty() { usage(); return None; } if args.is_empty() {
usage();
return None;
}
let matches = let matches =
match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) { match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
early_error(f.to_err_msg()); early_error(f.to_err_msg().as_slice());
} }
}; };
@ -212,24 +215,24 @@ pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> {
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append( let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
matches.opt_strs("warn").as_slice()); matches.opt_strs("warn").as_slice());
if lint_flags.iter().any(|x| x == &"help".to_owned()) { if lint_flags.iter().any(|x| x.as_slice() == "help") {
describe_warnings(); describe_warnings();
return None; return None;
} }
let r = matches.opt_strs("Z"); let r = matches.opt_strs("Z");
if r.iter().any(|x| x == &"help".to_owned()) { if r.iter().any(|x| x.as_slice() == "help") {
describe_debug_flags(); describe_debug_flags();
return None; return None;
} }
let cg_flags = matches.opt_strs("C"); let cg_flags = matches.opt_strs("C");
if cg_flags.iter().any(|x| x == &"help".to_owned()) { if cg_flags.iter().any(|x| x.as_slice() == "help") {
describe_codegen_flags(); describe_codegen_flags();
return None; return None;
} }
if cg_flags.contains(&"passes=list".to_owned()) { if cg_flags.contains(&"passes=list".to_strbuf()) {
unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); } unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); }
return None; return None;
} }

View File

@ -121,5 +121,8 @@ pub mod lib {
} }
pub fn main() { pub fn main() {
std::os::set_exit_status(driver::main_args(std::os::args().as_slice())); let args = std::os::args().iter()
.map(|x| x.to_strbuf())
.collect::<Vec<_>>();
std::os::set_exit_status(driver::main_args(args.as_slice()));
} }

View File

@ -137,12 +137,7 @@ pub fn usage(argv0: &str) {
} }
pub fn main_args(args: &[StrBuf]) -> int { pub fn main_args(args: &[StrBuf]) -> int {
let matches = match getopts::getopts(args.tail() let matches = match getopts::getopts(args.tail(), opts().as_slice()) {
.iter()
.map(|x| (*x).to_owned())
.collect::<Vec<_>>()
.as_slice(),
opts().as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(err) => { Err(err) => {
println!("{}", err.to_err_msg()); println!("{}", err.to_err_msg());
@ -170,7 +165,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
let test_args = matches.opt_strs("test-args"); let test_args = matches.opt_strs("test-args");
let test_args: Vec<StrBuf> = test_args.iter() let test_args: Vec<StrBuf> = test_args.iter()
.flat_map(|s| s.words()) .flat_map(|s| s.as_slice().words())
.map(|s| s.to_strbuf()) .map(|s| s.to_strbuf())
.collect(); .collect();
@ -199,7 +194,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
(false, false) => {} (false, false) => {}
} }
if matches.opt_strs("passes").as_slice() == &["list".to_owned()] { if matches.opt_strs("passes").as_slice() == &["list".to_strbuf()] {
println!("Available passes for running rustdoc:"); println!("Available passes for running rustdoc:");
for &(name, _, description) in PASSES.iter() { for &(name, _, description) in PASSES.iter() {
println!("{:>20s} - {}", name, description); println!("{:>20s} - {}", name, description);
@ -306,7 +301,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
clean::NameValue(ref x, ref value) clean::NameValue(ref x, ref value)
if "passes" == x.as_slice() => { if "passes" == x.as_slice() => {
for pass in value.as_slice().words() { for pass in value.as_slice().words() {
passes.push(pass.to_owned()); passes.push(pass.to_strbuf());
} }
} }
clean::NameValue(ref x, ref value) clean::NameValue(ref x, ref value)
@ -323,15 +318,19 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
} }
if default_passes { if default_passes {
for name in DEFAULT_PASSES.iter().rev() { for name in DEFAULT_PASSES.iter().rev() {
passes.unshift(name.to_owned()); passes.unshift(name.to_strbuf());
} }
} }
// Load all plugins/passes into a PluginManager // Load all plugins/passes into a PluginManager
let path = matches.opt_str("plugin-path").unwrap_or("/tmp/rustdoc/plugins".to_owned()); let path = matches.opt_str("plugin-path")
.unwrap_or("/tmp/rustdoc/plugins".to_strbuf());
let mut pm = plugins::PluginManager::new(Path::new(path)); let mut pm = plugins::PluginManager::new(Path::new(path));
for pass in passes.iter() { for pass in passes.iter() {
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) { let plugin = match PASSES.iter()
.position(|&(p, _, _)| {
p == pass.as_slice()
}) {
Some(i) => PASSES[i].val1(), Some(i) => PASSES[i].val1(),
None => { None => {
error!("unknown pass {}, skipping", *pass); error!("unknown pass {}, skipping", *pass);

View File

@ -354,11 +354,7 @@ Test Attributes:
pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> { pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
let args_ = args.tail(); let args_ = args.tail();
let matches = let matches =
match getopts::getopts(args_.iter() match getopts::getopts(args_.as_slice(), optgroups().as_slice()) {
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
optgroups().as_slice()) {
Ok(m) => m, Ok(m) => m,
Err(f) => return Some(Err(f.to_err_msg().to_strbuf())) Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
}; };
@ -388,7 +384,8 @@ pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s)); let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s));
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent"); let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap()); let ratchet_noise_percent =
ratchet_noise_percent.map(|s| from_str::<f64>(s.as_slice()).unwrap());
let save_metrics = matches.opt_str("save-metrics"); let save_metrics = matches.opt_str("save-metrics");
let save_metrics = save_metrics.map(|s| Path::new(s)); let save_metrics = save_metrics.map(|s| Path::new(s));

View File

@ -55,7 +55,7 @@ struct Config {
fn parse_opts(argv: Vec<StrBuf> ) -> Config { fn parse_opts(argv: Vec<StrBuf> ) -> Config {
let opts = vec!(getopts::optflag("", "stress", "")); let opts = vec!(getopts::optflag("", "stress", ""));
let argv = argv.iter().map(|x| x.to_str()).collect::<Vec<_>>(); let argv = argv.iter().map(|x| x.to_strbuf()).collect::<Vec<_>>();
let opt_args = argv.slice(1, argv.len()); let opt_args = argv.slice(1, argv.len());
match getopts::getopts(opt_args, opts.as_slice()) { match getopts::getopts(opt_args, opts.as_slice()) {