diff --git a/.gitignore b/.gitignore index 927cff2b..6160d917 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ -build* -.vscode/ -.vs/ +/build* +/.vscode/ +/.vs/ # documentation /docs/mkdocs/site/ -/docs/mkdocs/venv/ \ No newline at end of file +/docs/mkdocs/venv/ + +# natvis generator +/tool/natvis_generator/venv/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7588b003..c6ad94a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,15 @@ target_include_directories( ${FK_YAML_TARGET_NAME} INTERFACE $ $) +# add .natvis file to apply custom debug view for MSVC +if(MSVC) + set(FK_YAML_INSTALL_NATVIS ON) + set(FK_YAML_NATVIS_FILE "fkYAML.natvis") + target_sources( + ${FK_YAML_TARGET_NAME} INTERFACE $ + $) +endif() + ############################ # Integrate with tools # ############################ @@ -129,6 +138,10 @@ if(FK_YAML_INSTALL) install(DIRECTORY "${FK_YAML_INCLUDE_BUILD_DIR}" DESTINATION include) install(FILES "${FK_YAML_CMAKE_PROJECT_CONFIG_FILE}" "${FK_YAML_CMAKE_VERSION_CONFIG_FILE}" DESTINATION "${FK_YAML_CONFIG_INSTALL_DIR}") + if(FK_YAML_INSTALL_NATVIS) + install(FILES ${FK_YAML_NATVIS_FILE} + DESTINATION .) + endif() export( TARGETS ${FK_YAML_TARGET_NAME} NAMESPACE ${PROJECT_NAME}:: diff --git a/Makefile b/Makefile index 568e3f13..89ba3e3d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: update-version-macros CHANGELOG.md update-version +.PHONY: update-version-macros CHANGELOG.md update-version fkYAML.natvis ################# # variables # @@ -32,6 +32,7 @@ all: @echo "clang-sanitizers - check whether no runtime issue is detected while running the unit test app." @echo "clang-tidy - check whether source files detect no issues during static code analysis." @echo "cmake-format - check whether CMake scripts are well formatted." + @echo "fkYAML.natvis - generate the Natvis debugger visualization file." @echo "html-coverage - generate HTML coverage report." @echo "iwyu - check whether source files are each self-contained." @echo "lcov-coverage - generate coverage data with lcov." @@ -81,6 +82,16 @@ valgrind: cmake-format: cmake-format $(CMAKE_SCRIPTS) -i -c .cmake-format.yaml +########################################## +# Natvis Debugger Visualization File # +########################################## + +update-params-for-natvis: + echo { \"version\": \"$(TARGET_VERSION_FULL)\" } > ./tool/natvis_generator/params.json + +fkYAML.natvis: update-params-for-natvis + make -C ./tool/natvis_generator generate + ############### # Version # ############### @@ -125,7 +136,7 @@ CHANGELOG.md: --release-url https://github.com/fktn-k/fkYAML/releases/tag/%s \ --future-release v$(TARGET_VERSION_FULL) -update-version: update-version-macros update-project-version reuse CHANGELOG.md update-git-tag-ref +update-version: fkYAML.natvis update-version-macros update-project-version reuse update-git-tag-ref CHANGELOG.md @echo "updated version to $(TARGET_VERSION_FULL)" ################ diff --git a/fkYAML.natvis b/fkYAML.natvis new file mode 100644 index 00000000..59479ff8 --- /dev/null +++ b/fkYAML.natvis @@ -0,0 +1,32 @@ + + + + + + + + + {*(m_node_value.p_sequence)} + {*(m_node_value.p_mapping)} + nullptr + {m_node_value.boolean} + {m_node_value.integer} + {m_node_value.float_val} + {*(m_node_value.p_string)} + + + *(m_node_value.p_sequence),view(simple) + + + *(m_node_value.p_mapping),view(simple) + + + + + + {second} + + second + + + diff --git a/tool/natvis_generator/Makefile b/tool/natvis_generator/Makefile new file mode 100644 index 00000000..2530879a --- /dev/null +++ b/tool/natvis_generator/Makefile @@ -0,0 +1,10 @@ +install-venv: + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements.txt + +uninstall-venv: + rm -rf venv + +generate: install-venv + venv/bin/python3 ./natvis_generator.py \ No newline at end of file diff --git a/tool/natvis_generator/README.md b/tool/natvis_generator/README.md new file mode 100644 index 00000000..32aabecd --- /dev/null +++ b/tool/natvis_generator/README.md @@ -0,0 +1,12 @@ +# natvis_generator.py + +Generate the Natvis debugger visualization file for fkYAML library with fully qualified namespaces which is specified in the params.json file. +To modify the output natvis file, + +## Usage + +Update "version" value and run the following command. + +```bash +./natvis_generator.py +``` \ No newline at end of file diff --git a/tool/natvis_generator/fkYAML.natvis.j2 b/tool/natvis_generator/fkYAML.natvis.j2 new file mode 100644 index 00000000..b560e9b8 --- /dev/null +++ b/tool/natvis_generator/fkYAML.natvis.j2 @@ -0,0 +1,32 @@ + + + + + + + + + {*(m_node_value.p_sequence)} + {*(m_node_value.p_mapping)} + nullptr + {m_node_value.boolean} + {m_node_value.integer} + {m_node_value.float_val} + {*(m_node_value.p_string)} + + + *(m_node_value.p_sequence),view(simple) + + + *(m_node_value.p_mapping),view(simple) + + + + + + {second} + + second + + + diff --git a/tool/natvis_generator/natvis_generator.py b/tool/natvis_generator/natvis_generator.py new file mode 100644 index 00000000..ee5b8641 --- /dev/null +++ b/tool/natvis_generator/natvis_generator.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import json +import jinja2 +import re +import sys + +def check_version_format(ver): + if not re.fullmatch(r'\d+\.\d+\.\d+', ver): + raise ValueError('Invalid semantic version specified. ver=' + ver) + return ver + + +if __name__ == '__main__': + + with open('params.json') as j: + params= json.load(j) + + semver = check_version_format(params['version']) + abi_ns = 'v' + semver.replace('.', '_') + namespace = 'fkyaml::' + abi_ns + + environment = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]), + autoescape=True, + trim_blocks=True, + lstrip_blocks=True, + keep_trailing_newline=True) + template = environment.get_template('fkYAML.natvis.j2') + + natvis = template.render(namespace=namespace) + + with open('../../fkYAML.natvis', 'w') as f: + f.write(natvis) \ No newline at end of file diff --git a/tool/natvis_generator/params.json b/tool/natvis_generator/params.json new file mode 100644 index 00000000..d7d9ddc4 --- /dev/null +++ b/tool/natvis_generator/params.json @@ -0,0 +1 @@ +{ "version": "0.2.2" } diff --git a/tool/natvis_generator/requirements.txt b/tool/natvis_generator/requirements.txt new file mode 100644 index 00000000..9dc0d71f --- /dev/null +++ b/tool/natvis_generator/requirements.txt @@ -0,0 +1 @@ +Jinja2==3.1.2.