rustc: Extract --crate-type parsing to its own function
Helpful for users of rustc as a library.
This commit is contained in:
parent
9631bf2e25
commit
1c3655bed1
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user