Allow excluding specific crates from being parsed

This commit is contained in:
Ryan Hunt 2017-06-20 01:48:34 -04:00
parent a957bc2787
commit 01d88aa09b
3 changed files with 9 additions and 1 deletions

View File

@ -267,6 +267,8 @@ pub struct Config {
pub tab_width: usize,
/// The language to output bindings for
pub language: Language,
/// The names of crates to not parse
pub exclude: Vec<String>,
/// The names of crates to parse with `rustc --pretty=expanded`
pub expand: Vec<String>,
/// The configuration options for functions
@ -292,6 +294,7 @@ impl Default for Config {
line_length: 100,
tab_width: 2,
language: Language::Cxx,
exclude: Vec::new(),
expand: Vec::new(),
function: FunctionConfig::default(),
structure: StructConfig::default(),

View File

@ -128,6 +128,7 @@ impl<'a> Library<'a> {
rust_lib::parse_lib(crate_dir,
bindings_crate_name,
&config.exclude,
&config.expand,
&mut |crate_name, items| {
library.load_from_crate_mod(&crate_name, items);

View File

@ -44,6 +44,7 @@ pub fn parse_src<F>(src_file: &Path,
/// command to find the location of dependencies.
pub fn parse_lib<F>(crate_path: &Path,
binding_crate_name: &str,
exclude: &[String],
expand: &[String],
items_callback: &mut F) -> ParseResult
where F: FnMut(&str, &Vec<syn::Item>)
@ -60,6 +61,7 @@ pub fn parse_lib<F>(crate_path: &Path,
let mut context = ParseLibContext {
manifest_path: manifest_path,
metadata: metadata,
exclude: exclude.to_owned(),
expand: expand.to_owned(),
cache_src: HashMap::new(),
cache_expanded_crate: HashMap::new(),
@ -74,6 +76,7 @@ struct ParseLibContext<F>
{
manifest_path: PathBuf,
metadata: cargo_metadata::Metadata,
exclude: Vec<String>,
expand: Vec<String>,
cache_src: HashMap<PathBuf, Vec<syn::Item>>,
cache_expanded_crate: HashMap<String, Vec<syn::Item>>,
@ -103,7 +106,8 @@ impl<F> ParseLibContext<F>
fn parse_crate<F>(crate_name: &str, context: &mut ParseLibContext<F>) -> ParseResult
where F: FnMut(&str, &Vec<syn::Item>)
{
if STD_CRATES.contains(&crate_name) {
if STD_CRATES.contains(&crate_name) ||
context.exclude.contains(&crate_name.to_owned()) {
return Ok(());
}