提交 1c3655be 编写于 作者: B Brian Anderson 提交者: Alex Crichton

rustc: Extract --crate-type parsing to its own function

Helpful for users of rustc as a library.
上级 9631bf2e
......@@ -593,24 +593,10 @@ fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
}
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.as_slice().split(',') {
let new_part = match part {
"lib" => default_lib_output(),
"rlib" => CrateTypeRlib,
"staticlib" => CrateTypeStaticlib,
"dylib" => CrateTypeDylib,
"bin" => CrateTypeExecutable,
_ => {
early_error(format!("unknown crate type: `{}`",
part).as_slice())
}
};
crate_types.push(new_part)
}
}
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
.unwrap_or_else(|e| early_error(e.as_slice()));
let parse_only = matches.opt_present("parse-only");
let no_trans = matches.opt_present("no-trans");
......@@ -804,6 +790,29 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
}
}
pub fn parse_crate_types_from_list(crate_types_list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
let mut crate_types: Vec<CrateType> = Vec::new();
for unparsed_crate_type in crate_types_list_list.iter() {
for part in unparsed_crate_type.as_slice().split(',') {
let new_part = match part {
"lib" => default_lib_output(),
"rlib" => CrateTypeRlib,
"staticlib" => CrateTypeStaticlib,
"dylib" => CrateTypeDylib,
"bin" => CrateTypeExecutable,
_ => {
return Err(format!("unknown crate type: `{}`",
part));
}
};
crate_types.push(new_part)
}
}
return Ok(crate_types);
}
impl fmt::Show for CrateType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册