scripts: rework edtlib warnings-turned-errors
Create a "global" gen_defines.py option and edtlib.EDT constructor
kwarg that turns edtlib-specific warnings into errors. This applies to
edtlib-specific warnings only. Warnings that are just dupes of dtc
warnings are not affected.
Use it from twister to increase DT testing coverage in upstream zephyr.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py
index 42592cb..5b7138a 100755
--- a/scripts/dts/gen_defines.py
+++ b/scripts/dts/gen_defines.py
@@ -69,8 +69,7 @@
"-Wno-simple_bus_reg" not in args.dtc_flags,
default_prop_types=True,
infer_binding_for_paths=["/zephyr,user"],
- err_on_deprecated_properties=
- args.err_on_deprecated_properties,
+ werror=args.edtlib_Werror,
vendor_prefixes=vendor_prefixes)
except edtlib.EDTError as e:
sys.exit(f"devicetree error: {e}")
@@ -217,8 +216,10 @@
help="path to write pickled edtlib.EDT object to")
parser.add_argument("--vendor-prefixes",
help="vendor-prefixes.txt path; used for validation")
- parser.add_argument("--err-on-deprecated-properties", action="store_true",
- help="if set, deprecated property usage is an error")
+ parser.add_argument("--edtlib-Werror", action="store_true",
+ help="if set, edtlib-specific warnings become errors. "
+ "(this does not apply to warnings shared "
+ "with dtc.)")
return parser.parse_args()
diff --git a/scripts/dts/python-devicetree/src/devicetree/edtlib.py b/scripts/dts/python-devicetree/src/devicetree/edtlib.py
index badc869..57daf1b 100644
--- a/scripts/dts/python-devicetree/src/devicetree/edtlib.py
+++ b/scripts/dts/python-devicetree/src/devicetree/edtlib.py
@@ -150,8 +150,8 @@
default_prop_types=True,
support_fixed_partitions_on_any_bus=True,
infer_binding_for_paths=None,
- err_on_deprecated_properties=False,
- vendor_prefixes=None):
+ vendor_prefixes=None,
+ werror=False):
"""EDT constructor.
dts:
@@ -180,20 +180,22 @@
should be inferred from the node content. (Child nodes are not
processed.) Pass none if no nodes should support inferred bindings.
- err_on_deprecated_properties (default: False):
- If True and 'dts' has any deprecated properties set, raise an error.
-
vendor_prefixes (default: None):
A dict mapping vendor prefixes in compatible properties to their
descriptions. If given, compatibles in the form "manufacturer,device"
for which "manufacturer" is neither a key in the dict nor a specially
exempt set of grandfathered-in cases will cause warnings.
+
+ werror (default: False):
+ If True, some edtlib specific warnings become errors. This currently
+ errors out if 'dts' has any deprecated properties set, or an unknown
+ vendor prefix is used.
"""
self._warn_reg_unit_address_mismatch = warn_reg_unit_address_mismatch
self._default_prop_types = default_prop_types
self._fixed_partitions_no_bus = support_fixed_partitions_on_any_bus
self._infer_binding_for_paths = set(infer_binding_for_paths or [])
- self._err_on_deprecated_properties = bool(err_on_deprecated_properties)
+ self._werror = bool(werror)
self._vendor_prefixes = vendor_prefixes
self.dts_path = dts
@@ -426,8 +428,7 @@
# they (either always or sometimes) reference other nodes, so we
# run them separately
node._init_props(default_prop_types=self._default_prop_types,
- err_on_deprecated=
- self._err_on_deprecated_properties)
+ err_on_deprecated=self._werror)
node._init_interrupts()
node._init_pinctrls()
@@ -519,7 +520,11 @@
vendor = compat.split(',', 1)[0]
if vendor not in self._vendor_prefixes and \
vendor not in _VENDOR_PREFIX_ALLOWED:
- _LOG.warning(
+ if self._werror:
+ log_fn = _LOG.error
+ else:
+ log_fn = _LOG.warning
+ log_fn(
f"node '{node.path}' compatible '{compat}' "
f"has unknown vendor prefix '{vendor}'")
diff --git a/scripts/pylib/twister/twisterlib.py b/scripts/pylib/twister/twisterlib.py
index e88d1f1..13fea56 100755
--- a/scripts/pylib/twister/twisterlib.py
+++ b/scripts/pylib/twister/twisterlib.py
@@ -2008,7 +2008,7 @@
ldflags = "-Wl,--fatal-warnings"
cflags = "-Werror"
aflags = "-Wa,--fatal-warnings"
- gen_defines_args = "--err-on-deprecated-properties"
+ gen_defines_args = "--edtlib-Werror"
else:
ldflags = cflags = aflags = ""
gen_defines_args = ""