diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2021-06-16 17:02:25 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2022-02-12 11:09:52 +0000 |
commit | 8ec097772459d67d5a7e888f5096f3f04a422ba1 (patch) | |
tree | 97b6dcf29ef21e7e5133571f6f6a8600127c118a /giscanner | |
parent | e736f4d48ca93ff90f172190a33a87901a40e630 (diff) | |
download | gobject-introspection-8ec097772459d67d5a7e888f5096f3f04a422ba1.tar.gz |
scanner: Add strict mode
To avoid introducing additional strictness onto unsuspecting libraries,
we introduce a new mode: "strict".
The strict mode is opt-in, and used to signal potential issues with the
public API once exposed by language bindings, even when it's fully
introspectable.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/message.py | 18 | ||||
-rw-r--r-- | giscanner/scannermain.py | 8 |
2 files changed, 25 insertions, 1 deletions
diff --git a/giscanner/message.py b/giscanner/message.py index 24f1b7df..5b7bf685 100644 --- a/giscanner/message.py +++ b/giscanner/message.py @@ -102,6 +102,7 @@ class MessageLogger(object): self._output = output self._namespace = namespace self._enable_warnings = False + self._enable_strict = False self._warning_count = 0 @classmethod @@ -113,6 +114,17 @@ class MessageLogger(object): def enable_warnings(self, value): self._enable_warnings = bool(value) + @property + def warnings_enabled(self): + return self._enable_warnings + + def enable_strict(self, value): + self._enable_strict = bool(value) + + @property + def strict_enabled(self): + return self._enable_strict + def get_warning_count(self): return self._warning_count @@ -218,6 +230,12 @@ def error_node(node, text, context=None, positions=None): log_node(ERROR, node, text, context=context, positions=positions) +def strict_node(node, text, context=None, positions=None): + ml = MessageLogger.get() + if ml.strict_enabled: + ml.log(WARNING, node, text, context=context, positions=positions) + + def warn_symbol(symbol, text): ml = MessageLogger.get() ml.log_symbol(WARNING, symbol, text) diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 1124bc74..576f78ac 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -205,6 +205,9 @@ match the namespace prefix.""") parser.add_option('', "--warn-error", action="store_true", dest="warn_fatal", help="Turn warnings into fatal errors") + parser.add_option('', "--strict", + action="store_true", dest="warn_strict", default=False, + help="If true, enable strict warnings for introspection") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose") @@ -576,6 +579,8 @@ def scanner_main(args): logger = message.MessageLogger.get(namespace=namespace) if options.warn_all: logger.enable_warnings(True) + if options.warn_strict: + logger.enable_strict(True) transformer = create_transformer(namespace, options) @@ -610,11 +615,12 @@ def scanner_main(args): final = IntrospectablePass(transformer, blocks) final.validate() + show_suppression = options.warn_all is False and options.warn_strict is False and options.quiet is False warning_count = logger.get_warning_count() if options.warn_fatal and warning_count > 0: message.fatal("warnings configured as fatal") return 1 - elif warning_count > 0 and options.warn_all is False and options.quiet is False: + elif warning_count > 0 and show_suppression: print("g-ir-scanner: %s: warning: %d warnings suppressed " "(use --warn-all to see them)" % (transformer.namespace.name, warning_count, )) |