提交 1fb08f11 编写于 作者: P Patrick Walton

libgetopts: Remove all uses of `~str` from `libgetopts`

上级 28bcef85
......@@ -101,11 +101,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
}
let matches =
&match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
groups.as_slice()) {
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
......@@ -146,7 +142,9 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
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"),
filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
......@@ -154,7 +152,8 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
ratchet_metrics:
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
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()),
host_rustcflags: matches.opt_str("host-rustcflags")
.map(|x| x.to_strbuf()),
......
此差异已折叠。
......@@ -319,7 +319,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
{
let mut cg = basic_codegen_options();
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 value = iter.next();
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 unparsed_crate_types = matches.opt_strs("crate-type");
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 {
"lib" => default_lib_output(),
"rlib" => CrateTypeRlib,
......@@ -612,7 +612,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut this_bit = 0;
for tuple in debug_map.iter() {
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 {
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 {
let unparsed_output_types = matches.opt_strs("emit");
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() {
"asm" => link::OutputTypeAssembly,
"ir" => link::OutputTypeLlvmAssembly,
......@@ -765,7 +768,7 @@ mod test {
#[test]
fn test_switch_implies_cfg_test() {
let matches =
&match getopts(["--test".to_owned()], optgroups().as_slice()) {
&match getopts(["--test".to_strbuf()], optgroups().as_slice()) {
Ok(m) => m,
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
};
......@@ -780,7 +783,7 @@ fn test_switch_implies_cfg_test() {
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches =
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()],
&match getopts(["--test".to_strbuf(), "--cfg=test".to_strbuf()],
optgroups().as_slice()) {
Ok(m) => m,
Err(f) => {
......
......@@ -35,7 +35,7 @@
pub mod config;
pub fn main_args(args: &[~str]) -> int {
pub fn main_args(args: &[StrBuf]) -> int {
let owned_args = args.to_owned();
monitor(proc() run_compiler(owned_args));
0
......@@ -44,7 +44,7 @@ pub fn main_args(args: &[~str]) -> int {
static BUG_REPORT_URL: &'static str =
"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)) {
Some(matches) => matches,
None => return
......@@ -73,7 +73,7 @@ fn run_compiler(args: &[~str]) {
let ofile = matches.opt_str("o").map(|o| Path::new(o));
let pretty = matches.opt_default("pretty", "normal").map(|a| {
parse_pretty(&sess, a)
parse_pretty(&sess, a.as_slice())
});
match pretty {
Some::<PpMode>(ppm) => {
......@@ -84,7 +84,7 @@ fn run_compiler(args: &[~str]) {
}
let r = matches.opt_strs("Z");
if r.contains(&("ls".to_owned())) {
if r.contains(&("ls".to_strbuf())) {
match input {
FileInput(ref ifile) => {
let mut stdout = io::stdout();
......@@ -191,17 +191,20 @@ fn describe_codegen_flags() {
/// Process command line options. Emits messages as appropirate.If compilation
/// should continue, returns a getopts::Matches object parsed from args, otherwise
/// 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
let _binary = args.shift().unwrap();
if args.is_empty() { usage(); return None; }
if args.is_empty() {
usage();
return None;
}
let matches =
match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) {
Ok(m) => m,
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(
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();
return None;
}
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();
return None;
}
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();
return None;
}
if cg_flags.contains(&"passes=list".to_owned()) {
if cg_flags.contains(&"passes=list".to_strbuf()) {
unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); }
return None;
}
......
......@@ -121,5 +121,8 @@ pub mod lib {
}
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()));
}
......@@ -137,12 +137,7 @@ pub fn usage(argv0: &str) {
}
pub fn main_args(args: &[StrBuf]) -> int {
let matches = match getopts::getopts(args.tail()
.iter()
.map(|x| (*x).to_owned())
.collect::<Vec<_>>()
.as_slice(),
opts().as_slice()) {
let matches = match getopts::getopts(args.tail(), opts().as_slice()) {
Ok(m) => m,
Err(err) => {
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: Vec<StrBuf> = test_args.iter()
.flat_map(|s| s.words())
.flat_map(|s| s.as_slice().words())
.map(|s| s.to_strbuf())
.collect();
......@@ -199,7 +194,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
(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:");
for &(name, _, description) in PASSES.iter() {
println!("{:>20s} - {}", name, description);
......@@ -306,7 +301,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
clean::NameValue(ref x, ref value)
if "passes" == x.as_slice() => {
for pass in value.as_slice().words() {
passes.push(pass.to_owned());
passes.push(pass.to_strbuf());
}
}
clean::NameValue(ref x, ref value)
......@@ -323,15 +318,19 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
}
if default_passes {
for name in DEFAULT_PASSES.iter().rev() {
passes.unshift(name.to_owned());
passes.unshift(name.to_strbuf());
}
}
// 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));
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(),
None => {
error!("unknown pass {}, skipping", *pass);
......
......@@ -354,11 +354,7 @@ fn usage(binary: &str) {
pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
let args_ = args.tail();
let matches =
match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
optgroups().as_slice()) {
match getopts::getopts(args_.as_slice(), optgroups().as_slice()) {
Ok(m) => m,
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_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 = save_metrics.map(|s| Path::new(s));
......
......@@ -55,7 +55,7 @@ struct Config {
fn parse_opts(argv: Vec<StrBuf> ) -> Config {
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());
match getopts::getopts(opt_args, opts.as_slice()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册