Skip to content

Commit

Permalink
Added a python script to concat all natvis files into a single one (f…
Browse files Browse the repository at this point in the history
…or use with Visual Studio Code, on mac for example)
  • Loading branch information
jmarrec committed Sep 7, 2017
1 parent daf4fdd commit 60ffbfc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ test_fails.txt
*.sublime-project
cmake-build-debug

developer/msvc/Visualizers/all_concat.natvis
.vscode/

59 changes: 59 additions & 0 deletions developer/msvc/Visualizers/concat_natvis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
This small snippet will open all the *.natvis files and concat them into a
single one to be able to use them in Visual Studio Code (for Mac for eg)
vscode-cpptools expects only one visualizerFile currently
"""

import xml.etree.ElementTree as ET
import glob as gb

OUT_FILENAME = 'all_concat.natvis'


def concat_all_natvis_files():
"""
Main function
"""
natvis_files = gb.glob('*.natvis')
if OUT_FILENAME in natvis_files:
natvis_files.remove(OUT_FILENAME)

# In order to avoid the ns0 prefix the default namespace should be set
schema = 'http://schemas.microsoft.com/vstudio/debugger/natvis/2010'
# before reading the XML data.
ET.register_namespace('', schema)

# Open the file first found
print("Opening first: {}".format(natvis_files[0]))
tree = ET.parse(natvis_files[0])
root = tree.getroot()

ori_n_child = len(root)
total_n_child = ori_n_child

# Loop on the rest
for fname in natvis_files[1:]:
tree2 = ET.parse(fname)
root2 = tree2.getroot()
n_child = len(root2)
print("Parsing '{}', {} children".format(fname, n_child))
total_n_child += n_child
# Append each child or root2 to the first root
for child in root2.iter():
root.append(child)

final_n_child = len(root)
if final_n_child == total_n_child:
print("\nOK: Started with {}, Ended with {} children as "
"expected".format(ori_n_child, final_n_child))
else:
print("\nProblem: Started with {}, Ended with {} children, "
"expected {}".format(ori_n_child, final_n_child, total_n_child))

print("\nSaving to {}".format(OUT_FILENAME))
tree.write(OUT_FILENAME, encoding='utf-8', xml_declaration=True)


# If run from a terminal
if __name__ == '__main__':
concat_all_natvis_files()

0 comments on commit 60ffbfc

Please sign in to comment.