Fix settings-cleanup helper
MODIFY
binding-generator/src/bin/settings-cleanup.rs
binding-generator/src/bin/settings-cleanup.rs
@@ -106,11 +106,8 @@ fn show<S: AsRef<str>>(c: impl IntoIterator<Item=S>) {
fn main() {
let mut args = env::args_os().skip(1);
- let opencv_header_base_dir = PathBuf::from(args.next().expect("1st argument must be OpenCV header dir"));
let src_cpp_dir = PathBuf::from(args.next().expect("2nd argument must be dir with custom cpp"));
- let opencv_header_dirs = opencv_header_base_dir.read_dir().expect("Can't read opencv_header_base_dir")
- .map(|p| p.expect("Bad path").path())
- .filter(|p| p.is_dir());
+ let opencv_header_dirs = args.into_iter().map(PathBuf::from);
let mut func_rename_unused = settings::FUNC_RENAME.keys().copied().collect::<HashSet<_>>();
let mut func_cfg_attr_unused = settings::FUNC_CFG_ATTR.keys().copied().collect::<HashSet<_>>();
let mut func_unsafe_unused = settings::FUNC_UNSAFE.clone();
@@ -137,7 +134,7 @@ fn main() {
let gen = Generator::new(&opencv_header_dir, &[], &src_cpp_dir, clang);
for module in modules {
println!(" {}", module);
- gen.process_module(&module, false, |root_tu| {
+ gen.process_module(&module, false, |root_tu, _hdr| {
let root_entity = root_tu.get_entity();
let gen_env = GeneratorEnv::new(root_entity, &module);
let walker = EntityWalker::new(root_entity);

MODIFY
binding-generator/src/generator.rs
binding-generator/src/generator.rs
@@ -536,33 +536,31 @@ impl Generator {
args
}
- pub fn process_module(&self, module: &str, panic_on_error: bool, entity_processor: impl FnOnce(TranslationUnit)) {
+ pub fn process_module(&self, module: &str, panic_on_error: bool, entity_processor: impl FnOnce(TranslationUnit, &str)) {
let index = Index::new(&self.clang, true, false);
let mut module_file = self.src_cpp_dir.join(format!("{}.hpp", module));
if !module_file.exists() {
module_file = self.opencv_include_dir.join(format!("opencv2/{}.hpp", module));
}
- let root_tu: TranslationUnit = index.parser(module_file)
+ let mut root_tu: TranslationUnit = index.parser(module_file)
.unsaved(&[self.make_ephemeral_header("")])
.arguments(&self.build_clang_command_line_args())
.detailed_preprocessing_record(true)
.skip_function_bodies(true)
.parse().expect(&format!("Cannot parse module: {}", module));
- Self::handle_diags(&root_tu.get_diagnostics(), panic_on_error);
- entity_processor(root_tu);
- }
-
- pub fn process_opencv_module(&self, module: &str, mut visitor: impl GeneratorVisitor) {
- self.process_module(module, true, |mut root_tu| {
- let mut root_entity = root_tu.get_entity();
- let walker = EntityWalker::new(root_entity);
let mut ephem_gen = EphemeralGenerator::new(module);
+ let walker = EntityWalker::new(root_tu.get_entity());
walker.walk_opencv_entities(&mut ephem_gen);
let hdr = ephem_gen.make_generated_header();
- visitor.visit_ephemeral_header(&hdr);
root_tu = root_tu.reparse(&[self.make_ephemeral_header(&hdr)]).expect("Can't reparse file");
- Self::handle_diags(&root_tu.get_diagnostics(), true);
- root_entity = root_tu.get_entity();
+ Self::handle_diags(&root_tu.get_diagnostics(), panic_on_error);
+ entity_processor(root_tu, &hdr);
+ }
+
+ pub fn process_opencv_module(&self, module: &str, mut visitor: impl GeneratorVisitor) {
+ self.process_module(module, true, |root_tu, ephemeral_header| {
+ let root_entity = root_tu.get_entity();
+ visitor.visit_ephemeral_header(&ephemeral_header);
let gen_env = GeneratorEnv::new(root_entity, module);
let opencv_walker = OpenCvWalker::new(
&self.opencv_include_dir,

MODIFY
tools/config.tpl.sh
tools/config.tpl.sh
@@ -3,12 +3,14 @@ BINDINGS_OUT_DIR="$opencv_lib_base_dir/bindings"
# 3.2
OPENCV_32_PKG_CONFIG_PATH="$opencv_lib_base_dir/opencv-3.2/install/lib/pkgconfig/"
+OPENCV_32_HEADER_DIR="$opencv_lib_base_dir/opencv-3.2/install/include/"
OPENCV_32_OPENCV_PACKAGE_NAME="opencv"
OPENCV_32_LD_LIBRARY_PATH="$opencv_lib_base_dir/opencv-3.2/install/lib/"
OPENCV_32_OPENCV_INCLUDE_PATHS=+,/usr/include/eigen3/
# 3.4
OPENCV_34_CMAKE_DIR="$opencv_lib_base_dir/opencv-3.4/install/share/OpenCV"
+OPENCV_34_HEADER_DIR="$opencv_lib_base_dir/opencv-3.4/install/include/"
OPENCV_34_LD_LIBRARY_PATH="$opencv_lib_base_dir/opencv-3.4/install/lib64/"
# 4.x

MODIFY
tools/generate-bindings.sh
tools/generate-bindings.sh
@@ -4,13 +4,13 @@ script_dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
. "$script_dir/config.sh"
-export RUSTFLAGS=-Clink-arg=-fuse-ld=lld
-export RUST_BACKTRACE=full
SRC_CPP_DIR="$script_dir/../src_cpp/"
OUT_DIR="$script_dir/../out/generator/"
cd "$script_dir/.."
+export RUSTFLAGS=-Clink-arg=-fuse-ld=lld
+export RUST_BACKTRACE=full
if ! cargo build --release -p opencv-binding-generator --bin binding-generator; then
exit
fi

ADD
tools/settings-cleanup.sh
+#!/bin/bash
+
+set -e
+
+script_dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+. "$script_dir/config.sh"
+
+cd "$script_dir/.."
+
+export RUSTFLAGS=-Clink-arg=-fuse-ld=lld
+export RUST_BACKTRACE=full
+cargo run --release -p opencv-binding-generator --bin settings-cleanup -- src_cpp "$OPENCV_32_HEADER_DIR" "$OPENCV_34_HEADER_DIR" "$OPENCV_4_HEADER_DIR"

Fix settings-cleanup helper