aboutsummaryrefslogtreecommitdiffstats
path: root/amalgamate
diff options
context:
space:
mode:
authorMartin Kemp <martin.kemp@ingg.com>2015-07-30 15:59:54 +0100
committerMartin Kemp <martin.kemp@ingg.com>2015-07-30 15:59:54 +0100
commit18c9d69b2d75e38c9e0d05df576cf3a85d7a2392 (patch)
tree289ad95df6f6327ae86dfcf070c976f4188d10ef /amalgamate
parentacf686d3dd3e7ecde6527432fe3090a94929ed14 (diff)
downloadcrow-18c9d69b2d75e38c9e0d05df576cf3a85d7a2392.tar.gz
crow-18c9d69b2d75e38c9e0d05df576cf3a85d7a2392.zip
Initial py3 compatibility.
Diffstat (limited to 'amalgamate')
-rw-r--r--amalgamate/merge_all.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/amalgamate/merge_all.py b/amalgamate/merge_all.py
index fe7b50f..275e930 100644
--- a/amalgamate/merge_all.py
+++ b/amalgamate/merge_all.py
@@ -1,5 +1,6 @@
-import glob
-import os
+"""Merges all the header files."""
+from glob import glob
+from os import path as pt
import re
from collections import defaultdict
import sys
@@ -10,11 +11,11 @@ if len(sys.argv) > 1:
OUTPUT = 'crow_all.h'
re_depends = re.compile('^#include "(.*)"', re.MULTILINE)
-headers = [x.rsplit('/',1)[-1] for x in glob.glob(os.path.join(header_path,'*.h'))]
-print headers
+headers = [x.rsplit('/', 1)[-1] for x in glob(pt.join(header_path, '*.h'))]
+print(headers)
edges = defaultdict(list)
for header in headers:
- d = open(os.path.join(header_path, header)).read().decode('utf8')
+ d = open(pt.join(header_path, header)).read().decode('utf8')
match = re_depends.findall(d)
for m in match:
# m should included before header
@@ -22,30 +23,32 @@ for header in headers:
visited = defaultdict(bool)
order = []
+
+
def dfs(x):
+ """Ensure all header files are visited."""
visited[x] = True
for y in edges[x]:
if not visited[y]:
dfs(y)
order.append(x)
-
+
for header in headers:
if not visited[header]:
dfs(header)
order = order[::-1]
for x in edges:
- print x, edges[x]
+ print(x, edges[x])
for x in edges:
for y in edges[x]:
assert order.index(x) < order.index(y), 'cyclic include detected'
-print order
+print(order)
build = []
for header in order:
- d = open(os.path.join(header_path, header)).read().decode('utf8')
- build.append(re_depends.sub(lambda x:'\n', d))
+ d = open(pt.join(header_path, header)).read().decode('utf8')
+ build.append(re_depends.sub(lambda x: '\n', d))
build.append('\n')
-open(OUTPUT,'w').write('\n'.join(build))
-
+open(OUTPUT, 'w').write('\n'.join(build))