Rework debug mode enablement for binding-generator
MODIFY
binding-generator/src/bin/binding-generator.rs
binding-generator/src/bin/binding-generator.rs
@@ -68,7 +68,13 @@ fn get_version_from_headers(header_dir: &Path) -> Option<String> {
fn main() {
let mut args = env::args_os().skip(1);
- let opencv_header_dir = PathBuf::from(args.next().expect("1st argument must be OpenCV header dir"));
+ let mut opencv_header_dir = args.next();
+ let mut debug = false;
+ if opencv_header_dir.as_ref().map_or(false, |debug| debug == "--debug") {
+ debug = true;
+ opencv_header_dir = args.next();
+ }
+ let opencv_header_dir = PathBuf::from(opencv_header_dir.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 out_dir = PathBuf::from(args.next().expect("3rd argument must be output dir"));
let module = args.next().expect("4th argument must be module name");
@@ -85,7 +91,6 @@ fn main() {
} else {
vec![]
};
- let debug = args.next().map_or(false, |x| x == "1");
let clang = Clang::new().expect("Cannot initialize clang");
let bindings_writer = RustNativeBindingWriter::new(&src_cpp_dir, &out_dir, module, &version, debug);
Generator::new(&opencv_header_dir, &additional_include_dirs, &src_cpp_dir, clang)

MODIFY
binding-generator/src/writer/rust_native/mod.rs
binding-generator/src/writer/rust_native/mod.rs
@@ -70,8 +70,9 @@ impl<'s> RustNativeBindingWriter<'s> {
pub fn new(src_cpp_dir: &Path, out_dir: impl Into<PathBuf>, module: &'s str, opencv_version: &'s str, debug: bool) -> Self {
let out_dir = out_dir.into();
let debug_path = out_dir.join(format!("{}.log", module));
- if debug {
+ #[allow(clippy::collapsible_if)]
if false {
+ if debug {
File::create(&debug_path).expect("Can't create debug log");
}
}
@@ -158,11 +159,7 @@ impl GeneratorVisitor for RustNativeBindingWriter<'_> {
let safe_id = typ.element_safe_id();
let path = self.types_dir.join(format!("{:03}-{}.type.rs", prio, safe_id));
- let file = if self.debug {
- OpenOptions::new().create(true).write(true).truncate(true).open(&path)
- } else {
- OpenOptions::new().create_new(true).write(true).open(&path)
- };
+ let file = OpenOptions::new().create_new(true).write(true).open(&path);
match file {
Ok(mut file) => {
let gen = typ.gen_rust(self.opencv_version);
@@ -181,11 +178,7 @@ impl GeneratorVisitor for RustNativeBindingWriter<'_> {
}
let path = self.types_dir.join(format!("{:03}-{}.type.cpp", prio, safe_id));
- let file = if self.debug {
- OpenOptions::new().create(true).write(true).truncate(true).open(&path)
- } else {
- OpenOptions::new().create_new(true).write(true).open(&path)
- };
+ let file = OpenOptions::new().create_new(true).write(true).open(&path);
match file {
Ok(mut file) => {
let gen = typ.gen_cpp();
@@ -205,7 +198,7 @@ impl GeneratorVisitor for RustNativeBindingWriter<'_> {
}
fn visit_ephemeral_header(&mut self, contents: &str) {
- if false {
+ if self.debug {
let mut file = File::create(self.types_dir.join(format!("ocvrs_ephemeral_{}.hpp", self.module))).expect("Can't create debug ephemeral file");
file.write_all(contents.as_bytes()).expect("Can't write debug ephemeral file");
}

Rework debug mode enablement for binding-generator