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:
Ulf Magnusson 2019-09-06 12:31:55 +02:00 committed by Kumar Gala
commit 8d317bc665
5 changed files with 51 additions and 18 deletions

View file

@ -605,7 +605,10 @@ class Device:
if not prop_type: if not prop_type:
_err("'{}' in {} lacks 'type'".format(name, self.binding_path)) _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: if val is None:
# 'required: false' property that wasn't there, or a property type # 'required: false' property that wasn't there, or a property type
# for which we store no data. # 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]: if to_dict[prop] == from_dict[prop]:
return False 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 # Allow a property to be made required when it previously was optional
# without a warning # 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 False
return True return True
@ -1305,15 +1305,15 @@ def _check_binding_properties(binding, binding_path):
if "properties" not in binding: if "properties" not in binding:
return return
ok_prop_keys = {"description", "type", "required", "constraint", "enum", ok_prop_keys = {"description", "type", "required", "category",
"const"} "constraint", "enum", "const"}
for prop_name, options in binding["properties"].items(): for prop_name, options in binding["properties"].items():
for key in options: for key in options:
if key == "category": if key == "category":
_err("please put 'required: {}' instead of 'category: {}' in " _warn("please put 'required: {}' instead of 'category: {}' in "
"'properties: {}: ...' in {} - 'category' has been " "'properties: {}: ...' in {} - 'category' will be "
"removed".format( "removed".format(
"true" if options["category"] == "required" else "false", "true" if options["category"] == "required" else "false",
options["category"], prop_name, binding_path)) options["category"], prop_name, binding_path))

View file

@ -1,10 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
include: [grandchild-1.yaml, grandchild-2.yaml] include: [grandchild-1.yaml, grandchild-2.yaml, grandchild-3.yaml]
# Legacy include
inherits:
!include grandchild-3.yaml
properties: properties:
bar: bar:

View file

@ -0,0 +1,4 @@
properties:
required-2:
type: int
required: true

View 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

View file

@ -274,7 +274,7 @@
}; };
// //
// For testing 'include:' and the legacy 'inherits: !include ...' // For testing 'include:'
// //
binding-include { binding-include {
@ -323,4 +323,14 @@
not-speced = <0>; not-speced = <0>;
}; };
}; };
//
// For testing deprecated features
//
deprecated {
compatible = "deprecated";
required = <1>;
required-2 = <2>;
};
}; };