Skip to content

Commit 43c6571

Browse files
committed
Analyze libclang diagnostics
1 parent c7c4de8 commit 43c6571

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

binding-generator/src/bin/settings-cleanup.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ fn main() {
140140
let gen = Generator::new(None, &opencv_header_dir, &src_cpp_dir, clang);
141141
for module in modules {
142142
println!(" {}", module);
143-
gen.process_module(&module, |root_entity| {
144-
let gen_env = GeneratorEnv::new(root_entity, &module);
145-
let walker = EntityWalker::new(root_entity);
146-
walker.walk_opencv_entities(FunctionFinder {
147-
gen_env,
148-
func_rename_unused: &mut func_rename_unused,
149-
func_cfg_attr_unused: &mut func_cfg_attr_unused,
150-
func_unsafe_unused: &mut func_unsafe_unused,
151-
func_manual_unused: &mut func_manual_unused,
152-
func_specialize_unused: &mut func_specialize_unused,
153-
slice_argument_unused: &mut slice_argument_unused,
143+
gen.process_module(&module, false, |root_entity| {
144+
let gen_env = GeneratorEnv::new(root_entity, &module);
145+
let walker = EntityWalker::new(root_entity);
146+
walker.walk_opencv_entities(FunctionFinder {
147+
gen_env,
148+
func_rename_unused: &mut func_rename_unused,
149+
func_cfg_attr_unused: &mut func_cfg_attr_unused,
150+
func_unsafe_unused: &mut func_unsafe_unused,
151+
func_manual_unused: &mut func_manual_unused,
152+
func_specialize_unused: &mut func_specialize_unused,
153+
slice_argument_unused: &mut slice_argument_unused,
154154
});
155155
});
156156
}

binding-generator/src/generator.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use std::{
88

99
use clang::{
1010
Clang,
11+
diagnostic::Severity,
1112
Entity,
1213
EntityKind,
1314
Index,
15+
TranslationUnit,
1416
Type,
1517
};
1618
use dunce::canonicalize;
@@ -361,22 +363,36 @@ impl Generator {
361363
args
362364
}
363365

364-
pub fn process_module(&self, module: &str, entity_processor: impl FnOnce(Entity)) {
366+
pub fn process_module(&self, module: &str, panic_on_error: bool, entity_processor: impl FnOnce(Entity)) {
365367
let index = Index::new(&self.clang, true, false);
366368
let mut module_file = self.src_cpp_dir.join(format!("{}.hpp", module));
367369
if !module_file.exists() {
368370
module_file = self.opencv_include_dir.join(format!("opencv2/{}.hpp", module));
369371
}
370-
let root_tu = index.parser(module_file)
372+
let root_tu: TranslationUnit = index.parser(module_file)
371373
.arguments(&self.build_clang_command_line_args())
372374
.detailed_preprocessing_record(true)
373375
.skip_function_bodies(true)
374376
.parse().expect("Cannot parse");
377+
let diags = root_tu.get_diagnostics();
378+
if !diags.is_empty() {
379+
let mut has_error = false;
380+
eprintln!("=== WARNING: {} diagnostic messages", diags.len());
381+
for diag in diags {
382+
if !has_error && matches!(diag.get_severity(), Severity::Error | Severity::Fatal) {
383+
has_error = true;
384+
}
385+
eprintln!("=== {}", diag);
386+
}
387+
if has_error && panic_on_error {
388+
panic!("=== Errors during header parsing");
389+
}
390+
}
375391
entity_processor(root_tu.get_entity());
376392
}
377393

378394
pub fn process_opencv_module(&self, module: &str, visitor: impl for<'gtu> GeneratorVisitor<'gtu>) {
379-
self.process_module(module, |root_entity| {
395+
self.process_module(module, true, |root_entity| {
380396
let gen_env = GeneratorEnv::new(root_entity, module);
381397
let opencv_walker = OpenCVWalker::new(
382398
&self.opencv_include_dir,

0 commit comments

Comments
 (0)