Skip to content

Commit 19bd399

Browse files
committed
No --remove-function-prefix flag
1 parent 98a0d71 commit 19bd399

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

src/options.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
1-
use bindgen::callbacks::ParseCallbacks;
21
use bindgen::{
32
builder, AliasVariation, Builder, CodegenConfig, EnumVariation,
43
MacroTypeVariation, RustTarget, DEFAULT_ANON_FIELDS_PREFIX,
54
RUST_TARGET_STRINGS,
65
};
76
use clap::{App, Arg};
8-
use std::fmt::Debug;
97
use std::fs::File;
108
use std::io::{self, stderr, Error, ErrorKind, Write};
119
use std::path::PathBuf;
1210
use std::str::FromStr;
1311

14-
#[derive(Debug)]
15-
pub struct LinkNameOverrideParseCallback {
16-
pub remove_function_prefix: Option<String>,
17-
}
18-
19-
impl LinkNameOverrideParseCallback {
20-
pub fn new(prefix: &str) -> Self {
21-
LinkNameOverrideParseCallback {
22-
remove_function_prefix: Some(prefix.to_string()),
23-
}
24-
}
25-
}
26-
27-
impl ParseCallbacks for LinkNameOverrideParseCallback {
28-
fn generated_name_override(&self, function_name: &str) -> Option<String> {
29-
if let Some(prefix) = &self.remove_function_prefix {
30-
if function_name.starts_with(prefix) {
31-
return Some(function_name[prefix.len()..].to_string());
32-
}
33-
}
34-
None
35-
}
36-
}
37-
3812
/// Construct a new [`Builder`](./struct.Builder.html) from command line flags.
3913
pub fn builder_from_flags<I>(
4014
args: I,
@@ -571,11 +545,6 @@ where
571545
Arg::new("vtable-generation")
572546
.long("vtable-generation")
573547
.help("Enables generation of vtable functions."),
574-
Arg::new("remove-function-prefix")
575-
.long("remove-function-prefix")
576-
.multiple_occurrences(true)
577-
.takes_value(true)
578-
.help("Remove prefix when generating Rust function name."),
579548
Arg::new("V")
580549
.long("version")
581550
.help("Prints the version, and exits"),
@@ -1061,11 +1030,6 @@ where
10611030
builder = builder.vtable_generation(true);
10621031
}
10631032

1064-
if let Some(prefix) = matches.value_of("remove-function-prefix") {
1065-
let lnopc = LinkNameOverrideParseCallback::new(prefix);
1066-
builder = builder.parse_callbacks(Box::new(lnopc));
1067-
}
1068-
10691033
let verbose = matches.is_present("verbose");
10701034

10711035
Ok((builder, output, verbose))

tests/headers/issue-1375-prefixed-functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// bindgen-flags: --remove-function-prefix my_custom_prefix_
21
// bindgen-parse-callbacks: remove-function-prefix-my_custom_prefix_
32

43
void my_custom_prefix_function_name(const int x);

tests/parse_callbacks/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1-
use crate::options::LinkNameOverrideParseCallback;
21
use bindgen::callbacks::*;
32

3+
#[derive(Debug)]
4+
pub struct RemoveFunctionPrefixParseCallback {
5+
pub remove_function_prefix: Option<String>,
6+
}
7+
8+
impl RemoveFunctionPrefixParseCallback {
9+
pub fn new(prefix: &str) -> Self {
10+
RemoveFunctionPrefixParseCallback {
11+
remove_function_prefix: Some(prefix.to_string()),
12+
}
13+
}
14+
}
15+
16+
impl ParseCallbacks for RemoveFunctionPrefixParseCallback {
17+
fn generated_name_override(&self, function_name: &str) -> Option<String> {
18+
if let Some(prefix) = &self.remove_function_prefix {
19+
if function_name.starts_with(prefix) {
20+
return Some(function_name[prefix.len()..].to_string());
21+
}
22+
}
23+
None
24+
}
25+
}
26+
427
#[derive(Debug)]
528
struct EnumVariantRename;
629

@@ -44,7 +67,7 @@ pub fn lookup(cb: &str) -> Box<dyn ParseCallbacks> {
4467
.split("remove-function-prefix-")
4568
.last()
4669
.to_owned();
47-
let lnopc = LinkNameOverrideParseCallback::new(prefix.unwrap());
70+
let lnopc = RemoveFunctionPrefixParseCallback::new(prefix.unwrap());
4871
Box::new(lnopc)
4972
} else {
5073
panic!("Couldn't find name ParseCallbacks: {}", cb)

0 commit comments

Comments
 (0)