diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-05-28 17:20:49 +0200 |
---|---|---|
committer | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-10-08 20:54:59 +0200 |
commit | cc96177ec877153e7e5e55e6af270829da546015 (patch) | |
tree | c316058a23302adf9e63b3227d92853af692096c | |
parent | 4d1972cedd20bb51b8c67ec030339d5d4dce12a9 (diff) | |
download | gobject-introspection-cc96177ec877153e7e5e55e6af270829da546015.tar.gz |
giscanner: give pointer to original comment block...
...when complaining about multiple comment blocks
documenting the same identifier.
-rw-r--r-- | giscanner/annotationparser.py | 18 | ||||
-rw-r--r-- | giscanner/message.py | 11 | ||||
-rw-r--r-- | tests/warn/annotationparser.h | 19 |
3 files changed, 31 insertions, 17 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index f5205a57..d5da84cf 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -105,6 +105,7 @@ Refer to the `GTK-Doc manual`_ for more detailed usage information. ''' +import os import re from . import message @@ -856,15 +857,16 @@ class GtkDocCommentBlockParser(object): continue if comment_block is not None: - # Note: previous versions of this parser did not check - # if an identifier was already stored in comment_blocks, - # so when multiple comment blocks where encountered documenting - # the same identifier the last one seen "wins". - # Keep this behavior for backwards compatibility, but - # emit a warning. + # Note: previous versions of this parser did not check if an identifier was + # already stored in comment_blocks, so when different comment blocks where + # encountered documenting the same identifier the last comment block seen + # "wins". Keep this behavior for backwards compatibility, but emit a warning. if comment_block.name in comment_blocks: - message.warn("multiple comment blocks documenting '%s:' identifier." % - (comment_block.name, ), + firstseen = comment_blocks[comment_block.name] + path = os.path.dirname(firstseen.position.filename) + message.warn('multiple comment blocks documenting \'%s:\' identifier ' + '(already seen at %s).' % + (comment_block.name, firstseen.position.format(path)), comment_block.position) comment_blocks[comment_block.name] = comment_block diff --git a/giscanner/message.py b/giscanner/message.py index fc6100e0..eca425aa 100644 --- a/giscanner/message.py +++ b/giscanner/message.py @@ -53,9 +53,12 @@ class Position(object): self.column or -1) def format(self, cwd): - filename = self.filename - if filename.startswith(cwd): - filename = filename[len(cwd):] + filename = os.path.realpath(self.filename) + cwd = os.path.realpath(cwd) + common_prefix = os.path.commonprefix((filename, cwd)) + if common_prefix: + filename = os.path.relpath(filename, common_prefix) + if self.column is not None: return '%s:%d:%d' % (filename, self.line, self.column) elif self.line is not None: @@ -73,7 +76,7 @@ class MessageLogger(object): def __init__(self, namespace, output=None): if output is None: output = sys.stderr - self._cwd = os.getcwd() + os.sep + self._cwd = os.getcwd() self._output = output self._namespace = namespace self._enable_warnings = False diff --git a/tests/warn/annotationparser.h b/tests/warn/annotationparser.h index 87b632f4..db04b5a0 100644 --- a/tests/warn/annotationparser.h +++ b/tests/warn/annotationparser.h @@ -1,18 +1,27 @@ #include "common.h" /** - * test_symbol_twice_documented: + * test_symbol_thrice_documented: * * Documenting the same thing multiple times can lead to subtle bugs. * For example, one comment block might have correct annotations... **/ -void test_symbol_twice_documented(); +void test_symbol_thrice_documented(); /** - * test_symbol_twice_documented: + * test_symbol_thrice_documented: * * ...and a different comment block (out of sync with the above) might have - * no annotations at all. The last comment block seen by the parser "wins". + * no annotations at all. The last comment block seen by the parser "wins"... **/ -// EXPECT:12: Warning: Test: multiple comment blocks documenting 'test_symbol_twice_documented:' identifier. +// EXPECT:12: Warning: Test: multiple comment blocks documenting 'test_symbol_thrice_documented:' identifier (already seen at annotationparser.h:4). + + +/** + * test_symbol_thrice_documented: + * + * ...and yet another one. + **/ + +// EXPECT:22: Warning: Test: multiple comment blocks documenting 'test_symbol_thrice_documented:' identifier (already seen at annotationparser.h:12). |