rectify_include_paths: warn instead of aborting on duplicate headers

We have two sendme.h files at the moment; we should fix that, but
not in this branch.
This commit is contained in:
Nick Mathewson
2019-05-20 11:52:45 -04:00
parent 2845607f97
commit 2f31c8146f
2 changed files with 262 additions and 2 deletions
+11 -2
View File
@@ -3,6 +3,10 @@
import os
import os.path
import re
import sys
def warn(msg):
sys.stderr.write("WARNING: %s\n"%msg)
# Find all the include files, map them to their real names.
@@ -11,6 +15,8 @@ def exclude(paths, dirnames):
if p in dirnames:
dirnames.remove(p)
DUPLICATE = object()
def get_include_map():
includes = { }
@@ -19,7 +25,10 @@ def get_include_map():
for fname in fnames:
if fname.endswith(".h"):
assert fname not in includes
if fname in includes:
warn("Multiple headers named %s"%fname)
includes[fname] = DUPLICATE
continue
include = os.path.join(dirpath, fname)
assert include.startswith("src/")
includes[fname] = include[4:]
@@ -37,7 +46,7 @@ def fix_includes(inp, out, mapping):
if m:
include,hdr,rest = m.groups()
basehdr = get_base_header_name(hdr)
if basehdr in mapping:
if basehdr in mapping and mapping[basehdr] is not DUPLICATE:
out.write('{}{}{}\n'.format(include,mapping[basehdr],rest))
continue