Skip to content

Commit

Permalink
scripts: extract_dts_includes: Enhance message information
Browse files Browse the repository at this point in the history
The information message when processing the yaml files is
cryptic when there is an override. This change adds filenmae
of yaml file being processed and the parent tuple with
the override.

Signed-off-by: David Leach <[email protected]>
  • Loading branch information
dleach02 authored and galak committed Jan 12, 2019
1 parent 6a56235 commit afcfa11
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions scripts/dts/extract_dts_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def bindings(cls, compatibles, yaml_dirs):
file_load_list.add(file)
with open(file, 'r', encoding='utf-8') as yf:
cls._included = []
l = yaml_traverse_inherited(yaml.load(yf, cls))
l = yaml_traverse_inherited(file, yaml.load(yf, cls))
if c not in yaml_list['compat']:
yaml_list['compat'].append(c)
if 'parent' in l:
Expand Down Expand Up @@ -489,33 +489,36 @@ def extract_node_include_info(reduced, root_node_address, sub_node_address,
extract_property(
node_compat, sub_node_address, k, v, None)

def dict_merge(dct, merge_dct):
def dict_merge(parent, fname, dct, merge_dct):
# from https://gist.github.com/angstwad/bf22d1822c38a92ec0a9

""" Recursive dict merge. Inspired by :meth:``dict.update()``, instead of
updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The ``merge_dct`` is merged into
``dct``.
:param parent: parent tuple key
:param fname: yaml file being processed
:param dct: dict onto which the merge is executed
:param merge_dct: dct merged into dct
:return: None
"""
for k, v in merge_dct.items():
if (k in dct and isinstance(dct[k], dict)
and isinstance(merge_dct[k], Mapping)):
dict_merge(dct[k], merge_dct[k])
dict_merge(k, fname, dct[k], merge_dct[k])
else:
if k in dct and dct[k] != merge_dct[k]:
print("extract_dts_includes.py: Merge of '{}': '{}' overwrites '{}'.".format(
k, merge_dct[k], dct[k]))
print("extract_dts_includes.py: {}('{}') merge of property '{}': '{}' overwrites '{}'.".format(
fname, parent, k, merge_dct[k], dct[k]))
dct[k] = merge_dct[k]


def yaml_traverse_inherited(node):
def yaml_traverse_inherited(fname, node):
""" Recursive overload procedure inside ``node``
``inherits`` section is searched for and used as node base when found.
Base values are then overloaded by node values
and some consistency checks are done.
:param fname: initial yaml file being processed
:param node:
:return: node
"""
Expand Down Expand Up @@ -545,14 +548,14 @@ def yaml_traverse_inherited(node):
node.pop('inherits')
for inherits in inherits_list:
if 'inherits' in inherits:
inherits = yaml_traverse_inherited(inherits)
inherits = yaml_traverse_inherited(fname, inherits)
# title, description, version of inherited node
# are overwritten by intention. Remove to prevent dct_merge to
# complain about duplicates.
inherits.pop('title', None)
inherits.pop('version', None)
inherits.pop('description', None)
dict_merge(inherits, node)
dict_merge(None, fname, inherits, node)
node = inherits
return node

Expand Down

0 comments on commit afcfa11

Please sign in to comment.