Skip to content

Commit

Permalink
Add more logging to preprocessing step
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Nov 29, 2023
1 parent 96e0713 commit 8846f97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ViSP Python bindings generator
#
#############################################################################

import logging
from typing import Dict, Final, List, Optional
import re
from pathlib import Path
Expand Down Expand Up @@ -124,10 +124,10 @@ class GeneratorConfig(object):
'VISP_BUILD_DEPRECATED_FUNCTIONS', # Do not bind deprecated functions
'VISP_RUBIK_REGULAR_FONT_RESOURCES'
],
include_directories=[], # Populate through the main configuration file
include_directories=[], # Populated through the main configuration file
passthrough_includes_regex="^.*$", # Never output the result of other includes.
line_directive=None,
other_args=["--passthru-unfound-includes"] #"--passthru-comments"
other_args=['--passthru-unfound-includes'] #"--passthru-comments"
)

xml_doc_path: Optional[Path] = None
Expand Down Expand Up @@ -159,6 +159,7 @@ def update_from_main_config_file(path: Path) -> None:
assert path.exists()
with open(path, 'r') as main_config_file:
main_config = json.load(main_config_file)
logging.info('Updating the generator config from dict: ', main_config)
GeneratorConfig.pcpp_config.include_directories = main_config['include_dirs']

defines = main_config.get('defines')
Expand All @@ -178,4 +179,6 @@ def update_from_main_config_file(path: Path) -> None:

# Include only headers that are in the VISP source directory
headers = list(filter(lambda h: source_dir in h.parents, headers))
headers_log_str = '\n\t'.join([str(header) for header in headers])
logging.info(f'Module {module_name} headers: \n\t{headers_log_str}')
GeneratorConfig.module_data.append(ModuleInputData(module_name, headers, deps))
6 changes: 5 additions & 1 deletion modules/python/generator/visp_python_bindgen/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def preprocess(self) -> None:
self.documentation_holder_path = DocumentationData.get_xml_path_if_exists(name_cpp_no_template, DocumentationObjectKind.Class)

def run_preprocessor(self):
logging.info(f'Preprocessing header {self.path.name}')
tmp_dir = self.submodule.submodule_file_path.parent / "tmp"
tmp_dir.mkdir(exist_ok=True)
tmp_file_path = tmp_dir / (self.path.name + '.in')
Expand Down Expand Up @@ -148,6 +149,8 @@ def run_preprocessor(self):

argv = [''] + GeneratorConfig.pcpp_config.to_pcpp_args_list()
argv += ['-o', f'{preprocessor_output_path}', str(tmp_file_path.absolute())]
argv_str = ", ".join(argv)
logging.info(f'Preprocessor arguments:\n{argv_str}')

pcpp.CmdPreprocessor(argv)
preprocessed_header_content = None
Expand Down Expand Up @@ -212,7 +215,7 @@ def parse_sub_namespace(self, bindings_container: BindingsContainer, ns: Namespa
rejection_strs.append(f'\t{rejected_function.signature} was rejected! Reason: {rejected_function.rejection_reason}')
if len(rejection_strs) > 0:
logging.warning(f'Rejected function in namespace: {ns.name}')
logging.warning('\n'.join(rejection_strs))
logging.warning('\n' + '\n'.join(rejection_strs))

bound_object = BoundObjectNames('submodule', self.submodule.name, namespace_prefix, namespace_prefix)
defs = []
Expand All @@ -221,6 +224,7 @@ def parse_sub_namespace(self, bindings_container: BindingsContainer, ns: Namespa

bindings_container.add_bindings(SingleObjectBindings(bound_object, None, defs, GenerationObjectType.Namespace))
for sub_ns in ns.namespaces:
logging.info(f'Parsing subnamespace {namespace_prefix + sub_ns}')
self.parse_sub_namespace(bindings_container, ns.namespaces[sub_ns], namespace_prefix + sub_ns + '::', False)

def generate_class(self, bindings_container: BindingsContainer, cls: ClassScope, header_env: HeaderEnvironment) -> SingleObjectBindings:
Expand Down

0 comments on commit 8846f97

Please sign in to comment.