Skip to content

Commit

Permalink
Merge pull request #227 from fktn-k/feature/226_add_natvis_file
Browse files Browse the repository at this point in the history
Feature/226 add natvis file
  • Loading branch information
fktn-k authored Nov 28, 2023
2 parents 05bb3fe + 78afb75 commit e99a12c
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 6 deletions.
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
build*
.vscode/
.vs/
/build*
/.vscode/
/.vs/

# documentation
/docs/mkdocs/site/
/docs/mkdocs/venv/
/docs/mkdocs/venv/

# natvis generator
/tool/natvis_generator/venv/
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ target_include_directories(
${FK_YAML_TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${FK_YAML_INCLUDE_BUILD_DIR}>
$<INSTALL_INTERFACE:${FK_YAML_INCLUDE_INSTALL_DIR}>)

# 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 $<INSTALL_INTERFACE:${FK_YAML_NATVIS_FILE}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${FK_YAML_NATVIS_FILE}>)
endif()

############################
# Integrate with tools #
############################
Expand Down Expand Up @@ -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}::
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: update-version-macros CHANGELOG.md update-version
.PHONY: update-version-macros CHANGELOG.md update-version fkYAML.natvis

#################
# variables #
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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 #
###############
Expand Down Expand Up @@ -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)"

################
Expand Down
32 changes: 32 additions & 0 deletions fkYAML.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- This is a auto-generated file. -->
<!-- Edit ./tools/natvis_generator/fkYAML.natvis.j2 -->

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- Namespace fkyaml::v0_2_2 -->
<Type Name="fkyaml::v0_2_2::basic_node&lt;*&gt;">
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::SEQUENCE">{*(m_node_value.p_sequence)}</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::MAPPING">{*(m_node_value.p_mapping)}</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::NULL_OBJECT">nullptr</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::BOOLEAN">{m_node_value.boolean}</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::INTEGER">{m_node_value.integer}</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::FLOAT_NUMBER">{m_node_value.float_val}</DisplayString>
<DisplayString Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::STRING">{*(m_node_value.p_string)}</DisplayString>
<Expand>
<ExpandedItem Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::SEQUENCE">
*(m_node_value.p_sequence),view(simple)
</ExpandedItem>
<ExpandedItem Condition="m_node_type == fkyaml::v0_2_2::detail::node_t::MAPPING">
*(m_node_value.p_mapping),view(simple)
</ExpandedItem>
</Expand>
</Type>

<Type Name="std::pair&lt;*, fkyaml::v0_2_2::basic_node&lt;*&gt;&gt;" IncludeView="MapHelper">
<DisplayString>{second}</DisplayString>
<Expand>
<ExpandedItem>second</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>
10 changes: 10 additions & 0 deletions tool/natvis_generator/Makefile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tool/natvis_generator/README.md
Original file line number Diff line number Diff line change
@@ -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
```
32 changes: 32 additions & 0 deletions tool/natvis_generator/fkYAML.natvis.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- This is a auto-generated file. -->
<!-- Edit ./tools/natvis_generator/fkYAML.natvis.j2 -->

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- Namespace {{ namespace }} -->
<Type Name="{{ namespace }}::basic_node&lt;*&gt;">
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::SEQUENCE">{*(m_node_value.p_sequence)}</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::MAPPING">{*(m_node_value.p_mapping)}</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::NULL_OBJECT">nullptr</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::BOOLEAN">{m_node_value.boolean}</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::INTEGER">{m_node_value.integer}</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::FLOAT_NUMBER">{m_node_value.float_val}</DisplayString>
<DisplayString Condition="m_node_type == {{ namespace }}::detail::node_t::STRING">{*(m_node_value.p_string)}</DisplayString>
<Expand>
<ExpandedItem Condition="m_node_type == {{ namespace }}::detail::node_t::SEQUENCE">
*(m_node_value.p_sequence),view(simple)
</ExpandedItem>
<ExpandedItem Condition="m_node_type == {{ namespace }}::detail::node_t::MAPPING">
*(m_node_value.p_mapping),view(simple)
</ExpandedItem>
</Expand>
</Type>

<Type Name="std::pair&lt;*, {{ namespace }}::basic_node&lt;*&gt;&gt;" IncludeView="MapHelper">
<DisplayString>{second}</DisplayString>
<Expand>
<ExpandedItem>second</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>
33 changes: 33 additions & 0 deletions tool/natvis_generator/natvis_generator.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tool/natvis_generator/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "version": "0.2.2" }
1 change: 1 addition & 0 deletions tool/natvis_generator/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jinja2==3.1.2.

0 comments on commit e99a12c

Please sign in to comment.