aboutsummaryrefslogtreecommitdiffstats
path: root/doc/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'doc/scripts')
-rwxr-xr-xdoc/scripts/print_deps.py70
-rwxr-xr-xdoc/scripts/update_deps.py41
2 files changed, 111 insertions, 0 deletions
diff --git a/doc/scripts/print_deps.py b/doc/scripts/print_deps.py
new file mode 100755
index 000000000..b92c43310
--- /dev/null
+++ b/doc/scripts/print_deps.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+"""
+Analyze the botan source tree and print the module interdependencies
+
+(C) 2009 Jack Lloyd
+Distributed under the terms of the Botan license
+"""
+
+import os
+import os.path
+import sys
+import re
+
+def find_deps_in(filename):
+ # By convention #include's with spaces before them are
+ # always wrapped in #ifdef blocks
+ regexp = re.compile('^#include <botan/(.*)>')
+
+ for line in open(filename).readlines():
+ match = regexp.match(line)
+ if match != None:
+ yield match.group(1)
+
+def get_dependencies(dirname):
+ all_dirdeps = {}
+ file_homes = {}
+
+ is_sourcefile = re.compile('\.(cpp|h|S)$')
+
+ for (dirpath, dirnames, filenames) in os.walk('src'):
+ dirdeps = set()
+ for filename in filenames:
+ if is_sourcefile.search(filename) != None:
+ file_homes[filename] = os.path.basename(dirpath)
+
+ for dep in find_deps_in(os.path.join(dirpath, filename)):
+ if dep not in filenames and dep != 'build.h':
+ dirdeps.add(dep)
+
+ dirdeps = sorted(dirdeps)
+ if dirdeps != []:
+ all_dirdeps[dirpath] = dirdeps
+
+ return (all_dirdeps, file_homes)
+
+def main():
+ (all_dirdeps, file_homes) = get_dependencies('src')
+
+ def interesting_dep_for(dirname):
+ def interesting_dep(dep):
+ if dep == 'utils':
+ return False # everything depends on it
+
+ # block/serpent depends on block, etc
+ if dirname.find('/%s/' % (dep)) > 0:
+ return False
+ return True
+ return interesting_dep
+
+ for dirname in sorted(all_dirdeps.keys()):
+ depdirs = sorted(set(map(lambda x: file_homes[x], all_dirdeps[dirname])))
+
+ depdirs = filter(interesting_dep_for(dirname), depdirs)
+
+ if depdirs != []:
+ print "%s: %s" % (dirname, ' '.join(depdirs))
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/doc/scripts/update_deps.py b/doc/scripts/update_deps.py
new file mode 100755
index 000000000..61aa887cc
--- /dev/null
+++ b/doc/scripts/update_deps.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+import sys
+import re
+import os.path
+
+def update_requires(dir, deps):
+ lines = map(lambda x: x.strip(),
+ open(os.path.join(dir, 'info.txt')).readlines())
+
+ if '<requires>' in lines:
+ start = lines.index('<requires>')
+
+ while lines.pop(start) != '</requires>':
+ pass
+
+ while lines[-1] == '':
+ lines = lines[:-1]
+
+ if len(deps) > 0:
+ lines.append('')
+ lines.append('<requires>')
+ for dep in deps:
+ lines.append(dep)
+ lines.append('</requires>')
+ lines.append('')
+
+ lines = "\n".join(lines).replace("\n\n\n", "\n\n")
+
+ output = open(os.path.join(dir, 'info.txt'), 'w')
+ output.write(lines)
+ output.close()
+
+def main():
+ for line in sys.stdin.readlines():
+ (dirname, deps) = line.split(':')
+ deps = deps.strip().split(' ')
+ update_requires(dirname, deps)
+
+if __name__ == '__main__':
+ sys.exit(main())