Skip to content

Commit

Permalink
fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Oct 27, 2023
1 parent d19146b commit ce8fb36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion modules/python/generator/visp_python_bindgen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def generate_module(generate_path: Path, config_path: Path) -> None:
raise RuntimeError('There was an exception when processing headers: You should either ignore the faulty header/class, or fix the generator code!')
new_all_headers.append(result)


# Sort headers according to the dependencies. This is done across all modules.
# TODO: sort module generation order. For now this works but it's fairly brittle
new_all_headers = sort_headers(new_all_headers)
Expand Down Expand Up @@ -125,4 +126,4 @@ def main():
generate_module(generation_path, config_path)

if __name__ == '__main__':
main()
main()
10 changes: 8 additions & 2 deletions modules/python/generator/visp_python_bindgen/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ def preprocess(self) -> None:
Preprocess the header to obtain the abstract representation of the cpp classes available.
Additionally get the path to the xml documentation file generated by doxygen
'''
from cxxheaderparser.options import ParserOptions
self.preprocessed_header_str = self.run_preprocessor() # Run preprocessor, get only code that can be compiled with current visp
self.header_repr: ParsedData = parse_string(self.preprocessed_header_str) # Get the cxxheaderparser representation of the header

self.header_repr: ParsedData = parse_string(self.preprocessed_header_str, options=ParserOptions(verbose=False, convert_void_to_zero_params=True)) # Get the cxxheaderparser representation of the header

# Get dependencies of this header. This is important for the code generation order
for cls in self.header_repr.namespace.classes:
Expand All @@ -98,7 +100,7 @@ def run_preprocessor(self):
# Includes that should be appended at the start of every file
forced_includes = [
'visp3/core/vpConfig.h', # Always include vpConfig: ensure that VISP macros are correctly defined
'opencv2/opencv_modules.hpp'
'opencv2/opencv.hpp'
]
for include in forced_includes:
tmp_file_content.append(f'#include <{include}>\n')
Expand All @@ -110,6 +112,9 @@ def run_preprocessor(self):
matches = re.search(include_regex, line)
if matches is None: # Include line if its not an include
tmp_file_content.append(line)
# else:
# if 'visp3' in matches.group() or 'opencv' in matches.group():
# tmp_file_content.append(line)

with open(tmp_file_path.absolute(), 'w') as tmp_file:
tmp_file.write(''.join(tmp_file_content))
Expand All @@ -130,6 +135,7 @@ def run_preprocessor(self):
preprocessed_header_lines.append(line)
preprocessed_header_content = '\n'.join(preprocessed_header_lines)
preprocessed_header_content = preprocessed_header_content.replace('#include<', '#include <') # Bug in cpp header parser

return preprocessed_header_content

def generate_binding_code(self) -> None:
Expand Down

0 comments on commit ce8fb36

Please sign in to comment.