summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-14 03:56:06 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-14 03:56:06 +0300
commitdf35fbcbfd532e3ff33a07eaf6b79755aadadf61 (patch)
tree73b5e046b4bcebaff096c8d18364f4159d21c3c6
parente01f7e7013d523856ff11af852a8f28fa4919b25 (diff)
downloaddeheader-df35fbcbfd532e3ff33a07eaf6b79755aadadf61.tar.gz
deheader-df35fbcbfd532e3ff33a07eaf6b79755aadadf61.tar.bz2
deheader-df35fbcbfd532e3ff33a07eaf6b79755aadadf61.tar.xz
deheader-df35fbcbfd532e3ff33a07eaf6b79755aadadf61.zip
Add --std2 parameter for alternative std flag while checking includes.
-rwxr-xr-xdeheader31
1 files changed, 17 insertions, 14 deletions
diff --git a/deheader b/deheader
index a771e78..3761af5 100755
--- a/deheader
+++ b/deheader
@@ -1234,7 +1234,7 @@ class InclusionMap:
def c_source(filename):
"Predicate: return true if the filename appears to be C or C++ source."
return filename.endswith(".c") or filename.endswith(".cpp") or filename.endswith(".cc") or filename.endswith(".h")
- def __init__(self, roots, ignore, excludes, verbosity, compiler, std, defines, maker, showerrs=False, subdir=""):
+ def __init__(self, roots, ignore, excludes, verbosity, compiler, std, std2, defines, maker, showerrs=False, subdir=""):
"Build the initial inclusion map."
self.verbosity = verbosity
self.files = []
@@ -1332,7 +1332,7 @@ class InclusionMap:
def remember(self, sourcefile, header):
"Undo forgetting of a dependency."
self.depends_on[sourcefile].append(header)
- def check_block(self, sourcefile, cnt, compiler, std, defines, maker, verbosity, showerrs, subdir):
+ def check_block(self, sourcefile, cnt, compiler, std, std2, defines, maker, verbosity, showerrs, subdir):
tempName = sourcefile + ".cpp"
try:
with open(sourcefile, "r") as r:
@@ -1343,7 +1343,7 @@ class InclusionMap:
if cnt2 == cnt:
w.write("#error deheader\n")
cnt2 = cnt2 + 1
- (st, _t) = testcompile(tempName, compiler, std, defines, maker, "make {0}".format(cnt), verbosity, showerrs=False, subdir=subdir)
+ (st, _t) = testcompile(tempName, compiler, std, std2, defines, maker, "make {0}".format(cnt), verbosity, showerrs=False, subdir=subdir)
if st == 0:
return False
return True
@@ -1396,7 +1396,7 @@ def trim(line):
else:
return repr(line)
-def testcompile(source, compiler, std, defines, maker, msg="", verbosity=0, showerrs=False, subdir=""):
+def testcompile(source, compiler, std, std2, defines, maker, msg="", verbosity=0, showerrs=False, subdir=""):
"Test-compile a sourcefile. Return the status and the compilation time"
(stem, _suffix) = os.path.splitext(source)
tmpname = stem + ".o"
@@ -1417,7 +1417,7 @@ def testcompile(source, compiler, std, defines, maker, msg="", verbosity=0, show
if std == "":
explain = "succeeded"
else:
- command = "{0} {1} {2} {3} -o {4} {5}".format(compiler, "-std=c++98", defines, maker, tmpname, source)
+ command = "{0} {1} {2} {3} -o {4} {5}".format(compiler, std2, defines, maker, tmpname, source)
(status, output) = getstatusoutput(command)
end = time.time()
if status:
@@ -1432,7 +1432,7 @@ def testcompile(source, compiler, std, defines, maker, msg="", verbosity=0, show
print("deheader: %s%s %s." % (source, msg, explain))
return (status, end - start)
-def c_analyze(sourcefile, compiler, std, defines, maker, includes, requires, verbosity, subdir=""):
+def c_analyze(sourcefile, compiler, std, std2, defines, maker, includes, requires, verbosity, subdir=""):
"Given a C file and a list of includes, return those that can be omitted."
# We'll remove headers in reverse order, because later unnecessary
# headers might depend on earlier ones
@@ -1456,7 +1456,7 @@ def c_analyze(sourcefile, compiler, std, defines, maker, includes, requires, ver
retain += 1
if not retain:
saveit.remove_headers(unneeded + [header])
- (st, _t) = testcompile(sourcefile, compiler, std, defines, maker, " without %s" % trim(header), verbosity, showerrs=False, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, std, std2, defines, maker, " without %s" % trim(header), verbosity, showerrs=False, subdir=subdir)
if st == 0:
unneeded.append(header)
includes.remove(header)
@@ -1475,19 +1475,19 @@ def c_analyze(sourcefile, compiler, std, defines, maker, includes, requires, ver
print("deheader: in %s, %s portability requires %s." % (os.path.join(subdir, sourcefile), trigger, ",".join(requirement)))
return unneeded
-def deheader(sourcefile, compiler, std, defines, maker, includes, requires, remove, verbose):
+def deheader(sourcefile, compiler, std, std2, defines, maker, includes, requires, remove, verbose):
# Sanity check against broken sourcefiles; we want this to
# complain visibly if the sourcefile won't build at all.
subdir = ""
- (st, _t) = testcompile(sourcefile, compiler, std, defines, maker, verbosity=max(1, verbose), showerrs=False)
+ (st, _t) = testcompile(sourcefile, compiler, std, std2, defines, maker, verbosity=max(1, verbose), showerrs=False)
if st != 0:
subdir = os.path.dirname(sourcefile)
sourcefile = os.path.basename(sourcefile)
- (st, _t) = testcompile(sourcefile, compiler, std, defines, maker, verbosity=max(1, verbose), showerrs=True, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, std, std2, defines, maker, verbosity=max(1, verbose), showerrs=True, subdir=subdir)
if st == 0:
# Now do the analysis
if sourcefile.endswith(".c") or sourcefile.endswith(".cpp") or sourcefile.endswith(".cc") or sourcefile.endswith(".h"):
- unneeded = c_analyze(sourcefile, compiler, std, defines, maker,
+ unneeded = c_analyze(sourcefile, compiler, std, std2, defines, maker,
includes[:], requires, verbose, subdir=subdir)
if unneeded:
for line in unneeded:
@@ -1527,7 +1527,7 @@ if __name__ == "__main__":
"remove", "verbose",
"exclude", "version",
"compiler", "defines",
- "std"])
+ "std", "std2"])
maker = "make"
verbose = 0
quiet = False
@@ -1535,6 +1535,7 @@ if __name__ == "__main__":
compiler = "g++"
defines = ""
std = ""
+ std2 = "-std=c++98"
ignores = []
exclusions = []
for (switch, val) in options:
@@ -1562,6 +1563,8 @@ if __name__ == "__main__":
defines = val
elif switch in ('-s', '--std'):
std = val
+ elif switch in ('--std2'):
+ std = val
if not ignores:
ignore = None
else:
@@ -1574,10 +1577,10 @@ if __name__ == "__main__":
arguments = ["."]
inclusion_map = InclusionMap(arguments, ignore, exclusions, verbose,
- compiler, std, defines, maker, showerrs=False)
+ compiler, std, std2, defines, maker, showerrs=False)
summaries = []
for sourcefile in sorted(inclusion_map.depends_on.keys()):
- summaries.append(deheader(sourcefile, compiler, std, defines, maker,
+ summaries.append(deheader(sourcefile, compiler, std, std2, defines, maker,
inclusion_map.depends_on[sourcefile],
inclusion_map.requires[sourcefile],
remove, verbose))