summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Reed <jcreed@gmail.com>2018-10-12 17:31:36 -0400
committerJason Reed <jcreed@gmail.com>2018-10-12 17:31:36 -0400
commit76c3797f43b536f2fbb541fdf7455de933768ea2 (patch)
tree6b9e212892ce81aec0d311881b19c26d683959ad /src
parent6055f364bd1d341da8fa881741ec36ab0abf0a7a (diff)
Re-add ability to blacklist arbitrary identifiers
(regardless of which sort of Item they are)
Diffstat (limited to 'src')
-rw-r--r--src/ir/item.rs1
-rw-r--r--src/lib.rs27
-rw-r--r--src/options.rs13
3 files changed, 41 insertions, 0 deletions
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 92372031..396886e1 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -637,6 +637,7 @@ impl Item {
let path = self.canonical_path(ctx);
let name = path[1..].join("::");
+ ctx.options().blacklisted_identifiers.matches(&name) ||
match self.kind {
ItemKind::Type(..) => {
ctx.options().blacklisted_types.matches(&name) ||
diff --git a/src/lib.rs b/src/lib.rs
index b7608ce2..7149d2f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -311,6 +311,20 @@ impl Builder {
})
.count();
+ self.options
+ .blacklisted_identifiers
+ .get_items()
+ .iter()
+ .map(|item| {
+ output_vector.push("--blacklist-identifier".into());
+ output_vector.push(
+ item.trim_left_matches("^")
+ .trim_right_matches("$")
+ .into(),
+ );
+ })
+ .count();
+
if !self.options.layout_tests {
output_vector.push("--no-layout-tests".into());
}
@@ -754,6 +768,13 @@ impl Builder {
self
}
+ /// Hide the given identifier from the generated bindings. Regular expressions
+ /// are supported.
+ pub fn blacklist_identifier<T: AsRef<str>>(mut self, arg: T) -> Builder {
+ self.options.blacklisted_identifiers.insert(arg);
+ self
+ }
+
/// Treat the given type as opaque in the generated bindings. Regular
/// expressions are supported.
pub fn opaque_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
@@ -1313,6 +1334,10 @@ struct BindgenOptions {
/// in the generated code.
blacklisted_functions: RegexSet,
+ /// The set of identifiers (regardless of Item type) that have
+ /// been blacklisted and should not appear in the generated code.
+ blacklisted_identifiers: RegexSet,
+
/// The set of types that should be treated as opaque structures in the
/// generated code.
opaque_types: RegexSet,
@@ -1531,6 +1556,7 @@ impl BindgenOptions {
self.whitelisted_functions.build();
self.blacklisted_types.build();
self.blacklisted_functions.build();
+ self.blacklisted_identifiers.build();
self.opaque_types.build();
self.bitfield_enums.build();
self.constified_enums.build();
@@ -1564,6 +1590,7 @@ impl Default for BindgenOptions {
rust_features: rust_target.into(),
blacklisted_types: Default::default(),
blacklisted_functions: Default::default(),
+ blacklisted_identifiers: Default::default(),
opaque_types: Default::default(),
rustfmt_path: Default::default(),
whitelisted_types: Default::default(),
diff --git a/src/options.rs b/src/options.rs
index ce89c23c..7e5a5e67 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -78,6 +78,13 @@ where
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("blacklist-identifier")
+ .long("blacklist-identifier")
+ .help("Mark <identifier> as hidden.")
+ .value_name("identifier")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
Arg::with_name("no-layout-tests")
.long("no-layout-tests")
.help("Avoid generating layout tests for any type."),
@@ -370,6 +377,12 @@ where
}
}
+ if let Some(hidden_identifiers) = matches.values_of("blacklist-identifier") {
+ for id in hidden_identifiers {
+ builder = builder.blacklist_identifier(id);
+ }
+ }
+
if matches.is_present("builtins") {
builder = builder.emit_builtins();
}