Commit 4606e228 authored by Reiner Herrmann's avatar Reiner Herrmann

Merge tag 'upstream/1.2'

Upstream version 1.2
parents 15d2e822 fc77b853
...@@ -44,3 +44,6 @@ dist: deheader-$(VERS).tar.gz ...@@ -44,3 +44,6 @@ dist: deheader-$(VERS).tar.gz
release: deheader-$(VERS).tar.gz deheader.html release: deheader-$(VERS).tar.gz deheader.html
shipper version=$(VERS) | sh -e -x shipper version=$(VERS) | sh -e -x
refresh: deheader.html
shipper -N -w version=$(VERS) | sh -e -x
deheader project news deheader project news
1.2 @ 2015-07-18
Notice preprocessor directives with whitespace after the hash-mark
1.1 @ 2015-01-26 1.1 @ 2015-01-26
Allow --version on the command line. Fix up the regression tests. Allow --version on the command line. Fix up the regression tests.
......
...@@ -3,25 +3,23 @@ ...@@ -3,25 +3,23 @@
Package: deheader Package: deheader
Description: find (optionally remove) unneeded includes in C or C++ sourcefiles. Description: Find and optionally remove unneeded includes in C or C++ sourcefiles.
deheader analyzes C and C++ files to determine which header inclusions can be deheader analyzes C and C++ files to determine which header inclusions can be
removed while still allowing them to compile. This may result in substantial removed while still allowing them to compile. This may result in substantial
improvements in compilation time, especially on large C++ projects; it also improvements in compilation time, especially on large C++ projects; it also
sometimes exposes dependencies and cohesions of which developers were unaware. sometimes exposes dependencies and cohesions of which developers were unaware.
XBS-Destinations: freecode
Homepage: http://www.catb.org/~esr/deheader Homepage: http://www.catb.org/~esr/deheader
XBS-HTML-Target: index.html XBS-HTML-Target: index.html
Gitorious-URL: https://gitorious.org/deheader XBS-Repository-URL: https://gitlab.com/esr/deheader
OpenHub-URL: https://www.ohloh.net/p/deheader/ OpenHub-URL: https://www.ohloh.net/p/deheader/
XBS-Logo: deheader-logo.png XBS-Logo: deheader-logo.png
XBS-Freecode-Tags: development tools, optimization, C, C++ #XBS-Project-Tags: development tools, optimization, C, C++
XBS-VC-Tag-Template: %(version)s XBS-VC-Tag-Template: %(version)s
......
...@@ -36,7 +36,7 @@ BATON_DEBUG = 1 ...@@ -36,7 +36,7 @@ BATON_DEBUG = 1
PROGRESS_DEBUG = 2 PROGRESS_DEBUG = 2
COMMAND_DEBUG = 3 COMMAND_DEBUG = 3
version = "1.1" version = "1.2"
# Difference in various compiler implementations and OSes mean that for cross- # Difference in various compiler implementations and OSes mean that for cross-
# platform compatibility you sometimes want to leave "unneeded" headers alone # platform compatibility you sometimes want to leave "unneeded" headers alone
...@@ -1269,26 +1269,25 @@ class InclusionMap: ...@@ -1269,26 +1269,25 @@ class InclusionMap:
seen = [] seen = []
conditions = [] conditions = []
for line in open(sourcefile): for line in open(sourcefile):
if line.startswith("#ifndef"): c = match_preproc(["ifndef", "ifdef", "if"], line)
conditions.append(line[7:].strip()) if c is not False:
elif line.startswith("#ifdef"): conditions.append(c)
conditions.append(line[6:].strip()) elif match_preproc("endif", line) is not False:
elif line.startswith("#if"):
conditions.append(line[3:].strip())
elif line.startswith("#endif"):
conditions.pop() conditions.pop()
elif line.startswith("#include"): else:
if verbosity >= PROGRESS_DEBUG: f = match_preproc("include", line)
name = trim(line) if f is not False:
print "deheader: %s includes %s" % (sourcefile, name)
if ignore and ignore.search(line):
if verbosity >= PROGRESS_DEBUG: if verbosity >= PROGRESS_DEBUG:
print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern) name = trim(f)
continue print "deheader: %s includes %s" % (sourcefile, name)
if not conditions or conditions == ["S_SPLINT_S"]: if ignore and ignore.search(line):
includes.append(line) if verbosity >= PROGRESS_DEBUG:
elif verbose > 1: print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
print "deheader: ignoring %s (conditional inclusion)" % name continue
if not conditions or conditions == ["S_SPLINT_S"]:
includes.append(line)
elif verbose > 1:
print "deheader: ignoring %s (conditional inclusion)" % name
for (r, c, h) in compiled: for (r, c, h) in compiled:
if c.search(line): if c.search(line):
if not set(h).issubset(set(seen)): if not set(h).issubset(set(seen)):
...@@ -1335,9 +1334,18 @@ class SaveForModification: ...@@ -1335,9 +1334,18 @@ class SaveForModification:
pass pass
os.rename(self.original, self.filename) os.rename(self.original, self.filename)
def match_preproc(directives, line):
if not isinstance(directives, list):
directives = [directives]
regexp = "|".join(["#\s*" + d for d in directives])
m = re.match(regexp, line)
if m:
return line[m.span()[1]:].strip()
return False
def trim(line): def trim(line):
"Get file reference from an #include, retaining <> if a system header." "Get file reference from an #include, retaining <> if a system header."
trimmed = line[9:].strip() trimmed = re.sub("^#\s*include", "", line).strip()
if trimmed[0] in '"': if trimmed[0] in '"':
return '"' + trimmed.split('"')[1] + '"' return '"' + trimmed.split('"')[1] + '"'
elif trimmed[0] == '<': elif trimmed[0] == '<':
...@@ -1453,10 +1461,11 @@ class Summary: ...@@ -1453,10 +1461,11 @@ class Summary:
(len(self.filenames), len(self.includes), len(self.unneeded)) (len(self.filenames), len(self.includes), len(self.unneeded))
if __name__ == "__main__": if __name__ == "__main__":
(options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:rvx:V", (options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:qrvx:V",
["help", "ignore", ["help", "ignore",
"maker", "quiet",
"remove", "verbose", "remove", "verbose",
"version"]) "exclude", "version"])
maker = "make" maker = "make"
verbose = 0 verbose = 0
quiet = False quiet = False
......
deheader-logo.png

959 Bytes | W: | H:

deheader-logo.png

995 Bytes | W: | H:

deheader-logo.png
deheader-logo.png
deheader-logo.png
deheader-logo.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment