From beeb86ad8f93e9535caf0db3999353eac04e5bbc Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 28 Nov 2023 01:36:56 +0900 Subject: [PATCH 1/4] added .natvis file --- .gitignore | 11 ++++++---- CMakeLists.txt | 13 ++++++++++++ Makefile | 13 +++++++++++- fkYAML.natvis | 25 +++++++++++++++++++++++ tool/natvis_generator/fkYAML.natvis.j2 | 25 +++++++++++++++++++++++ tool/natvis_generator/natvis_generator.py | 22 ++++++++++++++++++++ 6 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 fkYAML.natvis create mode 100644 tool/natvis_generator/fkYAML.natvis.j2 create mode 100644 tool/natvis_generator/natvis_generator.py diff --git a/.gitignore b/.gitignore index 927cff2b..50b9b4c9 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 +/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..78a3067f 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 # @@ -81,6 +81,17 @@ valgrind: cmake-format: cmake-format $(CMAKE_SCRIPTS) -i -c .cmake-format.yaml +############################# +# Natvis File Generator # +############################# + +fkYAML.natvis: + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install jinja2 + venv/bin/python3 ./tool/natvis_generator/natvis_generator.py $(TARGET_VERSION_FULL) + rm -rf venv + ############### # Version # ############### diff --git a/fkYAML.natvis b/fkYAML.natvis new file mode 100644 index 00000000..992197d4 --- /dev/null +++ b/fkYAML.natvis @@ -0,0 +1,25 @@ + + + + + + + + + {*(m_node_value.p_sequence)} + {*(m_node_value.p_mapping)} + null + {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) + + + + diff --git a/tool/natvis_generator/fkYAML.natvis.j2 b/tool/natvis_generator/fkYAML.natvis.j2 new file mode 100644 index 00000000..e0a863dc --- /dev/null +++ b/tool/natvis_generator/fkYAML.natvis.j2 @@ -0,0 +1,25 @@ + + + + + + + + + {*(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) + + + + diff --git a/tool/natvis_generator/natvis_generator.py b/tool/natvis_generator/natvis_generator.py new file mode 100644 index 00000000..8b7b3b5e --- /dev/null +++ b/tool/natvis_generator/natvis_generator.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import jinja2 +import sys + +if __name__ == '__main__': + + version = 'v' + sys.argv[1].replace('.', '_') + namespace = 'fkyaml::' + version + + print(namespace) + + 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 From ac49e4c28766a0dbde41675180ff1c13aa298fa9 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 28 Nov 2023 23:17:45 +0900 Subject: [PATCH 2/4] improved natvis_generator tool --- .gitignore | 2 +- Makefile | 19 ++++++++++--------- fkYAML.natvis | 9 ++++++++- tool/natvis_generator/Makefile | 10 ++++++++++ tool/natvis_generator/README.md | 12 ++++++++++++ tool/natvis_generator/fkYAML.natvis.j2 | 7 +++++++ tool/natvis_generator/natvis_generator.py | 18 ++++++++++++++---- tool/natvis_generator/params.json | 1 + tool/natvis_generator/requirements.txt | 1 + 9 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 tool/natvis_generator/Makefile create mode 100644 tool/natvis_generator/README.md create mode 100644 tool/natvis_generator/params.json create mode 100644 tool/natvis_generator/requirements.txt diff --git a/.gitignore b/.gitignore index 50b9b4c9..6160d917 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ /docs/mkdocs/venv/ # natvis generator -/venv/ +/tool/natvis_generator/venv/ diff --git a/Makefile b/Makefile index 78a3067f..907eb5af 100644 --- a/Makefile +++ b/Makefile @@ -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,15 +82,15 @@ valgrind: cmake-format: cmake-format $(CMAKE_SCRIPTS) -i -c .cmake-format.yaml -############################# -# Natvis File Generator # -############################# +########################################## +# Natvis Debugger Visualization File # +########################################## + +update-params-for-natvis: + echo { \"version\": \"$(TARGET_VERSION_FULL)\" } > ./tool/natvis_generator/params.json -fkYAML.natvis: - python3 -m venv venv - venv/bin/pip install --upgrade pip - venv/bin/pip install jinja2 - venv/bin/python3 ./tool/natvis_generator/natvis_generator.py $(TARGET_VERSION_FULL) +fkYAML.natvis: update-params-for-natvis + make -C ./tool/natvis_generator generate rm -rf venv ############### @@ -136,7 +137,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 index 992197d4..59479ff8 100644 --- a/fkYAML.natvis +++ b/fkYAML.natvis @@ -8,7 +8,7 @@ {*(m_node_value.p_sequence)} {*(m_node_value.p_mapping)} - null + nullptr {m_node_value.boolean} {m_node_value.integer} {m_node_value.float_val} @@ -22,4 +22,11 @@ + + + {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 index e0a863dc..b560e9b8 100644 --- a/tool/natvis_generator/fkYAML.natvis.j2 +++ b/tool/natvis_generator/fkYAML.natvis.j2 @@ -22,4 +22,11 @@ + + + {second} + + second + + diff --git a/tool/natvis_generator/natvis_generator.py b/tool/natvis_generator/natvis_generator.py index 8b7b3b5e..e0d1d2aa 100644 --- a/tool/natvis_generator/natvis_generator.py +++ b/tool/natvis_generator/natvis_generator.py @@ -1,14 +1,23 @@ #!/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__': - version = 'v' + sys.argv[1].replace('.', '_') - namespace = 'fkyaml::' + version + with open('params.json') as j: + params= json.load(j) - print(namespace) + 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, @@ -16,7 +25,8 @@ 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: + 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. From cd5e7ffc9f246a06e8e275f908b32d1432cf22be Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 28 Nov 2023 23:23:42 +0900 Subject: [PATCH 3/4] deleted useless command execution in Makefile --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 907eb5af..89ba3e3d 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,6 @@ update-params-for-natvis: fkYAML.natvis: update-params-for-natvis make -C ./tool/natvis_generator generate - rm -rf venv ############### # Version # From 78afb75dd213968cf2319fbae132741124859831 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 28 Nov 2023 23:47:10 +0900 Subject: [PATCH 4/4] fixed pycodestyle error (E305) --- tool/natvis_generator/natvis_generator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tool/natvis_generator/natvis_generator.py b/tool/natvis_generator/natvis_generator.py index e0d1d2aa..ee5b8641 100644 --- a/tool/natvis_generator/natvis_generator.py +++ b/tool/natvis_generator/natvis_generator.py @@ -10,6 +10,7 @@ def check_version_format(ver): raise ValueError('Invalid semantic version specified. ver=' + ver) return ver + if __name__ == '__main__': with open('params.json') as j: