diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-07-19 21:11:26 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-21 09:54:26 -0700 |
| commit | 1c3655bed192e31bdf649ed5f4e728201ede17b2 (patch) | |
| tree | dc7333aadf8b04e6eee8d61d2a7e5ee8ad70fecd | |
| parent | 9631bf2e2526173b21070eb532c6cb590c5869b8 (diff) | |
| download | rust-1c3655bed192e31bdf649ed5f4e728201ede17b2.tar.gz rust-1c3655bed192e31bdf649ed5f4e728201ede17b2.zip | |
rustc: Extract --crate-type parsing to its own function
Helpful for users of rustc as a library.
| -rw-r--r-- | src/librustc/driver/config.rs | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index ee611293475..4752997a3fc 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -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 { |
