From a813d54965dc991e56da3146c8d838f9608b2b85 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 12 Sep 2018 22:05:15 +0800 Subject: [PATCH] add a python script to show the runtime packages' dependencies (#725) * add a python script to show the dependencies * add the header line and modify the mod --- substrate/scripts/runtime-dep.py | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 substrate/scripts/runtime-dep.py diff --git a/substrate/scripts/runtime-dep.py b/substrate/scripts/runtime-dep.py new file mode 100755 index 0000000000..1d0c42b2f5 --- /dev/null +++ b/substrate/scripts/runtime-dep.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +# To run this script, you need to install the 'toml' python package and install the 'graphviz' package: +# pip install toml +# sudo apt-get install graphviz +# the first parameter is the runtime folder +# python ./scripts/runtime-dep.py ./substrate/runtime | dot -Tpng -o output.png +import sys +import os +import toml + +if len(sys.argv) != 2: + print("needs the runtime folder.") + sys.exit(-1) + +runtime_dir = sys.argv[1] + +files = [os.path.join(runtime_dir, f, 'Cargo.toml') for f in os.listdir(runtime_dir) if os.path.isfile(os.path.join(runtime_dir, f, 'Cargo.toml')) and f != 'example'] + +print("digraph G {") + + +PREFIX = "substrate-runtime-" + +for f in files: + manifest = toml.load(f) + + package_name = manifest['package']['name'] + deps = [d for d in manifest['dependencies'].keys() if d.startswith(PREFIX)] + + for d in deps: + print(" \"{}\" -> \"{}\";".format(package_name, d)) + +print("}")