generate.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/usr/bin/env python
  2. # ------------------------------------------------------------------------------
  3. # This file is part of cpp-ethereum.
  4. #
  5. # cpp-ethereum is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # cpp-ethereum is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>
  17. #
  18. #------------------------------------------------------------------------------
  19. # Python script to generate a DOT graph showing the dependency graph of
  20. # the modules within the cpp-ethereum project. It is a mixture of
  21. # dynamically-generated and hard-coded content to augment and improve
  22. # the results.
  23. #
  24. # The script was originally written by Bob Summerwill to assist his own
  25. # efforts at understanding the dependencies for the cpp-ethereum-cross
  26. # project which cross-builds cpp-ethereum, and then contributed to the
  27. # main cpp-ethereum project.
  28. #
  29. # See https://github.com/doublethinkco/cpp-ethereum-cross for more
  30. # information on the cross-builds project.
  31. #
  32. # The documentation for cpp-ethereum is hosted at http://cpp-ethereum.org
  33. #
  34. # (c) 2015-2016 cpp-ethereum contributors.
  35. #------------------------------------------------------------------------------
  36. import os
  37. import re
  38. dependencyPattern = "eth_use\((.*)\s+(OPTIONAL|REQUIRED)\s+(.*)\)"
  39. # Returns a string which lists all the dependency edges for a given
  40. # library or application, based on the declared OPTIONAL and REQUIRED
  41. # dependencies within the CMake file for that library or application.
  42. def getDependencyEdges(submodulePath, library):
  43. cmakeListsPath = os.path.join(os.path.join(submodulePath, library),
  44. "CMakeLists.txt")
  45. outputString = ""
  46. if os.path.exists(cmakeListsPath):
  47. with open(cmakeListsPath) as fileHandle:
  48. for line in fileHandle.readlines():
  49. result = re.search(dependencyPattern, line)
  50. if result:
  51. fromNode = result.group(1)
  52. toNodes = result.group(3).split()
  53. for toNode in toNodes:
  54. # Merge all JsonRpc::* nodes to simplify the output graph.
  55. # Not much value in the details there.
  56. if toNode.startswith("JsonRpc::"):
  57. toNode = "json-rpc-cpp"
  58. elif "::" in toNode:
  59. toNode = toNode.split("::")[1]
  60. edgeText = '"' + fromNode + '" -> "' + toNode + '"'
  61. if "OPTIONAL" in line:
  62. edgeText = edgeText + " [style=dotted]"
  63. outputString = outputString + edgeText + "\n"
  64. return outputString
  65. # Return a string which is a list of all the library and application
  66. # names within a given git sub-module directory.
  67. def getLibraryAndApplicationNames(submodulePath):
  68. outputString = ""
  69. for subDirectoryName in os.listdir(submodulePath):
  70. if (subDirectoryName != "examples" and subDirectoryName != "utils" and subDirectoryName != ".git"):
  71. absSubDirectoryPath = os.path.join(submodulePath, subDirectoryName)
  72. if os.path.isdir(absSubDirectoryPath):
  73. cmakeListsPath = os.path.join(absSubDirectoryPath,
  74. "CMakeLists.txt")
  75. if os.path.exists(cmakeListsPath):
  76. moduleName = subDirectoryName
  77. if (moduleName == "libdevcore"):
  78. moduleName = "devcore"
  79. if (moduleName == "libdevcrypto"):
  80. moduleName = "devcrypto"
  81. if (moduleName == "libethash"):
  82. moduleName = "ethash"
  83. if (moduleName == "libethash-cl"):
  84. moduleName = "ethash-cl"
  85. if (moduleName == "libethashseal"):
  86. moduleName = "ethashseal"
  87. if (moduleName == "libethcore"):
  88. moduleName = "ethcore"
  89. if (moduleName == "libethereum"):
  90. moduleName = "ethereum"
  91. if (moduleName == "libevm"):
  92. moduleName = "evm"
  93. if (moduleName == "libevmcore"):
  94. moduleName = "evmcore"
  95. if (moduleName == "libp2p"):
  96. moduleName = "p2p"
  97. if (moduleName == "libwebthree"):
  98. moduleName = "webthree"
  99. if (moduleName == "libweb3jsonrpc"):
  100. moduleName = "web3jsonrpc"
  101. if (moduleName == "libwhisper"):
  102. moduleName = "whisper"
  103. outputString = outputString + ' "' + moduleName + '"'
  104. if (moduleName == "evmjit"):
  105. outputString = outputString + " [style=filled,fillcolor=coral]"
  106. elif ("lib" in absSubDirectoryPath):
  107. outputString = outputString + " [style=filled,fillcolor=deepskyblue]"
  108. else:
  109. outputString = outputString + " [shape=box;style=filled,penwidth=2,fillcolor=chartreuse]"
  110. outputString = outputString + "\n"
  111. return outputString
  112. # Walk the top-level folders within the repository
  113. def processRepository(root):
  114. print getLibraryAndApplicationNames(root)
  115. for folder in os.listdir(root):
  116. absPath = os.path.join(root, folder)
  117. if os.path.isdir(absPath):
  118. if not (".git" in absPath):
  119. print getDependencyEdges(root, folder)
  120. print 'digraph webthree {'
  121. print ' graph [ label = "Ethereum C++ dependencies" ]'
  122. print ' node [ fontname = "Courier", fontsize = 10 ]'
  123. print ''
  124. print ' compound = true'
  125. print ''
  126. print ' "buildinfo" [style=filled,fillcolor=deepskyblue]'
  127. print ' "json_spirit" [color=red]'
  128. print ' "scrypt" [color=red]'
  129. print ' "secp256k1" [color=red]'
  130. print ' "testeth" [shape=box;style=filled,penwidth=2,fillcolor=chartreuse]'
  131. print ' "testweb3" [shape=box;style=filled,penwidth=2,fillcolor=chartreuse]'
  132. print ' "testweb3core" [shape=box;style=filled,penwidth=2,fillcolor=chartreuse]'
  133. print ''
  134. print ' "bench" -> "devcrypto"'
  135. print ' "curl" -> "ssh2" [style=dotted]'
  136. print ' "curl" -> "openssl" [style=dotted]'
  137. print ' "curl" -> "zlib" [style=dotted]'
  138. print ' "devcore" -> "boost::filesystem"'
  139. print ' "devcore" -> "boost::random"'
  140. print ' "devcore" -> "boost::system"'
  141. print ' "devcore" -> "boost::thread"'
  142. print ' "devcore" -> "LevelDB"'
  143. print ' "devcrypto" -> "devcore"'
  144. print ' "devcrypto" -> "json_spirit"'
  145. print ' "devcrypto" -> "scrypt"'
  146. print ' "devcrypto" -> "secp256k1"'
  147. print ' "eth" -> "web3jsonrpc"'
  148. print ' "ethcore" -> "devcore"'
  149. print ' "ethcore" -> "buildinfo"'
  150. print ' "ethcore" -> "json_spirit"'
  151. print ' "ethereum" -> "boost::regex"'
  152. print ' "ethereum" -> "evm"'
  153. print ' "ethereum" -> "evmjit" [style=dotted]'
  154. print ' "ethereum" -> "json_spirit"'
  155. print ' "ethereum" -> "p2p"'
  156. print ' "ethash" -> "Cryptopp"'
  157. print ' "ethash-cl" -> "ethash"'
  158. print ' "ethashseal" -> "ethereum"'
  159. print ' "ethkey" -> "ethcore"'
  160. print ' "ethminer" -> "ethashseal"'
  161. print ' "ethvm" -> "ethashseal"'
  162. print ' "evm" -> "ethcore"'
  163. print ' "evm" -> "evmcore"'
  164. print ' "json-rpc-cpp" -> "argtable2" [style=dotted]'
  165. print ' "json-rpc-cpp" -> "curl"'
  166. print ' "json-rpc-cpp" -> "microhttpd"'
  167. print ' "json-rpc-cpp" -> "Jsoncpp"'
  168. print ' "json-rpc-cpp" -> "libedit"'
  169. print ' "LevelDB" -> "snappy" [style=dotted]'
  170. print ' "evmjit" -> "llvm"'
  171. print ' "p2p" -> "devcrypto"'
  172. print ' "rlp" -> "devcrypto"'
  173. print ' "rlp" -> "json_spirit"'
  174. print ' "secp256k1" -> "gmp"'
  175. print ' "testeth" -> "ethashseal"'
  176. print ' "testeth" -> "boost::unit_test_framework"'
  177. print ' "testweb3" -> "boost::unit_test_framework"'
  178. print ' "testweb3" -> "web3jsonrpc"'
  179. print ' "testweb3core" -> "boost::date_time"'
  180. print ' "testweb3core" -> "boost::regex"'
  181. print ' "testweb3core" -> "boost::unit_test_framework"'
  182. print ' "testweb3core" -> "devcore"'
  183. print ' "testweb3core" -> "devcrypto"'
  184. print ' "testweb3core" -> "p2p"'
  185. print ' "webthree" -> "ethashseal"'
  186. print ' "webthree" -> "whisper"'
  187. print ' "web3jsonrpc" -> "webthree"'
  188. print ' "whisper" -> "boost::regex"'
  189. print ' "whisper" -> "p2p"'
  190. print ''
  191. processRepository('../..')
  192. print "}"