scripts: edtlib: Add backwards compatibility for 'category:'
Having backwards compatibility for !include and 'constraint:' is silly without also having backwards compatibility for 'category:', because that forces a binding change anyway. Add backwards compatibility for 'category:', and just print a deprecation warning when it's used. Also move tests for deprecated features into a dedicated test-bindings/deprecated.yaml binding, instead of piggybacking on other tests. Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
ba76b82f5a
commit
8d317bc665
5 changed files with 51 additions and 18 deletions
|
@ -605,7 +605,10 @@ class Device:
|
|||
if not prop_type:
|
||||
_err("'{}' in {} lacks 'type'".format(name, self.binding_path))
|
||||
|
||||
val = self._prop_val(name, prop_type, options.get("required"))
|
||||
val = self._prop_val(
|
||||
name, prop_type,
|
||||
options.get("required") or options.get("category") == "required")
|
||||
|
||||
if val is None:
|
||||
# 'required: false' property that wasn't there, or a property type
|
||||
# for which we store no data.
|
||||
|
@ -1245,14 +1248,11 @@ def _bad_overwrite(to_dict, from_dict, prop):
|
|||
if to_dict[prop] == from_dict[prop]:
|
||||
return False
|
||||
|
||||
# Don't error out for the removed 'category' setting here. We will give a
|
||||
# better error message in _check_binding().
|
||||
if prop == "category":
|
||||
return False
|
||||
|
||||
# Allow a property to be made required when it previously was optional
|
||||
# without a warning
|
||||
if prop == "required" and to_dict[prop] and not from_dict[prop]:
|
||||
if (prop == "required" and to_dict[prop] and not from_dict[prop]) or \
|
||||
(prop == "category" and to_dict[prop] == "required" and
|
||||
from_dict[prop] == "optional"):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@ -1305,14 +1305,14 @@ def _check_binding_properties(binding, binding_path):
|
|||
if "properties" not in binding:
|
||||
return
|
||||
|
||||
ok_prop_keys = {"description", "type", "required", "constraint", "enum",
|
||||
"const"}
|
||||
ok_prop_keys = {"description", "type", "required", "category",
|
||||
"constraint", "enum", "const"}
|
||||
|
||||
for prop_name, options in binding["properties"].items():
|
||||
for key in options:
|
||||
if key == "category":
|
||||
_err("please put 'required: {}' instead of 'category: {}' in "
|
||||
"'properties: {}: ...' in {} - 'category' has been "
|
||||
_warn("please put 'required: {}' instead of 'category: {}' in "
|
||||
"'properties: {}: ...' in {} - 'category' will be "
|
||||
"removed".format(
|
||||
"true" if options["category"] == "required" else "false",
|
||||
options["category"], prop_name, binding_path))
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
include: [grandchild-1.yaml, grandchild-2.yaml]
|
||||
|
||||
# Legacy include
|
||||
inherits:
|
||||
!include grandchild-3.yaml
|
||||
include: [grandchild-1.yaml, grandchild-2.yaml, grandchild-3.yaml]
|
||||
|
||||
properties:
|
||||
bar:
|
||||
|
|
4
scripts/dts/test-bindings/deprecated-include.yaml
Normal file
4
scripts/dts/test-bindings/deprecated-include.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
properties:
|
||||
required-2:
|
||||
type: int
|
||||
required: true
|
23
scripts/dts/test-bindings/deprecated.yaml
Normal file
23
scripts/dts/test-bindings/deprecated.yaml
Normal file
|
@ -0,0 +1,23 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
title: Deprecated stuff
|
||||
description: Deprecated stuff
|
||||
|
||||
# Deprecated include syntax
|
||||
inherits:
|
||||
!include deprecated-include.yaml
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
constraint: "deprecated"
|
||||
type: string-array
|
||||
|
||||
# Deprecated 'category' key (replaced with 'required')
|
||||
|
||||
required:
|
||||
type: int
|
||||
category: required
|
||||
|
||||
optional:
|
||||
type: int
|
||||
category: optional
|
|
@ -274,7 +274,7 @@
|
|||
};
|
||||
|
||||
//
|
||||
// For testing 'include:' and the legacy 'inherits: !include ...'
|
||||
// For testing 'include:'
|
||||
//
|
||||
|
||||
binding-include {
|
||||
|
@ -323,4 +323,14 @@
|
|||
not-speced = <0>;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// For testing deprecated features
|
||||
//
|
||||
|
||||
deprecated {
|
||||
compatible = "deprecated";
|
||||
required = <1>;
|
||||
required-2 = <2>;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue