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