[gobject-introspection/ebassi/symbol-collision: 49/51] scanner: Add strict mode
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/ebassi/symbol-collision: 49/51] scanner: Add strict mode
- Date: Thu, 5 Aug 2021 17:12:10 +0000 (UTC)
commit f6053328bf855937c78d520940ab2f82fead53cd
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Jun 16 17:02:25 2021 +0100
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.
docs/g-ir-scanner.1 | 3 +++
docs/website/tools/g-ir-scanner.rst | 4 ++++
giscanner/message.py | 18 ++++++++++++++++++
giscanner/scannermain.py | 8 +++++++-
4 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/docs/g-ir-scanner.1 b/docs/g-ir-scanner.1
index d25f321b..907baecb 100644
--- a/docs/g-ir-scanner.1
+++ b/docs/g-ir-scanner.1
@@ -57,6 +57,9 @@ Display warnings for public API which is not introspectable.
.B \-\-warn\-error
Make warnings be fatal errors.
.TP
+.B \-\-strict
+Display warnings for strict introspectable API.
+.TP
.BI \-\-format\fB= FORMAT
This parameters decides which the resulting format will be used. The
default value is gir.
diff --git a/docs/website/tools/g-ir-scanner.rst b/docs/website/tools/g-ir-scanner.rst
index e8df7457..47bbc2ff 100644
--- a/docs/website/tools/g-ir-scanner.rst
+++ b/docs/website/tools/g-ir-scanner.rst
@@ -42,6 +42,10 @@ OPTIONS
--warn-error
Make warnings be fatal errors.
+--strict
+ Display warnings for introspectable API that may present issues when
+ consumed by known language bindings.
+
--format=FORMAT
This parameters decides which the resulting format will be used. The
default value is gir.
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 957ba0b7..7a965c08 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, ))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]