summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rwxr-xr-xdeheader9
-rw-r--r--deheader.xml2
-rw-r--r--test/duplicate.c8
-rw-r--r--test/noheaders.c2
-rw-r--r--test/regress.chk11
6 files changed, 31 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index e92b778..56cc9c7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
deheader project news
+0.4 @
+ Duplicate inclusions are now detected.
+
0.3 @ 2010-12-09
Add a dependencies table to head off common cross-platform problems.
diff --git a/deheader b/deheader
index 8f75997..8304960 100755
--- a/deheader
+++ b/deheader
@@ -126,10 +126,17 @@ class InclusionMap:
for (r, h) in requirements:
if r.search(line):
if verbosity >= PROGRESS_DEBUG:
- print "%s has requires %s from %s" % (sourcefile, h, r.pattern)
+ print "deheader: %s has requires %s from %s" % (sourcefile, h, r.pattern)
requires.append(h)
self.depends_on[sourcefile] = includes
self.requires[sourcefile] = re.compile("|".join(requires))
+ # Duplicate-header detection
+ trimmedcount = {}
+ for ref in map(trim, includes):
+ trimmedcount[ref] = trimmedcount.get(ref, 0) + 1
+ for ref in trimmedcount:
+ if trimmedcount[ref] > 1:
+ print "deheader: %s has more than one inclusion of %s" % (sourcefile, ref)
def forget(self, sourcefile, header):
"Forget a header dependency."
self.depends_on[sourcefile].remove(header)
diff --git a/deheader.xml b/deheader.xml
index 711bcce..6e0794a 100644
--- a/deheader.xml
+++ b/deheader.xml
@@ -49,6 +49,8 @@ directives are left alone, because trying to reason about potential
combinations of -D and U options would be too complicated and prone to
weird errors.</para>
+<para>The tool will also emit warnings about duplicate emissions.</para>
+
<para>It is recommended that you arrange to compile with options that
will stop the compiler on warnings when using this tool; otherwise it
will be report headers that only declare prototypes and return types
diff --git a/test/duplicate.c b/test/duplicate.c
new file mode 100644
index 0000000..5074c78
--- /dev/null
+++ b/test/duplicate.c
@@ -0,0 +1,8 @@
+/* this file tests detection of duplicate heafers */
+
+#include <stdio.h>
+#include <stdio.h>
+
+main(int arg, char **argv)
+{
+}
diff --git a/test/noheaders.c b/test/noheaders.c
index d245179..7655e0c 100644
--- a/test/noheaders.c
+++ b/test/noheaders.c
@@ -1,4 +1,4 @@
-/* this filre has no headers and needs none */
+/* this file has no headers and needs none */
main(int arg, char **argv)
{
diff --git a/test/regress.chk b/test/regress.chk
index f80d014..02bc982 100644
--- a/test/regress.chk
+++ b/test/regress.chk
@@ -1,9 +1,16 @@
deheader: test/string.c requires <string.h>
+deheader: test/duplicate.c requires <stdio.h>
+deheader: test/duplicate.c requires <stdio.h>
+deheader: test/duplicate.c has more than one inclusion of <stdio.h>
deheader: test/umask.c requires <sys/stat.h>
deheader: test/umask.c requires <sys/types.h>
-test/umask.c has requires <sys/stat.h>|<sys/types.h> from umask
+deheader: test/umask.c has requires <sys/stat.h>|<sys/types.h> from umask
deheader: test/string.c without <string.h> succeeded.
deheader: remove <string.h> from test/string.c
deheader: in test/umask.c, retaining required '#include <sys/types.h>\n'
deheader: in test/umask.c, retaining required '#include <sys/stat.h>\n'
-deheader: saw 3 files, 3 includes, 1 removed
+deheader: test/duplicate.c without <stdio.h> succeeded.
+deheader: test/duplicate.c without <stdio.h> succeeded.
+deheader: remove <stdio.h> from test/duplicate.c
+deheader: remove <stdio.h> from test/duplicate.c
+deheader: saw 4 files, 5 includes, 3 removed